Starting/stopping particular subsystems

In every system there is a number of special tasks that needs to be performed (in proper order) at startup and shutdown. This usually involves setup (e.g. network setup, sound setup), as well as launching some services (e.g. http server, ssh server). The tasks that needs to be handled in that way are commonly referred to as subsystems or services.

Running of particular subsystems/services can be easily controlled with system scripts. Each vital subsystem/service has its driver script available in /etc/rc.d/init.d/ directory. If you run script without parameters, it displays short info, e.g. network subsystem script displays:

# service network
Usage: /etc/rc.d/init.d/network {start|stop|restart|status}

Most scripts support start, stop, restart, and status argument:

start starts the subsystem/service
stop stops the subsystem/service
restart restarts the subsystem/service. Usually this is equivalent to start and stop, but in some cases it can be different.
status shows the status of the subsystem/service
[root@pldmachine root]# service network stop
Shutting down interface eth0.......................................[ DONE ]
Shutting down interface eth1.......................................[ DONE ]
[root@pldmachine root]# service network start
Setting network parameters.........................................[ DONE ]
Bringing up interface eth0.........................................[ DONE ]
Bringing up interface eth1.........................................[ DONE ]

Starting/stopping services

Every subsystem script contains information in what runlevels that subsystem should be started by default with line like this (example line from /etc/rc.d/init.d/syslog subsystem):

# chkconfig:    2345 30 70

This tells rc-scripts to run the subsystem when entering runlevels 2, 3, 4, 5 (and respectively, to stop subsystem when leaving one of these runlevels). Numbers 30 and 70 are priority levels for start/stop. See chkconfig(8) for details.

Set of subsystems/services run in particular runlevel can be changed with chkconfig command. Some examples:

] # list current status
] # asterisks (***) means the service/subsys is started/stopped in runlevel
]
] chkconfig --list
gpm             0:---   1:---   2:***   3:***   4:***   5:***   6:---
network         0:---   1:---   2:***   3:***   4:***   5:***   6:---
httpd           0:---   1:---   2:---   3:***   4:***   5:***   6:---
random          0:---   1:***   2:***   3:***   4:***   5:***   6:---
qmail           0:---   1:---   2:***   3:***   4:***   5:***   6:---
single          0:---   1:***   2:---   3:---   4:---   5:---   6:---
klogd           0:---   1:---   2:***   3:***   4:***   5:***   6:---
console         0:---   1:---   2:---   3:***   4:***   5:***   6:---
sshd            0:---   1:---   2:---   3:***   4:***   5:***   6:---
nfsfs           0:---   1:---   2:---   3:***   4:***   5:***   6:---
timezone        0:---   1:---   2:***   3:***   4:***   5:***   6:---
syslog          0:---   1:---   2:***   3:***   4:***   5:***   6:---
rc-inetd        0:---   1:---   2:---   3:***   4:***   5:***   6:---

] # exclude sshd service from runlevels 345
] chkconfig sshd off

] # include sshd service in runlevels 345 again
] chkconfig sshd on

Removing/adding service to runlevel takes effect next time the runlevel is changed. It does not automatically start subsystem if one is not running, or stop it if it's already running.

TOC