|
|
System Services ISummary:
Introducing System ServicesIf 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.
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:
The 'chkconfig' command lists, adds, removes and configures services permanently. To have a service started automatically at boot time, you would use: ~# chkconfig service_name on To have it not started automatically: ~# chkconfig service_name off To list all available services and their current configuration: ~# chkconfig ––list The output of this last command will become clearer to you when you've read the next section. More on this command can be found in man chkconfig. Like their graphical counterparts, these commands require you to be 'root'. Nothing forces you to use them instead of MCC or the other utilities, I prefer them because I'm faster at typing a command than at clicking through a graphical interface ;-). Advantages Of The Services MechanismBeing able to control services has several advantages:
DrakXServicesDrakXServices 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 Section How Services WorkThis 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 ScriptsIf 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). 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 If you've already seen a shell script, it's pretty simple. 'chkconfig' and 'description' are explained in the next subsection. The 'functions' line is only needed here to have the 'status' command available. Then there's a 'case' fork which tells the script which commands to execute if the last argument to the 'service' command is either 'stop', 'start' or 'status'. The 'echo' lines provide some feedback, ')' matches all cases in which the last argument isn't one of 'start', 'stop' or 'status' and thus invalid (prints a usage message and exits). Runlevel LinksSome 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 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}'). 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'. 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. The standard configuration for this script is to have it started in the runlevels 2, 3, 4 and 5 with a 'S10network' link in the directories '/etc/rc.d/rc.2' to '/etc/rc.d/rc.5' and stopped in runlevels 0, 1 and 6 with a 'K90network' in the directories '/etc/rc.d/rc.{0,1,6}'. This standard configuration is applied when using the 'reset' option: ~# chkconfig network reset will create exactly these links, whereas ~# chkconfig service_name on always defaults to starts on runlevels 3, 4 and 5 only. What are runlevels then? Runlevels are listed in '/etc/inittab': # 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) During operation, the system always is in one of these runlevels, most of the time either in runlevel 3 (console) or runlevel 5 (X, i.e. the graphical interface). 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. ~# chkconfig ––level 3 gpm on 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. Next Item: Annotated List of System Services a-h Related Resources:~SysAdminGuide, 9 Revision / Modified: June 8, 2005 Legal: This page is covered by the GNU Free Documentation License . Standard disclaimers of warranty apply. Copyright LSTB and Mandrakesoft. |