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

Forward exit code 1 from HEALTHCHECK in Dockerfile ? #180

Open
lukasmrtvy opened this issue Dec 11, 2018 · 1 comment
Open

Forward exit code 1 from HEALTHCHECK in Dockerfile ? #180

lukasmrtvy opened this issue Dec 11, 2018 · 1 comment

Comments

@lukasmrtvy
Copy link

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"]
@chriskuehl
Copy link
Contributor

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

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

No branches or pull requests

2 participants