Managing Running Services


After looking at the lengthy process lists in the preceding sections, you might be wondering just what most of the listed processes actually are. Even though Fedora Core 4 is intended to be a desktop-oriented operating system, many of these pro cesses are system and network services of the sort that servers typically offer. In the Unix world, even desktops often need to perform server-oriented tasks such as accepting remote logins or transferring files across the network.

As Linux operates, some of the services it offers are running and others aren't. The default set of services running at any given time is determined by the system's current runlevel. A Linux system is always at a specific runlevel; available runlevels are numbered 0 through 6. Each runlevel is associated with a specific list of services, which are started when the system enters the runlevel.

Changes to the list of running services can be made by manipulating the list of services associated with the current runlevel or by changing the default runlevel at which the system operates; both of these tasks are discussed in the following sections.

Understanding Runlevels

When your Linux system boots, the first process started by the kernel (the core of the operating system) is called init. The init process is responsible for starting all other processes in the systemfrom the system and network services to the graphical desktop environment. So, how does the init command know what to start?

One primary file, the /etc/inittab file, controls just what init does each time the system starts. A complete description of the format of the /etc/inittab file is beyond the scope of this book, and is better left to an advanced text on system administration. Near the beginning of the /etc/inittab file, however, you see a line that begins with the letters id, something like this one:

 id:5:initdefault: 

This line decides the default runlevel of your Fedora Core 4 system. The system in this example has a default runlevel of 5. Recall that seven runlevels are available, numbered 0 tHRough 6. A list of these runlevels and their traditional meanings is shown in Table 28.2.

Table 28.2. The Linux Runlevels and Their Meanings

Runlevel

Description

0

Halt. When this is the current runlevel, the system is in the process of shutting down.

1

Single-user. This runlevel includes little more than a single virtual console running a single command line. Virtually every other service is disabled. This runlevel is usually used for critical system maintenance, such as recovering from hack attacks or repairing disk corruption.

2

Multiuser, sans file services. This runlevel starts most services but does not enable network file service connections.

3

Full multiuser. This runlevel starts all enabled services but does not start the X Window System (or, by extension, any Linux desktop environment). Instead, users are able to use virtual consoles only.

4

User-defined. No conventional definition applies to runlevel 4; it is fully open to user configuration.

5

Full multiuser with X. This runlevel starts all enabled services and the X Window System and Linux desktop environments. Most Fedora Core 4 users find runlevel 5 to be their default.

6

Reboot. When this is the current runlevel, the system is in the process of rebooting.


At any given time, a Linux system is running at a runlevel between 0 and 6. Controlling the list of automatically started services on your Linux system is a matter of setting a default runlevel and then configuring the services associated with that runlevel. You can change the default runlevel at which your system starts by editing the id line in the /etc/inittab file and inserting the runlevel number of your choice. For example, if you want to start with a default runlevel of 3, you edit the line to read as follows:

 id:3:initdefault: 

You learn how to control the list of services associated with each runlevel by using the chkconfig command in the next section.

You Can Change Your Runlevel in Midstream

You can change your system's current runlevel without rebooting. This has the effect of changing the list of currently active services as well. To do so, call the init command by hand, supplying the desired runlevel as an argument. For example, to switch to runlevel 3 without rebooting, you type the following:

 /sbin/init 3 

After you enter the command, the system takes a few moments to settle down as processes are started and stopped before the system enters runlevel 3, where it remains until you switch again explicitly or reboot.


Selecting Automatically Started Services

In Fedora Core 4, the /sbin/chkconfig command is used at the command line to manage the list of services that are started automatically each time the system starts at a given runlevel. To see a list of available services and the current status of each with respect to each runlevel, call the chkconfig command using the --list option. The output appears in two parts, as shown in the following output fragments:

 [root@workstation20 you]# /sbin/chkconfig --list NetworkManager   0:off    1:off   2:off    3:off   4:off   5:off   6:off acpid            0:off    1:off   2:off    3:on    4:on    5:on    6:off anacron          0:off    1:off   2:on     3:on    4:on    5:on    6:off apmd             0:off    1:off   2:on     3:on    4:on    5:on    6:off atd              0:off    1:off   2:off    3:on    4:on    5:on    6:off [...] vncserver        0:off    1:off   2:off    3:off   4:off   5:off   6:off winbind          0:off    1:off   2:off    3:off   4:off   5:off   6:off xfs              0:off    1:off   2:on     3:on    4:on    5:on    6:off ypbind           0:off    1:off   2:off    3:off   4:off   5:off   6:off yum              0:off    1:off   2:off    3:off   4:off   5:off   6:off [root@workstation20 you]#  

Too Much Information from chkconfig list?

Remember, you can page the lengthy output of the chkconfig --list command through a pager such as more by using pipes:

 /sbin/chkconfig --list | more 


