Linux Daemons

Published: Monday, 25 October 2010

Starting and Stopping Linux Daemons

See also upstart if you are using Ubuntu.

You can start and stop installed daemons such as ’ntp’ (network time protocol – this will synchronize your clock) by running the start and stop scripts in /etc/init.d/

# /etc/init.d/ntp start
ntpd: time slew -0.014128s
Starting network time protocol daemon (NTPD)                          done

# /etc/init.d/ntp stop
Shutting down network time protocol daemon (NTPD)                     done

To have this turn on automatically when the server is rebooted you need to know about runlevels.

A runlevel is a mode the server is currently in. You can see the different levels in /etc/inittab.

My box has the following:

runlevel 0  is  System halt   (Do not use this for initdefault!)
runlevel 1  is  Single user mode
runlevel 2  is  Local multiuser without remote network (e.g. NFS)
runlevel 3  is  Full multiuser with network
runlevel 4  is  Not used
runlevel 5  is  Full multiuser with network and xdm
runlevel 6  is  System reboot (Do not use this for initdefault!)

To see the current runlevel, use the runlevel command.

# runlevel
N 5

This tells us we are in runlevel 5.

To change the daemons to be stopped or started at different runlevels, use the chkconfig program.

To turn on ntp when runlevel 5 is reached, run:

# chkconfig ntp 5