문제

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.

도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top