I’d like to create a container that itself runs a cronjob.
While the cronjob runs, a redeployment of the container should delay the shutdown for X minutes (my job runs at max 10mins).
Deployment in my case means:
docker-compose pull
docker-compose up
Question: how could I achieve a graceful shutdown here?
My first approach was to let the crontab
process being the PID1 process. Inspired from here: Running Cron in Docker
But how could I then detect if a cronjob is currently executing (=delay shutdown), or idle (=shutdown immediately) on redeployment?
dockerfile:
...
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["cron", "-f", "-L", "2"]
docker-compose.yml:
services:
my-app:
init: true
docker-entrypoint.sh:
exec "$@"
crontab:
0/30 * * * * /opt/importer.sh >/proc/1/fd/1 2>/proc/1/fd/2
importer.sh:
#!/usr/bin/bash
#this script takes a few minutes to execute:
#- copy files from a to b
#- run another .sh script that converts them
#- cleanup files