This whole article is obsoleted by systemd and systemctl.
Here's a template for init (source) :
#!/bin/bash
######################################### myInitScript.sh ###########################################
# chkconfig: 2345 20 80
# description: Description comes here....
#
# version: 20160609
########################################## ##########################################################
UNIX_SUCCESS=0
UNIX_FAILURE=1
# Source function library.
. /etc/init.d/functions maybe not a good idea
start() {
# code to start app comes here
# example: daemon program_name &
}
stop() {
# code to stop app comes here
# example: killproc program_name
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
# code to check status of app comes here
# example: status program_name
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
esac
exit $UNIX_SUCCESS
When the system runlevel changes (increase/decrease runlevel, boot and shutdown), init scripts (aka startup scripts) are executed with a single argument being one of (source) :
This whole article is obsoleted by systemd and systemctl.
This'll cause the rc.local script to be run last during the bootup process (because of the 99). This is generally what you want to do, to make sure your network connection is up and all the basic services are started before custom init script runs.
If for some reason you have commands you need to run sometime earlier in the bootup process, you can create multiple scripts this way. It doesn't matter what you name them, just stick them in /etc/init.d, then symlink to them from /etc/rcX.d. Make sure the name of the symlink starts with a capital S, and is followed by a two-digit number : the lower the number, the sooner during bootup the script will be run. Don't run it too early or your filesystems might not even be mounted yet !
If you want a script to ALWAYS be run, no matter what runlevel you boot into, even in Single User Mode (runlevel 1), make a symlink in /etc/rcS.d instead of /etc/rcn.d.