I created a daemon to run a python script. but it stops whenever i logout from my ubuntu machine.
DAEMON=sudo python /var/www/some_dir/my_python.py
ARGS=/var/www/some_dir/my_python.py
PIDFILE=/var/www/some_dir/my_python.pid
test -x $DAEMON || exit 0
#set -e
case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon --start --pidfile $PIDFILE --exec $DAEMON &
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --pidfile $PIFDILE --exec $DAEMON
echo "$NAME."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
start-stop-daemon --stop --pidfile $PIDFILE --exec $DAEMON
sleep 1
start-stop-daemon --start --pidfile $PIDFILE --exec $DAEMON &
echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
can anyone tell me how can i do it.
start-stop-daemontakes care of everything... obviously it does not. Try trapping theSIGHUPsignal in the Python script. Redirecting the output to a file or/dev/nullmay also be wise.