update-rc.d class

Services which need to be started during boot need to be registered using the update-rc.d command. These services are required to have an init script which is installed into /etc/init.d that can be used to start and stop the service.

The following examples show a service being manually stopped and started using it's init script:

root@titan:/etc# /etc/init.d/syslog stop
Stopping syslogd/klogd: stopped syslogd (pid 1551).
stopped klogd (pid 1553).
root@titan:/etc# /etc/init.d/syslog start
Starting syslogd/klogd: done

The update-rc.d class takes care of the following automatically:

  1. Registers the service with the system during postinst so it will be automatically started on boot;

  2. Stops the service during prerm so it will no longer be running after being removed;

  3. Unregisters the service during prerm so there will be no attempts to start the removed service during boot;

  4. Adds a build and run time dependency on the update-rc.d package which it uses to register and unregister the services.

Usage is very simple, as shown by this example from dropbear:

INITSCRIPT_NAME = "dropbear"
INITSCRIPT_PARAMS = "defaults 10"

inherit autotools update-rc.d

where the variables are:


The name of the init script, which the package will have installed into /etc/init.d


The parameters to pass to the update-rc.d call during installation. Typically this will be the work default followed by either single number or a pair of numbers representing the start/stop sequence number (both are set to the same if only one number is supplied.)

The help from update-rc.d shows show the required parameters:

root@titan:/etc# update-rc.d -h
usage: update-rc.d [-n] [-f] [-r ]  remove
       update-rc.d [-n] [-r ] [-s]  defaults [NN | sNN kNN]
       update-rc.d [-n] [-r ] [-s]  start|stop NN runlvl [runlvl] [...] .
                -n: not really
                -f: force
                -r: alternate root path (default is /)
                -s: invoke start methods if appropriate to current runlevel

The start and stop sequence numbers need to ensure that the the service is started at the appropriate time relative to other services, such as waiting for any service that it depends on before starting (networking for example). Unless the service is a system or security related service it's better to be started as late as possible.

Multiple update-rc.d packages

Defining multiple init scripts within the one recipe is also supported. Note that each init script must be in it's own package. The following example is from the quagga recipe:

# Main init script starts all deamons
# Seperate init script for watchquagga
INITSCRIPT_PACKAGES                 = "${PN} ${PN}-watchquagga"
INITSCRIPT_NAME_${PN}               = "quagga"
INITSCRIPT_PARAMS_${PN}             = "defaults 15 85"
INITSCRIPT_NAME_${PN}-watchquagga   = "watchquagga"
INITSCRIPT_PARAMS_${PN}-watchquagga = "defaults 90 10"

inherit autotools update-rc.d

The variables that need to be declared are:


The names of each package which includes an init script.


The same meaning as INITSCRIPT_NAME, but for the package x. This would be repeated for each package that includes an init script.


The same meaning as INITSCRIPT_PARAMS, but for the package x. This would be repeated for each package that includes an init script.