We are using Upstart to launch/terminate an in-house developed binary.
In the Upstart configuration file for this binary, we define the script as such:
script
exec su - user -c "screen -D -m -S $product /opt/bin/prog /opt/cfg/$product -v 5 --max_log_size=7"
end script
When the runlevel is set to 5, Upstart launches the script. When the runlevel is set to 3, Upstart terminates the script.
My problem, is Upstart is sending a SIGTERM and then a SIGKILL.
The SIGTERM is being 'handled' by screen, and not by my custom binary, so the signal handlers in our binary dont get the SIGTERM, and thus, cannot shut down cleanly.
I've verified that the signal handlers in our binary do allow it to shut down cleanly when it is NOT launched via screen.