LinuxCommandLibrary

update-rc.d

Manage System V init scripts

TLDR

Install a service

$ update-rc.d [mysql] defaults
copy

Enable a service
$ update-rc.d [mysql] enable
copy

Disable a service
$ update-rc.d [mysql] disable
copy

Forcibly remove a service
$ update-rc.d -f [mysql] remove
copy

SYNOPSIS

update-rc.d [-n] [-f] name defaults|start|stop [runlevels] .| disable|enable [runlevels]

PARAMETERS

name
    The name of the init script located in /etc/init.d/.

defaults
    Creates symlinks for the init script in the default runlevels (2-5 for start, 0,1,6 for stop) using the start and stop priorities specified in the init script's LSB header.
This action is discouraged now, it's recommended to use start/stop parameters.

start .
    Creates symlinks to start the service in the specified runlevels with the given priority. The runlevels are a space-separated list. A dot (.) must be at the end of the command.

stop .
    Creates symlinks to stop the service in the specified runlevels with the given priority. The runlevels are a space-separated list. A dot (.) must be at the end of the command.

disable [runlevels]
    Disables the service in the specified runlevels by renaming the start symlinks to stop symlinks. If no runlevels are specified, it disables the service in all runlevels.

enable [runlevels]
    Enables the service in the specified runlevels by renaming the stop symlinks to start symlinks. If no runlevels are specified, it enables the service in all runlevels.

-n
    Dry-run mode. Prints what update-rc.d *would* do, without actually making any changes.

-f
    Force. Removes existing symlinks, even if update-rc.d thinks they belong to another package. Use with caution.

DESCRIPTION

The update-rc.d command is used on Debian-based Linux systems to manage System V-style init scripts. It creates, removes, and updates symbolic links in the /etc/rc?.d directories (where '?' represents a runlevel) based on information provided in the init script itself or through command-line arguments. This controls whether a service starts or stops during different system runlevels. update-rc.d automates the tedious task of manually creating or deleting symlinks, ensuring that the system starts and stops services in the correct order and runlevel, according to the dependencies declared in the init script. The typical usage involves creating symlinks for default runlevels during package installation and removing them during package removal or upgrades. It simplifies the process of managing services and their startup/shutdown behavior across different system states.

CAVEATS

Using -f can break your system if you are not careful. Misusing this command can lead to services not starting or stopping correctly. Always examine the init script to understand its dependencies and startup/shutdown behavior. The defaults option is discouraged for creating links, the start and stop options give more control.

LSB HEADERS

Init scripts are expected to conform to the Linux Standard Base (LSB) specification. This includes providing LSB headers that define the service dependencies and default start/stop runlevels. These headers are used by update-rc.d to create appropriate symlinks. When using the 'start' and 'stop' commands, these headers are not used.

RUNLEVELS

Runlevels represent different system states. Common runlevels include:
0: Halt
1: Single-user mode
2-5: Multi-user mode
6: Reboot
The symlinks created by update-rc.d determine whether a service starts or stops in each of these runlevels. The runlevel is provided as a number, separated by spaces when more than one runlevel is used.

HISTORY

update-rc.d was originally created for Debian systems to standardize the management of System V init scripts. It automates a task that was previously done manually, reducing the risk of errors and simplifying system administration. Over time, it has become a standard tool for managing services across Debian and its derivatives. With the rise of systemd, its usage is decreasing in favor of native systemd service management.

SEE ALSO

init(8), systemctl(1), chkconfig(8) (on systems that use it)

Copied to clipboard