update-rc.d

2025-01-06

Understanding Runlevels and System Initialization

Before diving into update-rc.d, it’s important to grasp the concept of runlevels. Runlevels represent different operating states of a Linux system. Each runlevel corresponds to a specific set of services that are started or stopped. Common runlevels include:

update-rc.d manipulates the system’s initialization scripts to ensure services start and stop correctly within the specified runlevels.

Basic Syntax of update-rc.d

The basic syntax for update-rc.d is as follows:

update-rc.d <service_name> <defaults>

Where:

Let’s look at some examples.

Practical Examples of update-rc.d

Example 1: Enabling a Service at Runlevel 3

Let’s say you have a service named myservice located in /etc/init.d/myservice. To ensure this service starts at runlevel 3 (full multi-user mode) with a start priority of 20 and a stop priority of 80:

sudo update-rc.d myservice defaults 20 80

This command adds the necessary entries to the runlevel initialization scripts to start myservice at runlevel 3 and higher.

Example 2: Disabling a Service at Specific Runlevels

To disable myservice at runlevel 2 (multi-user mode without NFS):

sudo update-rc.d myservice remove 2

This removes the startup entries for myservice from runlevel 2, preventing it from starting in that mode.

Example 3: Changing the Priority of a Service

Suppose you want to increase the startup priority of myservice at all default runlevels:

sudo update-rc.d myservice defaults 10 90

This will adjust the start and stop priorities (note these are arbitrarily chosen priorities—adjust them based on your specific needs and service dependencies).

Example 4: Removing Service from all Runlevels

To entirely remove myservice from all runlevel configurations:

sudo update-rc.d myservice remove

This command removes all entries related to myservice from the runlevel configurations, preventing it from starting automatically during boot in any runlevel.

Important Note: Remember to replace <service_name> with the actual name of your service. Always use sudo to execute these commands as they require root privileges. Furthermore, remember that update-rc.d is largely deprecated in favor of systemd. Modern Linux distributions primarily use systemd for service management. This command is more relevant for older systems or maintaining backward compatibility.