We are running a php cli command in a docker container with New Relic deamon installed to track exceptions. The problem is that New Relic sends exception traces on an interval of 1 minute, but when our php process crashes due to an exception, the container gets killed right away.
Is there a (simple) solution to keep the container alive for about one minute after the php process has died, for example by wrapping it in some other script/program?
Thanks to the comment of user2915097, which got me thinking, we've found a solution. We wrote a small script which we use an entrypoint of the container and sleep when the script fails.
cron-php-entrypoint:
#!/bin/sh
eval "$@" || (echo 'Delaying exit for 60 seconds for New Relic to send its report...' && sleep 60)
Lines to add to Dockerfile:
COPY cron-php-entrypoint /usr/local/bin/
ENTRYPOINT ["cron-php-entrypoint"]