update-rc.d
Manage System V init scripts
TLDR
Install a service
Enable a service
Disable a service
Forcibly remove a service
SYNOPSIS
update-rc.d [-n] [-f] name remove
update-rc.d [-n] name defaults [NN]
update-rc.d [-n] name {start|stop} NN runlevel [...] .
update-rc.d [-n] name {disable|enable} [S|K] [NN runlevel [...] .]
PARAMETERS
-n
Perform a dry run. Do not actually make any changes, just show what would be done.
-f
Force the removal of links, even if the script is currently configured to run.
name
The base name of the script in /etc/init.d (e.g., 'apache2', 'mysql').
remove
Removes all existing symlinks for the specified script across all runlevel directories.
defaults
Installs symlinks for the script based on the default runlevel information found in the LSB comment block within the /etc/init.d script itself. An optional NN can override the default priority.
start NN runlevel [...] .
Adds 'S' (Start) symlinks with priority NN for the specified runlevel(s). The dot ('.') is a mandatory terminator.
stop NN runlevel [...] .
Adds 'K' (Kill) symlinks with priority NN for the specified runlevel(s). The dot ('.') is a mandatory terminator.
disable
Disables the script by converting existing 'S' (Start) symlinks to 'K' (Kill) symlinks, effectively preventing it from starting automatically. Optional NN and runlevel arguments can be used to target specific links.
enable
Enables the script by converting existing 'K' (Kill) symlinks to 'S' (Start) symlinks, allowing it to start automatically. Optional NN and runlevel arguments can be used to target specific links.
NN
A two-digit decimal number (00-99) representing the priority. Lower numbers execute earlier.
runlevel
A single character representing a runlevel (e.g., 'S' for boot, '0' for halt, '1' for single-user, '2'-'5' for multi-user, '6' for reboot).
.
A mandatory terminator for the start and stop actions, indicating the end of the runlevel list.
DESCRIPTION
update-rc.d is a command-line utility used on Debian-based Linux systems to manage the symlinks in the /etc/rc*.d/ directories. These directories represent different runlevels (e.g., single-user, multi-user, halt, reboot).
When a system boots or changes runlevels, scripts linked from /etc/init.d/ into these rc*.d directories are executed. Symlinks starting with 'S' (Start) are run at boot or runlevel entry, while those starting with 'K' (Kill) are run at shutdown or runlevel exit.
update-rc.d automates the creation and removal of these symbolic links, ensuring that services start and stop correctly across different runlevels according to their configuration, often derived from LSB (Linux Standard Base) headers within the /etc/init.d script itself. It simplifies the administrative task of enabling, disabling, or reconfiguring system services.
CAVEATS
update-rc.d is primarily used on Debian-based distributions (like Ubuntu). Red Hat/CentOS systems traditionally use chkconfig, and modern Linux distributions extensively use systemd and its systemctl command for service management. While update-rc.d might still function, systemctl is the preferred method for managing services on systemd-enabled systems.
The 'defaults' action heavily relies on correct LSB headers in the /etc/init.d script. Missing or incorrect headers can lead to unexpected behavior. Using the 'remove' action carelessly can disable critical system services, potentially leading to boot issues.
LSB HEADERS
For the 'defaults' action, update-rc.d parses special comment blocks (e.g., '### BEGIN INIT INFO' and '### END INIT INFO') at the top of /etc/init.d scripts. These blocks contain metadata like 'Required-Start', 'Required-Stop', 'Default-Start', 'Default-Stop', and 'X-Priority', which dictate how the service should behave across different runlevels and its dependencies on other services.
RUNLEVELS
In the System V init system, a runlevel defines the state of the operating system. Common runlevels include:
0: Halt (system shutdown)
1 (or S, s): Single-user mode (maintenance)
2-5: Multi-user modes (different configurations, e.g., GUI or non-GUI)
6: Reboot
update-rc.d helps manage which services start or stop when the system transitions between these runlevels.
HISTORY
update-rc.d emerged as a way to standardize and simplify the management of System V init scripts on Debian. Prior to such tools, administrators had to manually create and manage symlinks in the /etc/rcN.d directories. It abstracts away the complexity of determining correct link names (SNNservice, KNNservice) and priorities based on service dependencies. While its direct usage has diminished with the rise of systemd, it remains a fundamental component of the Debian init system and is still used internally or for managing legacy SysV init scripts.


