Overv / openstreetmap-tile-server

Docker file for a minimal effort OpenStreetMap tile server
Apache License 2.0
1.2k stars 482 forks source link

Cron doesn't load environment variables. #383

Open OptiMael opened 1 year ago

OptiMael commented 1 year ago

I define some environment variables in docker-compose.yml (e.g. THREADS=8) which get used correctly for setting up renderd.conf https://github.com/Overv/openstreetmap-tile-server/blob/6088b9b37f440f141f643f413a3d6454a1c01aa2/run.sh#L171

But the openstreetmap-tiles-update-expire.sh executed via Cron doesn't have access to the enviroment variables. This results in execution of openstreetmap-tiles-update-expire.sh with default parameters.

Istador commented 1 year ago

I was able to reproduce this.

# import
docker  run  --rm  -e UPDATES=enabled  -e THREADS=2  -v osm-data:/data/database/  overv/openstreetmap-tile-server  import

# run in background
docker  run  -d  --name osm  --rm  -e UPDATES=enabled  -e THREADS=2  -v osm-data:/data/database/  overv/openstreetmap-tile-server  run

# change the update script to write the THREADS env to a debug file instead
docker  exec  osm  bash  -c "echo 'echo \${THREADS:-default} >/tmp/debugenv' >/usr/bin/openstreetmap-tiles-update-expire.sh"

# wait a minute for crontab to execute the script

# output the contents of the debug file
docker  exec  osm  bash  -c "cat /tmp/debugenv"

This outputs default instead of 2.


Workaround that results in 2 being written to the file instead of default:

docker  exec  osm  bash  -c "printenv >/etc/environment"

printenv >/etc/environment could be added to the run.sh here between line 174 and 175: https://github.com/Overv/openstreetmap-tile-server/blob/6088b9b37f440f141f643f413a3d6454a1c01aa2/run.sh#L174-L175