Service is the program that resides in memory and provides special functions for system or network. Unix-like system uses daemon processes to serve as services, thus a "service" is sometimes used to refer to a "daemon" in system process list.
Generally, once we start up a Linux system and enter command line mode or graphical environment, a lots of services have already being run to make the system function properly.
The stand alone service can be started alone, and occupy system resources until it is stopped manually. Because it resides in system memory, it can quickly response to the request from client.
Common services of this kind: WWW daemon (httpd), FTP daemon (vsftpd) and so on.
The super daemon is a special daemon process used to manage other service. When there is no request from client, the super daemon keeps other services stopped; when a client request comes in, it wakes up the related service and stops this service after tasks have been finished.
The advantages: services are started and stopped on demand and under control, which is similar to the firewall on the Internet. Also, services do not occupy system resources all the time.
The disadvantages: system needs extra time to load and unload the service on demand, prolong the time of response.
Common services of this kind: telnet service.
The daemon that handles multiple requests at a same time.
The daemon that handles only one request at a same time. The other request must be pending to the waiting list, or fail.
The Daemon that is managed by signals sent from system. Once a request comes in, it is immediately waken up to deal with it. Example: Unix printing system daemon (cupsd).
The daemon that is waken by a regular time interval to do its work. Users need to configure the time and the tasks, so that the daemon will finish them at a specified time. Example: atd and crond.
Note: if you are interested in developing programs, use man 3 daemon
to see details information of system daemons.
Generally, services have a "d" at the end of their names, which indicates they are realized by daemon processes.
In order to provide services, daemons usually need to be started with the environment correctly configured. Also, for management of these services, their running status like PIDs are recorded in directory /var/run. To have all these things done, most Linux distributions provides pre-configured shell scripts to start these service. Just run this script, and it will:
detect the running environment
analyze configurations
write process information
lock status file
and many things so on.
The common places where these shell scripts are put:
/etc/init.d/* : holding almost all startup scripts.
/etc/sysconfig/* : configuration scripts of each system service.
/etc/xinetd.conf and /etc/xinetd.d/* : configuration files of super daemons
/etc/* : Configuration files of other services.
/var/lib/* : databases of services. For example, /var/lib/mysql is used by MySQL database.
/var/run/* : Running status of each program. It is used by shell scripts to manage the process that have already been started, either by sending signals or invoke system calls.
Note: /lib/linux-restricted-modules/ is used to store restricted modules such as closed source drivers. If you do not use any of these modules, please do not enable linux-restricted-modules-common service.
chkconfig is a command line tool for enabling and disabling system services.
Syntax:
chkconfig [--add][--del][--list][Service]
chkconfig [--level<Level>][Service][on/off/reset]
Options:
--add Add the specified system service
--del Delete the specified system service
--level Specify the level that the service is to be started in or stopped in
--list List all services available for chkconfig and their levels
on/off/reset Enable, disable or reset the specified service
See Initialization for explanation of system runlevel.
Example:
To see status of each service in different runlevel:
chkconfig --list
To list status of vsftpd in different runlevel:
chkconfig --list vsftpd
To disable vsftpd in runlevel 3 and 5:
chkconfig --level 35 vsftpd off
To enable vsftpd in runlevel 2, 3 and 5:
chkconfig --level 235 vsftpd on
To disable unused services:
chkconfig --level 235 cups off ## For system that does not have a printer
chkconfig --level 235 smb off ## For system that does not have a network connection
chkconfig --level 235 sshd off ## For system that does not have remove login
chkconfig --level 235 crond off ## For system that does not have regular tasks
chkconfig --level 235 kudzu off ## For system that does not have new hardware installed
Use service
to start, stop, restart and show status of system services.
Syntax:
service Service Command [Options]
Options:
Service Name of the service to deal with; the name should be found in directory /etc/init.d/
-status-all Show status of all stand alone services
--help | -h Show helpful information
Example:
service --status-all ## Show all services
sudo service httpd stop ## Stop service httpd
sudo service httpd start ## Start service httpd
sudo service httpd restart ## Restart service httpd