Friday, August 20, 2010

Using Init.d in Ubuntu

As the system boots, kernel drivers are loaded into memory and the init process begins setting the runlevel.At each runlevel, different software drivers and services are started. Which ones are started and the order in which they are started is determined by /etc/init.d/ and the rc script. There are eight rc directories: /etc/rc0.d, /etc/rc1.d, ... /etc/rc6.d, and /etc/rcS.d. These correspond with the different runlevels: 0 through 6, and S for system startup.

In each of these directories are symbolic links to files in /etc/init.d/. The name of the symbolic link determines whether the script is called when starting (S) or leaving (K for kill) the runlevel (see Listing 3-2). Each name also has a number, used to order when the service is started. This way,
dependent processes can be started in the right order. For example, S13gdm is started before S99rmnologin since the Gnome Display Manager (gdm) should be started before the user login prompt.

The directory /etc/init.d/ contains the actual control scripts (without the S/K and number). Each script has a start, stop, and restart option. So, for example, if you want to restart the network and stop the cron server, you can run:

sudo /etc/init.d/networking restart
sudo /etc/init.d/cron stop

To make system changes happen after the next reboot, add the appropriate S or K script to the appropriate runlevel directory.

Listing 3-2: Directory Contents of /etc/rc6.d
$ ls /etc/rc6.d
K01gdm K20zvbi
K01usplash K21postgresql-8.3
K01xdm K25hwclock.sh

Listing 3-2: Directory Contents of /etc/rc6.d (continued)
K09apache2 K25mdadm
K16dhcdbd K50alsa-utils
K19aumix K59mountoverflowtmp
K20apport K80nfs-kernel-server
K20avahi-daemon K99laptop-mode
K20cpufreqd README
K20dkim-filter S01linux-restricted-modules-common
K20dkms_autoinstaller S15wpa-ifupdown
K20libvirt-bin S20sendsigs
K20nas S30urandom
K20nfs-common S31umountnfs.sh
K20nvtv S32portmap
K20postfix S40umountfs
K20privoxy S51dmraid
K20snort S60umountroot
K20sysstat S90reboot
K20xinetd


RUNNING RAGGED
Ubuntu includes seven different runlevels: 0-6 and S. Many of the runlevels provide very specific services. For example, level 0 is a system halt, 1 provides for single-user mode, 6 reboots the system, and S provides services that are needed to start the system regardless of runlevel. The remaining runlevels provide different types of multi-user support. Usually the system uses level 2. This provides a graphical user interface (when available) and network support. The default level 3 provides support for accessibility devices, such as a Braille TTY display. Finally, levels 4 and 5 usually look like level 2, but you can modify them if you need customized run-time environments.

Source of Information : Wiley Ubuntu Powerful Hacks And Customizations

No comments: