System Services I
Summary:- Introducing System Services
- Advantages Of The Service Mechanism
- DrakXServices
- How Services Work
Introducing System Services
If you happen to open 'System' - 'Services' (or 'Enable or disable the system services') in the Mandriva Control Center, you see a lot of columns, starting with a more or less cryptic name for the service. The second column reads either 'stopped' or 'running', the third is a button which reveals some basic information. Then there's a check box labeled 'On boot' followed by two buttons: 'Start' and 'Stop'. This layout describes in essence what you can do with a service: you can start or stop it and you can configure it to be 'started' automatically at boot time. But what is a service? In contrast to a program, services do not require user input (they 'run in the background') apart from starting or stopping them, and even this can be automated.There are two kinds of services:
- Services which are started and keep running for the duration of a session (i.e. until the system gets shut down). In Unix slang these are also called daemons ('helpful spirit'). These are usually servers of some kind which are started and then wait for incoming requests, like a web server, a mail server, the printer service or a font server.
- Services which are started, run and terminated when finished. These are usually scripts for system maintenance or for enabling certain features, like the 'numlock' script whose sole purpose is to turn on the numlock feature - i.e. being able to use the right-hand number pad on most keyboards for number input - during boot.
The MCC module does what needs to be done, but maybe you like one of the other applications better. You don't need to be afraid of causing inconsistencies when using different utilities since they all use the same (command line) commands, 'service' and 'chkconfig'.
'service' and 'chkconfig'
The 'service' command, a simple shell script in '/sbin', is used to display the status of a service, to start, stop or restart it. This command takes two arguments, the name of the service (i.e. the name of the file in '/etc/init.d') and what should be done in regard to this service:- # service service_name start
- # service service_name stop
- # service service_name restart
- # service service_name status
Advantages Of The Services Mechanism
Being able to control services has several advantages:- Reducing system load:
Although daemons are 'sleeping' most of time they nevertheless use up a certain amount of system memory. The 'service' interface allows you to start services on demand, for example you can start the printer daemon right before printing and stop it when finished. - Increasing system security:
Daemons are listening on certain ports for events. More daemons running mean more open ports which in turn provide more possible points of attack. On the other hand there are services which actively increase system security, like a firewall service. - Avoiding reboots:
If you change the configuration of a daemon, the daemon usually has to be started to let the change take effect. If you install a package which contains a service, the service usually won't start right away but will be configured to be started automatically at boot time.
By controlling services you can fulfill these tasks during runtime. - Shortening boot time:
A good chunk of the time your Linux system needs to boot is taken up by starting or running daemons and other services. If you configure your system to start only those services on boot you need immediately or all the time, you can reduce the boot up time considerably.
DrakXServices
DrakXServices is a graphical tool available from the Mandrakelinux Control Center, System -> Services. At boot time, a number of services (programs running in background) performing a variety of tasks are started. This tool gives the administrator control over those services. http://doc.mandrivalinux.com/MandrakeLinux/101/en/Starter.html/images/drakxservices-main.png A detailed description is given on the ~Starter Guide, Chapter 20. Configuration: System SectionHow Services Work
This section is intended for people who not only want to know what to do but also why things are done this way. You can live on Linux without this, but in my opinion it's more fun when you get a grasp of the concept behind the scenes.Service Scripts
If you are curious, you might want to know now how the system knows which services are available. The service scripts are located in '/etc/init.d' ('/etc/rc.d/init.d' on older releases).Graphical utilities like the Mandrake Control Center just assume that every script in this directory controls a service, so if you put a script there, it will appear on the Services module of the Mandrake Control Center and in similar utilities, too, and can also be handled directly via the commands 'service' and 'chkconfig'. A service script contains the commands to at least start or stop a service. Have a look at a basic template for a service script:
~#1.1 /bin/sh ~# chkconfig: runlevels order_start_link order_stop_link ~# description: short description of service . /etc/rc.d/init.d/functions case "$1" in start) echo -n "Starting service: " command(s) to start service echo ;; stop) echo -n "Shutting down service: " command(s) to stop service echo ;; status) status service_name ;; ~*) echo "*** Usage: service_name {start|stop|status}" exit 1 esac exit 0
Of course you have to make sure that service_name really is the name of the script and that the script has the executable bit set.
Runlevel Links
Some services depend on other services. The 'httpd' service (Apache web server) for example won't start correctly if the 'network' script hasn't already set up the network interfaces. How is the order in which services are started on boot determined? Have a look at the '/etc/rc.d' directory: $ ls /etc/rc.d~~ init.d/ rc0.d/ rc2.d/ rc4.d/ rc6.d/ rc.local rc.sysinit* rc* rc1.d/ rc3.d/ rc5.d/ rc.firewall rc.modules* You see the 'init.d' from '/etc' here again (in fact it's the same) and then several directories and files starting with 'rc' ('rc' is short for 'runcom{mand}').
In Mandrake Linux releases 8.0 and later, these files and directories are also accessible directly from the '/etc' directory. If you now look into one of those 'rcnumber' subdirectories, you will find a bunch of files, some of them starting with 'S' and some of them with 'K' followed by a two-digit number. 'S' is short for 'start' and 'K' stands for 'kill'. The numbers imply the order in which starting and killing services takes place. In fact all those files are just links to their appropriate counterparts in '/etc/init.d'.
'S12syslog' for example is a link to '/etc/init.d/syslog' and gets started after 'S10network' which links to '/etc/init.d/internet' but before 'S15cups'. You don't have to create these links yourself when configuring a standard service with 'chkconfig' because most scripts already contain a 'chkconfig' line, like for example the 'network' service script:
#1.1 /bin/bash ~# ~# network Bring up/down networking ~# ~# chkconfig: 2345 10 90 ~# description: Activates/Deactivates all network interfaces ~# configured to start at boot time.
# Default runlevel. The runlevels used by RHS are: ~# 0 - halt (Do NOT set initdefault to this) ~# 1 - Single user mode ~# 2 - Multiuser, without NFS ~# 3 - Full multiuser mode ~# 4 - unused ~# 5 - X11 ~# 6 - reboot (Do NOT set initdefault to this)
Upon switching runlevels, e.g. by starting the graphical interface or stopping it, by booting the machine or rebooting it etc, the script '/etc/rc.d/rc' is executed. This script in turn looks up the start and kill links in the appropriate 'rcnumber' directory (where number matches the number of the runlevel the system is switching to) and executes them, i.e. starts or stops the services as configured for the runlevel the system is switching to. This explains why '/etc/rc.d/rc.0' and '/etc/rc.d/rc6' almost only contain 'kill' links since all services are stopped when halting or rebooting the machine. This elaborate system is called the System V Init Process, because it has been introduced with version five of UNIX®. Apart from Slackware, all major Linux distributions use it. Slackware and *BSD operating systems use the BSD-style Init Process which more or less packs the whole initialization and service maintenance work into one file. 1.1 How To Put This System To Use The 'chkconfig' program allows you a finely grained control on what services are started or stopped on which runlevels. Under certain circumstances it can be useful to reconfigure services.
Take the GPM service, for example. GPM is the 'General Purpose Mouse Daemon'. You will need to have it running when you want to use a mouse on runlevel 3 (console). On runlevel 5 (graphical interface), it is next to useless, it can even cause incompatibilities to occur. Using 'chkconfig' you can configure the gpm service only to be run on runlevel 3: ~# chkconfig level 3 gpm on
~# chkconfig level 5 gpm off This will create a start link in 'rc3' and a kill link in 'rc5'. The next pages of this article will provide you with an overview of all service scripts available in Mandriva Linux. section index Next Item: Annotated List of System Services a-h
Related Resources:
~SysAdminGuide, 9~Chapter 20. Configuration: System Section
man init Revision / Modified: June 8, 2005
Author: Tom Berger/Wiki Community Legal: This page is covered by the GNU Free Documentation License. Standard disclaimers of warranty apply. Copyright LSTB and Mandrakesoft.
System Services I
Version 1.7 last modified by awilliamson on 09/06/2005 at 01:27
Version 1.7 last modified by awilliamson on 09/06/2005 at 01:27
Document data
- Lost account?
- Join the community, be part of the Club: it's free!
- Get the PWP Download Subscription!
Mandriva.com
Store
Club


