The systemd is backward compatible with SysV init. If the system has /etc/inittab file, it uses SysV init.
The SystemV init (SysV init) is using runlevels to define the state of servers should be booting in. These runlevels identify which services are loaded at which runlevel. For example, at runlevel 1 (rescue mode) only essential services are loaded for administration, at runlevel 3, essential services with networking services are loaded, at runlevel 5, graphical environment is loaded. However, some distributions use different runlevels for different services.
Red-Hat-based SysV init runlevels
|Runlevel||Red Hat-based distribution runlevels||Debian-based distribution runlevels|
|0||Shut down the system||Shut down the system|
|1, s, or S||Single-user mode (maintenance)||Single-user mode (maintenance)|
|2||Multi-user mode without networking services enabled||Multi-user mode with GUI|
|3||Multi-user mode with networking services enabled||N/A|
|5||Multi-user mode with GUI||N/A|
|6||Reboot the system||Reboot the system|
To see current runlevel on the system:
# runlevel N 5
Instead using default target (default.target) like systemd, SysV init uses configuration file – /etc/inittab. Let’s see what it holds:
# grep :initdefault: /etc/inittab id:5:initdefault:
The “initdefault” keyword specifies the runlevel to enter after the system boots.
- Each script must have initialization script located in /etc/init.d/ directory.
- Each of these scripts contains shell code responsible for starting, stopping, restarting, reloading a service.
- Now, program that starts these scripts is called rc script and it lives in /etc/init.d/ or in /etc/rc.d/ directory.
- The rc script, runs all scripts within one of these directories. T
- he directory used depends on the runlevel.
- Each runlevel has its own subdirectory in /etc/rc.d/ like rc0.d, rc1.d, rc2.d…
- Inside each of these are service scripts that start with K or S in their name. K stands for kill, S stands for start.
- The number indicates order in which script will be run.
- All scripts in /etc/rc.d/rcX.d/ are symbolic links to scripts in /etc/init.d/ directory.
Managing SysV services
To view a SysV init service’s status and control its behaviour use service utility.
service SCRIPT COMMAND [OPTIONS]
the SCRIPT here refers to a particular script in /etc/init.d/ directory. The service scripts typically have names same as the service. The COMMAND are explained in table below.
|restart||Stop and restart specified service|
|start||Start specified service|
|status||Show service status|
|–status-all||Show all services’ status|
|stop||Stop the specified service|
|reload||Load the service configuration file. It makes service changes without stopping it.|