[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: init.d shell script can't stop daemon (python script)



> > I wrote a (python) script that is acting like a daemon (doing something,
> > sleeping for 10 seconds, doing ..., sleeping ...) and would like to
> > launch and kill it from a shell script in /etc/init.d.
> > 
> > Using start-stop-daemon seemed appropriate, but the problems is that
> > no /var/run/$NAME.pid is written and /proc/<PID>/exe points to
> > /usr/bin/python. Hence stopping the daemon or preventing further deamons
> > from starting is not possible :(

> I make my python daemons test (early) and then write (late) their
> own pidfile as part of the process of daemonifying themselves.
> 
> Stopping: The --pidfile should now work of course, but I throw
> in --execfile /usr/bin/python --name python --user foo
> if only to document for myself what works. Those parameters are
> for a daemon that is a python script starting with the header
> #!/usr/bin/env python

Thanx for your suggestions. I finally got it to work with all the daemon
logic inside the init.d shell script:

case "$1" in
  start)
        echo -n "Starting $DESC: "
        start-stop-daemon --start --pidfile /var/run/$NAME.pid \
            --make-pidfile --background --startas $DAEMON
        echo "$NAME."
        ;;
  stop)
        echo -n "Stopping $DESC: "
        start-stop-daemon --stop --quiet --oknodo \
	    --pidfile /var/run/$NAME.pid
        rm -f /var/run/$NAME.pid
        echo "$NAME."
        ;;

where $DEAMON is the full pathname of the executable python script.

Stony 



Reply to: