Eseguire un file come servizio
Updated at: 16/10/2013


1. place your python script in the following folder: /user/local/sbin/ 2. create a new file in /etc/init.d/ in this case it will be "sched_serv", so sudo nano /etc/init.d/sched_serv 3. Use the following code for the example file
#! /bin/sh
#! /bin/sh
### BEGIN INIT INFO
# Provides:          skeleton
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Example initscript
# Description:       This file should be used to construct scripts to be
#                    placed in /etc/init.d.
### END INIT INFO
# /etc/init.d/sched_serv

case "$1" in
 start)
    echo "Starting sched_serv"
    # run application you want to start
    python /etc/script/task_scheduler.py &
    ;;
 stop)
    echo "Stopping sched_serv"
    # kill application you want to stop
    killall python
    ;;
 *)
    echo "Usage: /etc/init.d/sched_serv{start|stop}"
    exit 1
    ;;
esac

exit 0
4. give the file execute rights, sudo chmod 755 sched_serv 5. now execute: sudo update-rc.d sched_serv defaults When you reboot debian it should automatically start the python script, else try service example start and service example stop