
The Role of the Init System and Systemd Units
The startup and management of services in Linux are controlled by the init system. This system uses configuration files called systemd units to determine how applications should be started, what actions to take when an application fails, and other necessary operations. The term systemd refers both to the suite of tools that manage Linux systems and the primary program that acts as the init system.Example: Managing the SSH Daemon
Many Linux servers run an SSH daemon to enable remote connections. Systemd manages this daemon using a specific service unit. You can display the SSH service unit file by executing:- ExecStart specifies the command used to launch the SSH daemon.
- ExecReload defines the commands to reload the SSH configuration.
- Restart=on-failure ensures that systemd automatically restarts the service if it crashes.
Checking Service Status
To verify the status of the SSH service, run:Starting, Stopping, Restarting, and Reloading Services
You can manually manage services using various systemctl commands:-
Stop a service:
-
Start a service:
-
Restart a service:
This command stops and then starts the service to apply new configurations. -
Reload a service:
This command reloads the service’s configuration without interrupting active sessions, which is particularly useful when users are connected.
/etc/ssh/sshd_config, you can enforce the new settings with either of the following commands:
Not all applications support configuration reloads. When in doubt, systemd will first attempt a graceful reload and then perform a full restart if necessary.
Enabling and Disabling Services
To prevent a service from starting automatically at boot, use the disable command:Be cautious when disabling critical services such as SSH, particularly on remote systems.
Masking Services
Some services might restart automatically even after being stopped or disabled because other services trigger them. In such cases, you can mask the service to completely prevent it from starting. For example, to prevent the at daemon from being activated:Listing Service Units
Sometimes the service name for an installed application may not be obvious (for instance, Apache might be listed as apache.service or httpd.service depending on your distribution). To display all service units regardless of their state, use:
In addition to service units, systemd also manages other types of units such as sockets and timers.
In summary, this article demonstrated how systemd manages Linux services through service units—from starting and stopping to restarting and reloading configurations. Mastering these commands is essential for efficient system management and ensuring continuous system reliability.