Starting and Stopping Servers

Starting and stopping servers is a matter of calling the SysV startup scripts and passing them the appropriate parameters. You can do this on a one-time basis to make temporary changes, or you can make permanent changes by changing the names of the links in the startup script link directories for your default runlevel. You can also modify the order in which your servers start or stop.

Making Temporary Changes

Most SysV startup scripts accept several parameters that affect the run status of the servers or other programs they handle. The most important of these parameters are start and stop, which start and stop the service, respectively. You can call these scripts as root and pass them these parameters. Most distributions respond by displaying the status of their efforts; for instance, to start Samba on a Mandrake system, you might type the following command and see the specified output:

Starting SMB services: [ OK ]

Starting NMB services: [ OK ]

The precise nature of the feedback depends on the distribution and the startup script.

This specific example starts two servers, smbd and nmbd, and tells you that the servers have both been started. Chances are these displays will look familiar; most distributions display these messages during the system boot process.

Warning Startup messages aren't entirely trustworthy. Sometimes the SysV startup script will tell you that it's done what you told it to do, when in fact the server has crashed during startup or has failed to shut down when told to stop. If in doubt, use ps or some other process monitoring tool to look for evidence of a running server.

In addition to start and stop, most SysV startup scripts accept a few other parameters. Examples include restart, which restarts a service; reload, which causes the service to load changes to its configuration file; and status, which reports on the status of a service. Check individual scripts to learn what parameters they accept. Frequently, typing the script name with no parameters creates a usage summary:

Usage: /etc/rc.d/init.d/smb {start|stop|restart|status|condrestart}

Any changes you make by calling SysV startup scripts after booting the computer won't persist across boots; when you shut down and restart, the computer will come up in the same state it was in when you last booted. In order to make a change permanent, you must either change the runlevel or change the SysV startup script links.

Making Persistent Changes

One way to make changes permanent is to change the runlevel. If two runlevels' SysV startup script link directories contain different mixes of links, changing the runlevel will change the services available. You can change the runlevel on a one-time basis by typing telinit runlevel, where runlevel is the runlevel number. To make this change permanent, you must edit the/etc/inittab file and change the number in the line that begins id:

id:3:initdefault:

Change 3 to 5, for instance, to have the computer start up in runlevel 5. Typically, runlevels between 2 and 5 don't vary except in their handling of X startup methods;

most runlevels are text-mode runlevels, whereas runlevel 5 starts X and displays a GUI login prompt. You can, however, create custom runlevels if you like, in order to easily switch between different run states. For instance, you might set aside a runlevel as a means of shutting down certain servers for maintenance. Of course, in order to make those changes, you must alter the SysV startup script links.

You can create SysV startup script links just as you can create any other link. For instance, suppose you've found that the apache startup script has no link in the runlevel 3 directory on a Debian system. You might type the following command to create this link:

Thereafter, when you boot the system into runlevel 3, Apache should start. Likewise, if you want to ensure that Apache does not start in runlevel 3, you might type the following command:

# In -s /etc/init.d/apache /etc/rc3.d/K20apache

Of course, you should be sure that a given runlevel directory doesn't have both a start and a stop script. This condition is potentially confusing at best. (SuSE's configuration tools often create this condition, though.) As a general rule, you should create matching scripts for all of the runlevels between 2 and 5, so that if you change your runlevel, you won't find your servers starting or stopping when you didn't intend them to do so. In practice, if you don't change your runlevels frequently, having the appropriate links only in your default runlevel directory should work well.

Setting Server Startup Order

The preceding discussion ignored an issue that's very important but that can be perplexing: What do you use as a sequence number? As a general rule, there is no single correct number; for a single service, it varies from one distribution to another. For instance, Debian uses a sequence number of 20 to start the X Font Server (xfs), whereas SuSE uses a sequence number of 15 for this server. Ultimately, the startup sequence depends on the needs of the individual servers. For instance, many servers work best when started after the network interface is brought up (often by a script called network or networking).

The server shutdown order is similarly constrained by the needs of individual servers. If you shut down a service before the servers that depend on it, those dependent servers might not shut down as smoothly or as cleanly as you like.

If you want to create a new startup or shutdown script, try looking for other scripts of the same type to ascertain a good number. For instance, suppose your Mandrake system isn't starting Postfix in runlevel 5. You might type the following command to learn what numbers are used for the Postfix startup script in other runlevels:

/etc/rc.d/rc0.d/K30 postfix /etc/rc.d/rc1 ,d/K30postfix /etc/rc.d/rc2.d/S80postfix /etc/rc.d/rc3.d/S80postfix /etc/rc.d/rc6.d/K30 postfix

This result reveals that the startup number of 80 is appropriate for Postfix on this system. You can then create an appropriate link using that number and starting with the letter S. If you wanted to shut down Postfix in runlevel 5, you'd use a K30 prefix to the link's filename.

Mandrake and Red Hat both include suggested startup sequence numbers in their default SysV startup scripts, as comments near the start of the scripts. For instance, Mandrake's postfix script includes the following line:

# chkconfig: 2345 80 30

This line tells the system that the server should be active in runlevels 2 through 5, that the startup sequence number is 80, and that the shutdown sequence number is 30. This information conforms to that returned by the previously presented find command, except that for some reason the startup script links for runlevels 4 and 5 had been deleted.

Many of SuSE's SysV scripts contain similar information, but it's stored in a different format—specifically, in lines between comments that read BEGIN INIT INFO and END INIT INFO. Information provided in these comments includes prerequisite SysV startup scripts and default start and stop runlevels.

You may find scripts with the same sequence numbers. These scripts are run in alphabetical order, but the order in which they're run shouldn't matter. Some configuration tools don't enable you to create SysV startup script links with identical sequence numbers.

0 0

Post a comment