PHP and Web Technologies Freak
Debian uses a Sys-V like init system for executing commands when the system runlevel changes – for example at bootup and shutdown time.
If you wish to add a new service to start when the machine boots you should add the script to the directory /etc/init.d/. Many of the scripts already present in that directory will give you an example of the kind of things that you can do.
Here’s a very simple script which is divided into two parts, code which always runs, and code which runs when called with “start” or “stop”.
#! /bin/sh # /etc/init.d/routines # # Some lines that run always rm /var/lock/routines touch /var/lock/routines # Carry out specific functions when asked to by the system case "$1" in start) echo "Starting script routines " echo "Could do more here" ;; stop) echo "Stopping script routines" echo "Could do more here" ;; *) echo "Usage: /etc/init.d/routines {start|stop}" exit 1 ;; esac exit 0
Once you’ve saved your file into the correct location make sure that it’s executable by running “chmod 755 /etc/init.d/routines”.
Then you need to add the appropriate symbolic links to cause the script to be executed when the system goes down, or comes up.
The simplest way of doing this is to use the Debian-specific command update-rc.d:
root@skx:~# update-rc.d blah defaults Adding system startup for /etc/init.d/routines... /etc/rc0.d/K20routines -> ../init.d/routines /etc/rc1.d/K20routines -> ../init.d/routines /etc/rc6.d/K20routines -> ../init.d/routines /etc/rc2.d/S20routines -> ../init.d/routines /etc/rc3.d/S20routines -> ../init.d/routines /etc/rc4.d/S20routines -> ../init.d/routines /etc/rc5.d/S20routines -> ../init.d/routines
If you wish to remove the script from the startup sequence in the future run:
root@skx:/etc/rc2.d# update-rc.d -f routines remove update-rc.d: /etc/init.d/routines exists during rc.d purge (continuing) Removing any system startup links for /etc/init.d/routines ... /etc/rc0.d/K20routines /etc/rc1.d/K20routines /etc/rc2.d/S20routines /etc/rc3.d/S20routines /etc/rc4.d/S20routines /etc/rc5.d/S20routines /etc/rc6.d/K20routines
This will leave the script itself in place, just remove the links which cause it to be executed.
You can find more details of this command by running “man update-rc.d”.
Leave a reply