Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cron doesn't load environment variables. #383

Open
OptiMael opened this issue Aug 8, 2023 · 1 comment · May be fixed by #385
Open

Cron doesn't load environment variables. #383

OptiMael opened this issue Aug 8, 2023 · 1 comment · May be fixed by #385

Comments

@OptiMael
Copy link

OptiMael commented Aug 8, 2023

I define some environment variables in docker-compose.yml (e.g. THREADS=8) which get used correctly for setting up renderd.conf

sed -i -E "s/num_threads=[0-9]+/num_threads=${THREADS:-4}/g" /etc/renderd.conf

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
Copy link
Contributor

Istador commented Aug 8, 2023

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:

if [ "${UPDATES:-}" == "enabled" ] || [ "${UPDATES:-}" == "1" ]; then
/etc/init.d/cron start

Istador added a commit to Istador/openstreetmap-tile-server that referenced this issue Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants