/etc/init.d/amc doesn't complete when run by ssh


#1

In the AMC start script, there’s code that is supposed to start a watchdog script start_amc_cron.sh, but that script doesn’t properly detach from the shell, and as a result anything that tries to automate that script ends up hanging.

You can test this by running the script without a TTY via “ssh $host sudo /etc/init.d/amc start”. The service starts up fine, but the command never exits and ssh just hangs there. I was able to work around this (and make it pretty reliable) by using runit to monitor gnuicorn in the foreground instead. But I wasn’t able to find a good way for the background process to detach cleanly and allow ssh to close the connection. (This problem also make automation of the service via the provided script impossible for at least Salt, and likely Puppet/Chef as well.)


#2

I will give this a quick test in house.


#3

If you want, the following run script (for use with runit or daemontools) works really well instead:

#!/bin/bash
exec 2>&1

PROJECT="/opt/amc"
PIDFILE="/tmp/amc.pid"
GUNICORN="${PROJECT}/bin/gunicorn"
CONFIG="/etc/amc/config/gunicorn_config.py"

CMD="${GUNICORN} --config=${CONFIG} flaskapp:app"

exec $CMD