Have Gnu Screen Pass SIGTERM Signal to Child Processes, Allowing Them To Shut Down Cleanly

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:

   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.


Turns out I had to approach this from a different perspective, and handle it via Upstart. The addition of a pre-stop script, allowed me to identify the Screen session, and then stuff in the commands ("quit\n" and then "y\n") to cleanly shut down the binary that Screen was running.

pre-stop script
   SESSID=`ps -elf | grep '/opt/bin/prog /opt/cfg/$product' | grep SCREEN | awk '{print $4}'`
   QUIT_CMD="screen -S $SESSID.$product -X stuff \"exit"$'\n'"\""
   exec `su spuser -c "$QUIT_CMD"`
   QUIT_CMD="screen -S $SESSID.$product -X stuff \"y"$'\n'"\""
   exec `su spuser -c "$QUIT_CMD"`
   sleep 20
end script

Need Your Help

Undelete files in docker

docker recovery

I have docker container and execute command

How to use MySQLdb with Python and Django in OSX 10.6?

python mysql django virtualenv virtualenvwrapper

This is a much discussed issue for OSX 10.6 users, but I haven't been able to find a solution that works. Here's my setup: