See LXF 114 p48, 'Banish Your Daemons' |
Runlevels are defined levels in which a linux operating system can start. Daemons (or services) are scripts/programs that run in the background constantly (like apache or mysql are services that are always running) and are usually executed at startup by the defined runlevel. Runlevels are identified by a number from 0 - 6, but each linux distribution may use those numbers a bit differently. Basically a runlevel determines which daemons to execute at startup. Runlevel 1 is typically known as single-user mode, it only executes the minimal set of scripts to get the system up and running (meaning you won't have xorg, mysql or apache... running at this level). This mode is often used as a recovery mode since most of your daemons are not running at this point. In many distros, the default runlevel is 3 or 5, this is the normal full mode, meaning all your normal services are started including your xorg graphical environment.Each linux distribution is a bit different, even if it uses the standard System V, it may have additional helper scripts to start/stop/enable/disable services. Read below for distro specific daemon information. |
Many distros use a standard boot method, or a standard series of executed scripts, known as the "System V" (system five) init scripts. System V is just a script design and layout. When your system boots, it executes a series of scripts and then it starts your daemons. Daemon scripts are located in /etc/init.d. At certain runlevels, some of these daemons may or may not be started. Which services start at which runlevel is defined by the /etc/rc0.d/, /etc/rc1.d/, ... folders. So all daemons which will run at startup for runlevel 5 are in the /etc/rc5.d/ folder. The scripts in those runlevel folders are not the real scripts, but rather a symbolic link to the actual scripts in /etc/init.d/. The symbolic links in those folders start with a S if they are to be enabled, or a K if they are to be disabled and are followed by a number which is the order they will be executed. So /etc/rc2.d/S20mysql will start before /etc/rc2.d/S30apache and /etc/rc2.d/K20pure-ftpd is disabled. All services in the /etc/rcS.d/ folder are always executed first, at any runlevel, they can also be disbaled by renaming with a K instead of an S. When you shutdown your computer, you are actually executing a runlevel (different per distro), usually 0 or 6. When you execute a shutdown or change a runlevel, any link starting with a K in that runlevel folder will be executed with the stop command. So you will notice all your services should be in the rc0.d or rc6.d folder with a K, that means on computer shutdown or reboot, stop all daemons nicely. Or you will notice many services are in the rc1.d folder as K. This is because runlevel 1 should only have a few daemons running, all others should be shutdown.To manage which daemons execute on startup you can manually modify those symbolic links or you can use the helper scripts defined by your linux distro. |
Before 2006, ubuntu used the standard System V boot script method. Around 2006 ubuntu introduced what they call Upstart. Upstart is a new boot and daemon design. To maintain backward compatibility ubuntu created a System V legacy system which allows you to control ubuntu's deamons much like you would any other System V system. Ubuntu still has the /etc/init.d/ daemons script folder and all the runlevel symbolic links are in the corresponding /etc/rcXX.d folders, but they prefer you use their new Upstart method to manage your services. Since most services have been converted to upstart, you may find none of them appear in your rcXX.d folders, even K for shutdown on runlevel 0 or 6, thats OK, upstart manages their start and stop functionality via their config in /etc/init/myservice.confWith Upstart, runlevels become obsolete because services are not executed at startup like the old System V, they are executed only if and when they are needed. You can read more about Ubuntu's System V and Upstart methods here https://help.ubuntu.com/community/UbuntuBootupHowto
</box>In Ubuntu, you can still use the old legacy System V method they provide (see System V Above), or use their new Upstart methods:
Service Managers (GUI and CLI)[-][--]Services in Fedora Command Line[-][--]http://linuxhelp.blogspot.com/2006/04/enabling-and-disabling-services-during_01.html**Red Hat and Red Hat based Linux distributions (like fedora, centos...) make use of the script called chkconfig to enable \and disable the system services running in Linux.**For example, to enable the apache webserver to start in certain run levels,you use the chkconfig script to enable it in the desired run levels asfollows:
Ubuntu/Debian[-][--]Ubuntu also has chkconfig, but not in any repositories, though I did find an article here http://ubuntuforums.org/archive/index.php/t-20583.html which says you can install chkconfig with (untested)
Graphics Service Managers[-][--]BUM[-][--]Ubuntu has its built in service manager, so does fedora. Another good package you can download is \Boot Up Manager (bum).
Test Performance[-][--]A nice way to test boot performance is a program called Boot Chart. It starts just be fore any boot script, and ends \after all other scripts, then generates a nice graphic of your systems performance.
Autostart a daemon in Arch Linux[-][--]edit the /etc/rc.conf and add to the DAEMONS=(...) they do start in order Create a Daemon Script (not tested)[-][--]
Resources[-][--]FIX: add regular daemon control (/etc/init.d/), add archlinux, add program for upstart... |