Yelp/dumb-init

Forward exit code 1 from HEALTHCHECK in Dockerfile ?

lukasmrtvy opened this issue · 1 comments

I am wondering if its possible to forward signal from crontab`s job to dumb-init ?
Seems that crontab will always run, no matter of exit codes of its jobs.

What can I do is that instead of exit 1 I will create file and do and Healthcheck in Dockerfile to monitor this file. Unfortunatelly this will mark container as unhealty, but will not exit dumb-init process.

Any idea?
Thanks

FROM ubuntu:bionic
RUN apk add --no-cache dumb-init cron && \
         echo "#!/bin/sh; echo foo; touch /test.exited; exit 1" > /test.sh && \
         echo "* * * * * root /bin/sh /test.sh > /proc/1/fd/1" > /etc/cron.d/test

HEALTHCHECK --interval=5s --timeout=3s \
    CMD if [ -f /test.exited ]; then exit 1 ;fi

ENTRYPOINT ["/usr/bin/dumb-init", "--"]
 
CMD ["/usr/sbin/cron", "-f"]

For dumb-init to exit, you'd either need to send it an uncatchable "terminate" signal (i.e. SIGKILL) or have its immediate child die (cron in your case). The uncatchable signal thing won't really work if it's PID 1 though.

The options I'd probably consider are:

  • Killing the cron process (either in your HEALTHCHECK or when your script fails)
  • Having some process above cron in the process tree that knows to watch for the file and exits when it appears; when it exits, dumb-init would exit