2024-01-30
Before exploring rc-update, understand Linux runlevels. A runlevel represents a system’s operational state. Common runlevels include:
rc-update manipulates which services start and stop at specific runlevels.
Let’s say you have a script located at /etc/init.d/myservice that manages a custom service. To enable this service to start at runlevels 2, 3, 4, and 5, you would use the following command:
sudo rc-update add myservice defaultThis command adds myservice to the default runlevel, which typically encompasses runlevels 2, 3, 4, and 5. If you want more granular control, you can specify individual runlevels:
sudo rc-update add myservice 2
sudo rc-update add myservice 3
sudo rc-update add myservice 4
sudo rc-update add myservice 5This achieves the same result, but allows for independent control of each runlevel. You can verify the changes by examining the relevant files within the /etc/rc.d/rc*.d directories. These directories contain symbolic links reflecting the services and their start/stop order.
To remove myservice from runlevel 3, you would use:
sudo rc-update del myservice 3Similarly, removing from the default runlevel:
sudo rc-update del myservice defaultTo see which services are linked to a specific runlevel (e.g., 3):
sudo rc-update show 3This command lists all services associated with runlevel 3. To view all services associated with all runlevels:
sudo rc-update showThis provides an overview of service runlevel associations.
Complex services often depend on other services. rc-update doesn’t directly manage dependencies; these are typically handled within the service scripts themselves (often using chkconfig or similar tools alongside rc-update in older systems, or systemctl in systemd-based systems). Ensure your service scripts correctly handle dependencies to avoid boot failures.
The rc-update command is traditionally associated with SysVinit based systems. Modern distributions often employ systemd as their init system. Systemd uses systemctl for managing services and has a different approach to runlevels and service control. If you’re using systemd, rc-update might not be available or functional as expected. Consult your distribution’s documentation for service management using systemctl.