Skip to main content
In this article, you’ll learn how to manage Linux startup processes and services effectively. We will discuss how systemd—the init system—handles the startup sequence, restarts failed applications, and orchestrates service dependencies. When Linux boots, several critical applications launch automatically in a defined order. For instance, if “app2” depends on “app1”, then app1 starts before app2. This ordered process happens seamlessly behind the scenes. Furthermore, if a vital application crashes, systemd automatically restarts it to maintain system reliability.

Understanding the Init System and Service Units

The core mechanism responsible for this operation is the init system (short for initialization system). It reads configuration files called “units” that provide detailed instructions on how to:
  • Start the system and individual services.
  • Handle unexpected crashes.
  • Reload configurations or restart services.
Service units—files ending with a .service extension—specifically define how to manage applications. A typical service unit describes: • The command to launch an application. • The behavior when a program crashes. • Commands to reload configurations or restart the service. To explore all available options for a service unit, run:
This command opens the manual page that explains the configuration options for service units:

Example: Managing the SSH Daemon

For many servers, the SSH daemon is essential for remote connectivity. The SSH service unit guides systemd on how to start and maintain the daemon. To inspect this service file, use the command:
You might see output similar to this:
In this configuration:
  • The ExecStart directive tells systemd which command to execute to start the SSH daemon.
  • ExecReload specifies how to reload the daemon’s configuration.
To edit this service file completely, use:
If you need to revert your changes and return to the default settings, run:
To check the service status, including its PID, enabled state, and recent log messages, execute:
A typical status output might look like:
An enabled service will start automatically during system boot. Always check recent log messages to diagnose startup issues.

Controlling Service States

Managing service states with systemd involves starting, stopping, restarting, and reloading services. The following table summarizes common commands and their use cases:

Restart vs. Reload

  • Restart: Stops and then starts the service, which may interrupt current connections.
  • Reload: Applies configuration changes without disrupting active connections (if supported).
After any action, you should verify the status:
If the configuration reload is successful, the logs may show entries such as:
Not all applications support a graceful reload. If a reload is not possible, systemd may perform a full restart.

Enabling and Disabling Services

To control whether a service starts automatically at boot, use the following commands:
  • Disable a Service: Prevents a service from launching on boot.
  • Check Service Status: Verify if the service is enabled.
  • Enable a Service: Ensures the service starts during boot.
When installing a new server application, you often want to enable and start it simultaneously:
Or combine them into one step:
To disable plus stop a service at the same time:
Be cautious when disabling critical services such as the SSH daemon; doing so can lock you out of your system.

Masking Services

Even after disabling a service, other components may inadvertently start it. Masking a service creates a symbolic link to /dev/null, ensuring the service can neither be started nor enabled. To mask a service like atd (which schedules tasks), execute:
Any attempt to start or enable the masked service will result in an error, as shown below:
To restore normal operations, simply unmask the service:

Listing All Service Units

Service unit names can sometimes be confusing. For example, the Apache web server might be listed as “httpd.service” instead of “apache.service.” To list all service units, regardless of their state, run:
This command provides details like:

Conclusion

In this article, we covered how Linux manages startup processes and services using systemd. We explored service units and learned how to inspect, start, stop, reload, enable, disable, and mask services. With these tools and commands, you can manage critical applications effectively, ensuring your system remains stable. Now it’s time to put these concepts into practice in a lab environment to solidify your understanding.

Watch Video

Practice Lab