1

The scripts need to be executed at boot time was put in the /etc/init.d,and files contained in /etc/rc*.d was the symbolic links point to files in /etc/init.d.Furthermore the names of the symbolic links indicate whether the service is to be started (S*) or stopped (killed, K*) in specific runlevel. I issue a command “ls -al” to inspect the files in the /etc/rc3.d,the output as follows:

drwxr-xr-x.  2 root root 4096 Apr  6 23:04 .
drwxr-xr-x. 10 root root 4096 May 22  2015 ..
lrwxrwxrwx.  1 root root   20 May 22  2015 K50netconsole -> ../init.d/netconsole
lrwxrwxrwx.  1 root root   17 May 22  2015 K90network -> ../init.d/network
lrwxrwxrwx.  1 root root   17 May 22  2015 S00livesys -> ../init.d/livesys
lrwxrwxrwx.  1 root root   16 Apr  6 23:04 S85mongod -> ../init.d/mongod
lrwxrwxrwx.  1 root root   15 May 31  2015 S95jexec -> ../init.d/jexec
lrwxrwxrwx.  1 root root   22 May 22  2015 S99livesys-late -> ../init.d/livesys-late

I supposes that start script and kill script should appear in pairs, but it`s wrong,why?

LoremIpsum
  • 163
  • 1
  • 4

1 Answers1

0

If this is for RHEL6 or similar breed of Linux, these scripts are generally managed by chkconfig(8) , which makes sure there is EITHER a start script or a stop script for each runlevel, for each service, not that they are made in pairs. (Not sure about Ubuntu or others).

From man page for chkconfig:

Note that for every service, each runlevel has either a start script 
or a stop script.  When switching runlevels, init will not re-start an 
already-started service, and will not re-stop a  service that is not running.

...

--add name
  This option adds a new service for management by chkconfig.  When a new service is added, 
  chkconfig ensures that the service has either a start or a kill entry in  every  runlevel.  
  If  any  runlevel is missing such an entry, chkconfig creates the 
  appropriate entry as specified by the default values in the init script.

An answer to another question about runlevels describes the naming convention.

Now, the naming scheme is also quite simple. Scripts whose name begins with an S will be started at the runlevel in question while those whose name begins with K will be killed.

If you look at the runlevel change script /etc/rc, you can see how whenever the runlevel is being changed the S* are executed with start input parameter, AFTER the K* scripts are executed with the stop parameter. Having both K and S scripts would mean the script is stopped and started in each run level.

# rc            This file is responsible for starting/stopping
#               services when the runlevel changes.
...
# First, run the KILL scripts.
for i in /etc/rc$runlevel.d/K* ; do
        ...
        $i stop
done
# Now run the START scripts.
for i in /etc/rc$runlevel.d/S* ; do
        ...
                exec $i start
        ...
done

I am only looking at RHEL6 machine, so if someone can confirm how other distros differ, please do.

hilcharge
  • 359