8.3 Managing Services

A UNIX daemon is a program that runs in the background and is independent of control from a terminal. Daemons are usually started by a system startup script, where there is no controlling terminal although they can also be started from the command line if required. The init daemon is the system and service manager for Oracle Linux. It is one of the first processes that starts at boot time with a PID of 1 and is the ancestor of all processes. Services are started and stopped through init scripts in the /etc/init.d directory. Most services are launched by the init daemon when the system is booted. Many System V UNIX variants use scripts in the /etc/rcN.d/ directories to control which services should be started in run level N. As this model involved having multiple copies of the same script in many different directories,

Oracle Linux adopts the standard of putting all service control scripts in the /etc/init.d/ directory and symbolically linking these scripts from the /etc/rcN.d/ directories. With this arrangement, it is possible to use centralized commands such as chkconfig and service to manage all services from a single interface.

The service command provides a consistent interface for executing the init scripts. The init scripts provide a consistent interface for managing a service by providing options to start, stop, restart, query status, reload, and perform other actions on services. As nearly all services on a server need high privileges, you need to log in as root to control them. You can view the current state of all services by specifying the --status-all option:

# service --status-all
abrtd (pid  2031) is running...
abrt-dump-oops (pid 2039) is running...
acpid (pid  1669) is running...
atd (pid  2146) is running...
auditd (pid  1407) is running...
automount (pid  1817) is running...
...

You can use the chkconfig command to query and modify the system run level at which a service starts. For example, to display the current settings for the httpd service:

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

The output shows that crond starts automatically at boot time for run levels 2, 3, 4, and 5.

You can use chkconfig to prevent a service from startign at certain run levels, for example:

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

You can also use chkconfig to disable a service altogether, for example:

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

The chkconfig command does not affect the state of the service until the run level changes. To disable or enable a service immediately, use the service command, for example:

# service httpd stop
Stopping httpd:                                            [  OK  ]
# service httpd start
Starting httpd:                                            [  OK  ]