Skip to main content
This article explains how to manage startup processes and services in Linux. During the boot sequence, Linux automatically launches several critical applications in a defined order. For example, if Application 2 depends on Application 1, Application 1 will load first. Additionally, if a critical application crashes, the system is configured to automatically restart it to ensure uninterrupted operation.
The image illustrates a startup process flow, showing "Boot Up" leading to "App1" and "App2," with a note that "init" stands for the initialization system.

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.
The image shows icons representing different system units: service, socket, device, and timer, with a note that "init" stands for the initialization system.
Systemd ensures smooth system operation by initializing and monitoring various system components. There are several types of systemd units such as service, socket, device, and timer units. For example, timer units can schedule tasks like weekly file cleanups or database verifications. In this guide, the focus is on service units. A service unit provides systemd with all the details required to manage an application’s lifecycle. This includes the command to start the application, what to do if it crashes, how to reload configurations, and more. To explore the various options available in a service unit file, run:

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:
The output might resemble the following:
In this file:
  • 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.
If the SSH daemon fails, systemd will restart it to maintain remote connectivity.

Checking Service Status

To verify the status of the SSH service, run:
A typical output may look like this:
The output indicates whether the service is enabled to start at boot, confirms that the process is running, and displays the process identifier (PID) along with log messages for troubleshooting.

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.
After modifying the SSH configuration file located at /etc/ssh/sshd_config, you can enforce the new settings with either of the following commands:
You can review the status again to confirm the service behavior:
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:
Verify the service’s enablement status with:
To enable the service for automatic startup at boot, run:
If you want a daemon to start immediately and at boot, you can use the —now option:
Likewise, to stop a service immediately and disable it for future boots, run:
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:
A masked service cannot be enabled or started. Any attempt to do so will generate an error:
To reverse the masking and allow the service to operate normally, run:

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:
This command lists service units in various states—active, inactive, enabled, or disabled—ensuring you have a complete overview. An example output may look like: 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.

Additional Resources

Happy managing!

Watch Video