debian -- start stuff at boot

A couple of ways to start jobs and daemons at boot in debian.



A simple way to run something after everything was started would be to put the command or script at /etc/rc.local

The political correct system V or debian way to manage a daemon is to make an init script for your daemon and use the System V init links to fire up your daemon or kill it in certain runlevels.

There is a skeleton for init scripts at /etc/init.d/skeleton that comes with debian systems and shows a bulletproof political correct way to do a system V ala debian init script.

However, a bare minimum init could be something like the following script.
# cat /etc/init.d/workerjob 
#!/bin/sh
#g0 2014 http://alog.ipduh.com
#weak system V init script skeleton
#look at /etc/init.d/skeleton for a solid solution

DOJ="job"
INITNAME="workerjob"


case "$1" in
  start)

    echo "Starting ${DOJ} ..."
    
    # daemon 
    # /usr/bin/${DOJ} --config /etc/daemon/daemon.conf 

    # some daemon as user worker
    #su --login worker --command "/usr/bin/daemon --config /etc/daemon/daemon.conf"
    
    # some user worker job in screen
    #su --login worker --command "/usr/bin/screen -dmS ${DOJ} /usr/local/bin/${DOJ}"
    
    ;;
  stop)
    echo "attempting to stop ${DOJ} "
    
    # daemon
    # /usr/bin/daemon stop

    # some daemon as user worker
    #su --login worker --command "/usr/bin/${DOJ} stop"
    
    # some user job in screen worker
    pgrep -u worker screen |xargs kill -9

    ps aufx |grep ${DOJ} 

    ;;
  *)
    echo "Usage: /etc/init.d/${INITNAME} {start|stop}"
    exit 1
    ;;
esac

exit 0



An easy way to add init scripts to the system V /etc/rc*.d/* init script links is update-rc.d

eg: to start workerjob in runlevels 2,3,4,5 and stop it in runlevels 1,6
# update-rc.d workerjob defaults
update-rc.d: using dependency based boot sequencing


To remove the workerjob from the init links
# update-rc.d workerjob remove -f
update-rc.d: using dependency based boot sequencing





Run after boot in debian