There are two components to the output of the chkconfig command:

  • The first half of the output lists a number of system and network services in the first column; subsequent columns list the on or off status of that service in each runlevel, from 0 through 6.

  • The second half of the chkconfig output, which is present if you have installed many of the network services discussed in Chapter 33, "Offering Network File Services," or 34, "Offering Web and FTP Service," lists a number of more basic services managed by the xinetd service. Each of the more basic xinetd services is either on or off globally, for all runlevels for which xinetd is active.

A complete listing of, and set of descriptions for, all these services is beyond the scope of this book and better left to a book on Unix-style networking. However, some of the best-known services that can appear in the output of chkconfig are described in Table 28.3.

Table 28.3. The Most Common Services Manageable by chkconfig

Service

Description

httpd

The Apache web server is used to answer incoming http requests to your Linux system.

sendmail

The Sendmail SMTP server is used to enable your Linux system to act as a full-fledged SMTP mail server.

nfs

The Network File System service is used to enable your Linux system to act as a file server to other Unix or Linux computer systems.

named

The BIND service is used to enable your Linux system to act as a domain name server to other computers on your network.

smb

The Samba service is used to enable your Linux system to act as a file server to Windows computer systems.

sshd

The Secure Shell service is used to enable your Linux system to provide secure remote logins.

telnet

The Telnet service is used to enable your Linux system to provide less secure but more backward-compatible remote logins.

vsftpd

The File Transfer Protocol service is used to enable your Linux system to allow incoming File Transfer Protocol (ftp) logins.


You can globally enable or disable any of the services in Table 28.3 or the services in the chkconfig --list output by calling chkconfig and supplying first the name of the service and then the word on or off as an argument. For example, to completely disable both web service and incoming telnet service, you would enter the following two commands:

 [root@workstation20 you]# /sbin/chkconfig httpd off [root@workstation20 you]# /sbin/chkconfig telnet off [root@workstation20 you]# 

You can easily check to see whether your changes have taken effect by using the chkconfig --list command again in combination with the grep command to filter the output. For example, to check on the new status of the httpd service, enter the following:

 [root@workstation20 you]# /sbin/chkconfig --list | grep httpd httpd         0:off    1:off    2:off    3:off    4:off    5:off    6:off [root@workstation20 you]# 

For services not managed by xinetd (those in the first half of the chkconfig listing), you can also enable or disable services on a runlevel-by-runlevel basis by using the --level option, supplying the level to change as the first argument. For example, to reenable web service for runlevel 3 only and verify the result, you enter the following commands:

 [root@workstation20 you]# /sbin/chkconfig --level 3 httpd on [root@workstation20 you]# /sbin/chkconfig --list | grep httpd httpd         0:off    1:off    2:off    3:on    4:off    5:off    6:off [root@workstation20 you]#  

Uninstalled Services

Services that haven't been installed on your system will not be listed in the output of chkconfig. If you find that you want to offer a common network service that hasn't been installed on your system, refer to Chapter 31, "Installing Linux Software."


After making changes to your chkconfig configuration, you need to reboot or use the service command in the next section for the changes you've made to your current runlevel to take effect.

Stopping, Starting, and Restarting Running Services

Sometimes over the course of a network's lifetime, it is helpful to be able to temporarily stop a running service that is normally offered, to temporarily offer a service that is not normally offered, or to restart a running service on your Linux system. Often this is the case when you have changed a configuration file or when a service seems to have become unstable or overloaded.

You do not need to use the chkconfig utility or restart your system to make temporary changes of this sort. You can use the service command to stop, start, or restart running services one by one. To do this, call the service command, supplying the service whose name matches an entry in the chkconfig service list as the first argument and either stop, start, or restart as a second argument.

For example, to start the httpd service when it hasn't already been running, enter the following command:

 [root@workstation20 you]# /sbin/service httpd start Starting httpd:                      [ OK ] [root@workstation20 you]# 

To stop the service once again, call service with httpd as an argument again, but with stop as the second argument instead:

 [root@workstation20 you]# /sbin/service httpd stop Stopping httpd:                      [ OK ] [root@workstation20 you]# 

The restart argument is used in the same way to force a running service to restart, usually after you edit its configuration file (to activate new changes) or if the service has encountered a bug and stopped responding or encountered other problems.

The changes you make to the running status of a service this way last only until the system is rebooted; for example, if you call service with httpd start to start your web server but don't have the httpd service enabled via chkconfig, the next time you reboot, the httpd service is not activated automatically.



    SAMS Teach Yourself Red Hat(r) Fedora(tm) 4 Linux(r) All in One
    Cisco ASA and PIX Firewall Handbook
    ISBN: N/A
    EAN: 2147483647
    Year: 2006
    Pages: 311
    Authors: David Hucaby

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