Service Management

One key skill for Linux system administrators is service management. You can start and stop current services with the scripts in the /etc/rc.d/init.d directory. In addition, you can ensure that the services of your choice are active only at specific runlevels.

/etc/rc.d/init.d Scripts

The services that you install in Red Hat Linux have their own scripts in the /etc/rc.d/init.d directory. It s likely that you have a substantial number of scripts on your system; a sample from my desktop computer is shown in Figure 13.1.

click to expand
Figure 13.1: Service scripts in /etc/rc.d/init.d

Take a look at some of these scripts. Open them up in a text editor. Near the end of each script, you should see a series of commands similar to Figure 13.2. This particular script, smb , manages Samba. Some of the commands in different scripts do vary.

click to expand
Figure 13.2: The innards of a service script

As you can see Figure 13.2, you can run several actions for that particular service, as shown in Table 13.3. The table simply reflects the actions shown in Figure 13.2; the actions associated with a different script will vary.

Table 13.3: Service Script Actions

Action

Description

start

Starts the service; equivalent to the service script start command.

stop

Starts the service; equivalent to the service script stop command.

restart

Shuts down the service, then starts it again; equivalent to the service script restart command.

reload

Makes the service reread any applicable configuration files without restarting; equivalent to the service script reload command.

status

Provides the current status of the service; equivalent to the service script status command.

condrestart

If the service is locked, this switch shuts down the service, then starts it again; equivalent to the service script condrestart command.

For example, if you wanted to restart Samba, you could run one of the following two commands as the root user :

 # /etc/rc.d/init.d/smb restart # service smb restart 

Activation at Different Runlevels

You can make a service start and stop at different runlevels. For example, take a look at Figure 13.3.

click to expand
Figure 13.3: Services at runlevel 3

You can see from the /etc/rc.d/rc3.d directory that Apache is killed when Linux starts runlevel 3 ( K15httpd ). If you want to start that service at runlevel 3, you need to change it into a start script. The standard method is the chkconfig command. To list the current runlevels associated with Apache ( httpd ), run the following command:

 #  chkconfig --list httpd  httpd   0:off  1:off  2:off  3:off  4:off  5:off  6:off 

The output shows that Apache isn t started at any runlevel. To start it, you need to activate it at the desired runlevels. For example, the following command starts Apache at runlevels 3 and 5, in standard multiuser and GUI modes:

 # chkconfig --level 35 httpd on 

You can confirm the effect by listing the files at runlevels 3 and 5; in this case, you ll see the S85httpd start script in each directory ( /etc/rc.d/rc3.d and /etc/rc.d/rc5.d ). Alternatively, just run the following command:

 #  chkconfig --list httpd  httpd   0:off  1:off  2:off  3:on  4:off  5:on  6:off 

Several graphical tools are available. For example, you can use ntsysv --level runlevel to view the services at different runlevels. For example, the ntsysv --level 5 command could illustrate active services at runlevel 5, as shown in Figure 13.4.

click to expand
Figure 13.4: Managing services with ntsysv
 


Mastering Red Hat Linux 9
Building Tablet PC Applications (Pro-Developer)
ISBN: 078214179X
EAN: 2147483647
Year: 2005
Pages: 220

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net