2014年11月13日 星期四

Starting an application at boot (daemon)

1. add a file in /etc/init.d
ex: vim /etc/init.d/hello_service
2. edit the hello_service
#!/bin/sh
# Starts the hello_service daemon for test
#
export PATH=$PATH:/usr/local/bin  <- not work :(
case "$1" in
start)
   export PATH=$PATH:/usr/local/bin  <- not work :(
   echo "Starting hello_service "
   exec /bin/hello &
   ;;
stop)
   echo "Stopping hello_service"
   start-stop-daemon --stop --name hello_service
   ;;
*)
   echo "Usage: /etc/init.d/hello_service {start|stop}"
   exit 1
   ;;
esac
exit 0
3. test the file
    ex:
    # /etc/init.d/hello_service start
4. add a link in runlevel
    ex:
    # update-rc.d newera_s start 99 3 .


ref: RIGADO-Starting an application at boot

沒有留言:

張貼留言