My apologies for bumping the old post, but it's unresolved and highly relevant to me.
I'm working on an init script for Gentoo Linux using SABnzbd 0.6.0, and I'd like to have a way to launch SAB and get a PID back. I notice that you get the pid using os.fork() in SABnzbd.py, but it's not returned or used anywhere outside of that script.
The standard method for starting services on Gentoo is by using start-stop-daemon. start-stop-daemon lets me, for example, run the SAB process as a specific user (I don't like running net-accessible services as root). start-stop-daemon, however, exits abnormally when used to launch interpreted python scripts, and reports the status of the service as [crashed], even though it launches correctly.
Currently, I accomplish this task by using "su" instead, which switches to a specific user prior to launching SABnzbd.py with python directly. I shut down the service with a direct call to the HTTP interface using http://localhost/shutdown?session=
[api_key]. I can't guarantee, however, that the process will actually shut down, since I don't know its PID. I could kill all the python processes with SABnzbd.py in the name, but that could kill a difficult process that I might want to keep running.
If SAB provided a method to return its PID after successfully daemonizing, multiple copies could be started and stopped individually by PID later, using start-stop-daemon. What are your thoughts?