linux-startup-script-creating-a-lsb-compliant-custom-service
PREPARATION
insserv enables an installed system init script (`boot script') by reading the comment header of the script:
### BEGIN INIT INFO
# Provides: boot_facility_1 [ boot_facility_2 ...]
# Required-Start: boot_facility_1 [ boot_facility_2 ...]
# Required-Stop: boot_facility_1 [ boot_facility_2 ...]
# Should-Start: boot_facility_1 [ boot_facility_2 ...]
# Should-Stop: boot_facility_1 [ boot_facility_2 ...]
# Default-Start: run_level_1 [ run_level_2 ...]
# Default-Stop: run_level_1 [ run_level_2 ...]
# Description: multiline_description
### END INIT INFO
and calculating the dependencies between all scripts (see TROUBLESHOOTING section for details)
EXAMPLE a wpa_supplicant connection for wifi at startup (based on wpa-ifupdown)
nano /etc/init.d/ MY-wifi-start-wpa.sh
! /bin/sh
BEGIN INIT INFO
Provides: MY-wifi-start-wpa.sh
Required-Start: $network
Required-Stop:
Default-Start: S
Default-Stop: 0 6
Short-Description: connect to local wifi with wpa_supplicant using ssid/password file
Description: connect to local wifi with wpa_supplicant using ssid/password file
END INIT INFO
wpa_supplicant -B -iwlan0 -c/etc/wpa_supplicant/wpa_supplicant.conf
chmod 755 /etc/init.d/ MY-wifi-start-wpa.sh //make the script executable
DEBIAN / UBUNTU
sudo update-rc.d /etc/init.d/myscript.sh defaults
CENTOS / REDHAT script must be modified slightly for chkconfig
!bash/bin
chkconfig: 2345 90 10
description: myscript does something at boot
nano /etc/rc.local //add the following line to /etc/rc.local
/etc/init.d/MYvirtualbox.sh
sudo /sbin/chkconfig --add myscript.sh
TROUBLESHOOTING
Always test your script first before you go through all of the trouble to make it a startup script... e.g. make sure the MY-wifi-wpa-startup.sh can read the wpa_supplicant.conf file, that you have the correct ssid and you've created the wpa_passphrase key correctly, that your wifi AP / router is on
Since it's a startup script reboot the computer and see if it has the desired functionality sudo shutdown -r now
http://wiki.debian.org/LSBInitScripts
DEFAULT-START and DEFAULT-STOP can be the "init numbers", e.g. S (??) or 2 3 4 5 and stop on 0 or 6 (halt or reboot).
REQUIRED-START variables:
$local_fs = all local filesystems are mounted. All scripts that write in /var/ need to depend on this, unless they already depend on $remote_fs.
$network = low level networking (ethernet card; may imply PCMCIA running)
$named = daemons which may provide hostname resolution (if present) are running. For example, daemons to query DNS, NIS+, or LDAP.
$portmap = daemons providing SunRPC/ONCRPC portmapping service as defined in RFC 1833 (if present) are running all remote
$remote_fs = all filesystems are mounted. In some LSB run-time environments, filesystems such as /usr may be remote. If the script need a mounted /usr/, it need to depend on $remote_fs. Scripts depending on $remote_fs do not need to depend on $local_fs. During shutdown, scripts that need to run before sendsigs kills all processes should depend on $remote_fs.
$syslog = system logger is operational
$time = system time has been set, (e.g. using a time program such as ntp, rdate, or the hardware Real Time Clock.
$all = facility supported by insserv to start a script after all the other scripts, at the end of the boot sequence. This only work for start ordering, not stop ordering. It is not possible to depend on a script which depend on $all.