For every runlevel (0 6) there is an folder /etc/rc[N].d
In every directory there are symbolic link either starts with an "S" or with a âKâ. "S" to start e "K" to stop. The scripts are executed in a lexical sort manner of the filename, in other words S10script will be executed first than S20myscript. For example :
we have two simple scripts, the second.sh script must be execute after the fist.sh script in the current runlevel.
root@localhost init.d]# cat /etc/init.d/first.sh
#!/bin/bash
#
echo 'I am the first' >> /var/log/messages
root@localhost init.d]# cat /etc/init.d/second.sh
#!/bin/bash
#
echo 'I am the second' >> /var/log/messages
What is my current level?
[root@localhost init.d]# runlevel
N 5
Now we need a symbolic link starting namely S(N)myScript for the first and S(N+1)mysecondScript:
root@localhost rc5.d]# ln -s /etc/init.d/first.sh /etc/rc5.d/S1first
root@localhost rc5.d]# ln -s /etc/init.d/second.sh /etc/rc5.d/S2second
We can reboot and check the messages log:
[root@localhost ~]# cat /var/log/messages | grep "I am" -A 1 -B 1
Dec 13 13:53:36 localhost rpc.statd[3468]: Version 1.0.9 Starting
I am the first
Dec 13 13:53:37 localhost hcid[3532]: Bluetooth HCI daemon
--
Dec 13 13:53:40 localhost automount[3689]: lookup_read_master: lookup(nisplus): couldn't locate nis+ table auto.master
I am the second
Dec 13 13:53:41 localhost gpm[3785]: *** info [startup.c(95)]:
Tested on old Centos5