1827844 Members
1511 Online
109969 Solutions
New Discussion

Re: Order of services

 
Tonatiuh
Super Advisor

Order of services

Red Hat Enterprise Linux 4

I want to know the order of execution of services in init (when shutdown)

Service A: # chkconfig: 35 98 11
Service B: # chkconfig: 35 99 10

At startup it executes (I know how it works):
1) Service A
2) Service B

At shutdown it execute (I am not sure how it works):
1) ????
2) ????
4 REPLIES 4
Steven E. Protter
Exalted Contributor

Re: Order of services

/etc/rc5.d

The last directory of the startup directories.

ls /etc/rc1.d
ls /etc/rc2.d
ls /etc/rc3.d
ls /etc/rc4.d
ls /etc/rc5.d

The order you see of the soft links starting with a capital S. That is the startup order, lowest to highest.

The shutdown order is in reverse from 5 down to 1 and beyond, the soft links starting with a K.

They all soft link to combined shut/start scripts in /etc/init.d

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Stuart Browne
Honored Contributor

Re: Order of services

The startup routines on the various unicies are confusing at times.

SEP is right about the structures, but here's a little more.

The different /etc/rcX.d structures are the different available run levels on a system (run levels 0-6 + s & S usually, but Linux actually has 0-9 + s & S). Have a quick look at the comments in '/etc/inittab' and 'man init' as to what the different levels are for.

On RH Linux systems, at the change of init levels, the script '/etc/rc.d/rc' is executed. This is what actually launches the '/etc/rcX.d' scripts in their defined order. This script is defined in '/etc/inittab' as lines starting with 'lX' (where X is the run-level you are changing to).

Now here's where it starts differing between the different varients.

The script files linked to in '/etc/rcX.d' (they are in different places in different unicies) get executed based on their name in that directory, in glob-order.

The quick way to check what that means is to run:

echo /etc/rc6.d/*

It will output a single line listing all of the script files in alphabetical/numerical order.

The standard is to have files starting with uppercase S or K for startup and for kill, followed by two digits, designating their order of execution. So on a RH box, we see something like this (ok, this is from my FC4 box):

# echo /etc/rc6.d/K*
/etc/rc6.d/K01yum /etc/rc6.d/K02haldaemon /etc/rc6.d/K03messagebus /etc/rc6.d/K05anacron /etc/rc6.d/K05atd /etc/rc6.d/K05saslauthd /etc/rc6.d/K10dc_server /etc/rc6.d/K10psacct /etc/rc6.d/K12dc_client /etc/rc6.d/K15gpm /etc/rc6.d/K15httpd /etc/rc6.d/K25sshd /etc/rc6.d/K30sendmail /etc/rc6.d/K30spamassassin /etc/rc6.d/K35cyrus-imapd /etc/rc6.d/K50netdump /etc/rc6.d/K50snmpd /etc/rc6.d/K50snmptrapd /etc/rc6.d/K50xinetd /etc/rc6.d/K56acpid /etc/rc6.d/K60crond /etc/rc6.d/K66mDNSResponder /etc/rc6.d/K67nifd /etc/rc6.d/K72autofs /etc/rc6.d/K74apmd /etc/rc6.d/K74lm_sensors /etc/rc6.d/K74nscd /etc/rc6.d/K74ntpd /etc/rc6.d/K75netfs /etc/rc6.d/K85mdmonitor /etc/rc6.d/K85mdmpd /etc/rc6.d/K87auditd /etc/rc6.d/K87named /etc/rc6.d/K88syslog /etc/rc6.d/K89netplugd /etc/rc6.d/K89rdisc /etc/rc6.d/K90network /etc/rc6.d/K92iptables /etc/rc6.d/K94diskdump /etc/rc6.d/K95kudzu

# echo /etc/rc6.d/S*
/etc/rc6.d/S00killall /etc/rc6.d/S01reboot

This means, when changing to init level 6 (someone issued a 'shutdown -r' or some other 'reboot' command), it will start by executing all the K scripts (kill) with the 'stop' argument. Once they are completed, it will then execute all the S scripts with a 'start' argument.

If you're good at reading through a shell script, you can walk through '/etc/rc.d/rc' to see the actual voo-doo, but here's the guts of it:

## stripped a bit for clarity ##

# First, run the KILL scripts.
for i in /etc/rc$runlevel.d/K* ; do
# Check if the subsystem is already up.
subsys=${i#/etc/rc$runlevel.d/K??}
[ -f /var/lock/subsys/$subsys -o -f /var/lock/subsys/$subsys.init ] \
|| continue
# Bring the subsystem down.
action $"Stopping $subsys: " $i stop
done

# Now run the START scripts.
for i in /etc/rc$runlevel.d/S* ; do
# Check if the subsystem is already up.
subsys=${i#/etc/rc$runlevel.d/S??}
[ -f /var/lock/subsys/$subsys -o -f /var/lock/subsys/$subsys.init ] \
&& continue
# Bring the subsystem up.
if [ "$subsys" = "halt" -o "$subsys" = "reboot" ]; then
exec $i start
fi
action $"Starting $subsys: " $i start
done

So, if stuff is running, kill it off nicely. Once you've killed everything that asked to be killed, start things which need starting.

In the case of INIT 6, you stop all the services.. As a stop-gag, you then run 'S00killall' which checks other subsystems are running and issues nice stops to them, then 'S01reboot' which does final cleanup, unmounting filesystems, killing off remaining processes, before finally rebooting.

So, in answer to the last question, it shuts things down with the same ordering concept as the start-up.

General rule of thumb for a RH box though. The startup+shutdown in the chkconfig linen should add up to 100.

i.e., gpm: # chkconfig: 2345 85 15

Start at position 85 (i.e. late), finish at 15 (i.e. early).

If you stick to this rule of thumb, then everything should shut down in the dependancy order that they started up in. Keeps it nice and simple.

Have fun!
One long-haired git at your service...
Stuart Browne
Honored Contributor

Re: Order of services

.. and Whoa .. talk about loss of formatting! :)
One long-haired git at your service...
Stuart Browne
Honored Contributor

Re: Order of services

Ahh, just an IE7 bug it seems.. yay..
One long-haired git at your service...