I am using following run script to run the program under daemontools
#!/bin/sh exec 2>&1 /usr/bin/python /home/test/sigtest.py
And there's your error. You're forking a child process to run the python program in. Stop your daemon from forking. Daemons do not need to, and should not, fork to run in a child process, be they running under daemontools, daemontools-encore, runit, s6, perp, or even systemd.
The standard operation of the shell, remember, is to fork and run commands in child processes.
For best results, you should acclimate yourself to writing run
scripts using something other than the shell, that chain loads daemon programs. Here's your run
script using Laurent Bercot's execline
instead of /bin/sh
as the script interpreter:
#!/command/execlineb -PW
fdmove -c 2 1
/usr/bin/python /home/test/sigtest.py
execline
doesn't have any of the overhead of all of the things that even non-interactive shells do, including parsing startup "rc" files. And it comes with a useful suite of chain loading utilities for doing many of the things that one might want to do in run
scripts.
But even execline
does things that you don't need in a run
script. Hence the -P
option to turn off argument pushing, which has no utility for run
scripts. Here's your run
script using an even more barebones script interpreter, my nosh
program:
#!/usr/local/bin/nosh
fdmove -c 2 1
/usr/bin/python /home/test/sigtest.py
Finally, here's your run
script for /bin/sh
, corrected:
#!/bin/sh exec 2>&1 exec /usr/bin/python /home/test/sigtest.py
Further reading
- https://superuser.com/a/708384/38062
- Russ Allbery (2013-12-18). Bug#727708: upstart proposed policy in Debian. debian-ctte.
- Jonathan de Boyne Pollard (2001). "Don't fork() in order to 'put the dæmon into the background'.". Mistakes to avoid when designing Unix dæmon programs. Frequently Given Answers.