systemd, systemctl, and Linux Service Management

Understand systemd, units, and systemctl; check service status, configure startup behavior, and read a basic service unit.

On this page

systemd, systemctl, and Linux Service Management

When installing or troubleshooting a service on a Linux host, you will often see the terms systemd, systemctl, and .service. They are related, but they are not the same thing: systemd is the system and service manager, systemctl is the command-line tool used to interact with it, and a service unit describes how systemd manages a service.

Understanding these roles makes it easier to start services, configure them to start automatically at boot, and investigate why they are not running as expected.

What are systemd and units?

On Linux distributions that use systemd, after the Linux kernel completes its early initialization, it starts the first userspace process. This is usually systemd, with process ID 1 (PID 1). The kernel creates and schedules processes, while systemd manages the boot process and services in userspace.

NOTE

systemd starts service processes according to their unit configuration, typically by creating a child process and executing the specified program (fork/exec). That is a topic for another article. A child process can create its own child processes, and processes can also be started by other managers or services. In short, as PID 1, systemd is at the root of the userspace process tree and is responsible for managing system services.

The items managed by systemd are called units. A unit is a configuration that describes a resource and how it should be managed. Different unit types use different filename extensions. Common types include:

TypePurposeExample
.serviceA background service or one-off tasksshd.service
.socketActivates a service through a socketcups.socket
.mountA filesystem mount pointhome.mount
.timerSchedules a tasklogrotate.timer

This article focuses on .service units. A service usually runs a background program (a daemon), but the two are not exactly the same: a daemon is a program that runs in the background, while a service unit is the configuration systemd uses to describe and control that program. Here, sshd refers to the SSH daemon, usually provided by OpenSSH Server, which accepts remote SSH connections. Depending on the Linux distribution, its service unit may be named sshd.service or ssh.service.

Managing services with systemctl

systemctl can query or change the state of systemd units. The examples below use sshd; service names can vary by distribution or package, so you can check them with systemctl list-unit-files --type=service.

# Check the service status and recent logs
sudo systemctl status sshd

# Start or stop the service immediately
sudo systemctl start sshd
sudo systemctl stop sshd

# Restart the service, or ask it to reload its configuration (if supported)
sudo systemctl restart sshd
sudo systemctl reload sshd
Bash

status is a useful first troubleshooting step. Its output includes the current state, main process information, and a snippet of recent logs. To see more logs, use journalctl:

# Show this service's logs
sudo journalctl -u sshd

# Follow new log entries as they arrive
sudo journalctl -u sshd -f
Bash

In many cases, you can omit the .service extension. For example, systemctl status sshd is equivalent to specifying sshd.service. You can use the full name if it is ambiguous or if you want to be explicit.

Running now and starting at boot are different things

Whether a service is running now and whether it will start automatically at the next boot are separate states. start starts the service immediately; enable configures systemd to start it at boot. One does not replace the other.

# Enable automatic startup at boot
sudo systemctl enable sshd

# Enable automatic startup and start the service now
sudo systemctl enable --now sshd

# Disable automatic startup; this does not stop a service that is already running
sudo systemctl disable sshd

# Check separately whether it is running and whether it is enabled at boot
systemctl is-active sshd
systemctl is-enabled sshd
Bash

When troubleshooting, ask two separate questions: “Is it running now?” and “Is it configured to start at boot?” Checking only one of these states can miss the source of the problem.

Creating a simple custom service

To have systemd manage your own program, you can create a service unit. Units maintained by a system administrator are commonly placed in /etc/systemd/system/. For example, the following configuration tells systemd to run a hypothetical program:

# /etc/systemd/system/example-worker.service
[Unit]
Description=Example background worker
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/example-worker
Restart=on-failure

[Install]
WantedBy=multi-user.target
Ini

In this example, [Unit] provides a description and relationships to other units; [Service] defines how to run the program and what to do if it fails; and [Install] provides the target to link the service to when you run enable.

After=: Set startup order

After=network.target means that if network.target is also part of this boot transaction, this service should start after it. This setting controls ordering only; by itself, it does not pull network.target or any network service into the startup process. To express a dependency, use settings such as Wants= or Requires= as well. Even network.target does not necessarily mean that the system has an IP address or internet access, so a program that truly requires a working network should use an appropriate readiness condition.

WantedBy=: Choose the target for enable

WantedBy=multi-user.target is installation information. It tells systemctl enable to link this service into the startup relationship for multi-user.target. multi-user.target represents the system's normal multi-user operating state, commonly used by servers. When the service is enabled, systemd creates the corresponding link so that starting this target also starts the service. This differs from After=: the former says which startup target the service is attached to, while the latter only specifies ordering.

NOTE

As a quick summary, After controls ordering, Wants/Requires express dependencies, and WantedBy provides the target used by enable. Make sure ExecStart points to an existing executable, and choose the service type and restart policy based on how the program behaves.

Reload the unit and start the service

After adding or changing a unit file, systemd may not automatically reread the changes on disk. Reload the unit definitions before starting the service:

sudo systemctl daemon-reload
sudo systemctl start example-worker
sudo systemctl status example-worker
Bash

If you also want it to start at boot, run:

sudo systemctl enable example-worker
Bash

daemon-reload rereads unit configuration; it does not restart a service that is already running. If you changed the application's own configuration, whether you need reload or restart depends on what that service supports.

TIP

To recap: a unit is a configuration that describes a resource and how it should be managed; systemd is usually the first userspace process started by the Linux kernel after early initialization, with PID 1; and systemctl can query or change the state of systemd units.

A practical troubleshooting sequence

When a service is unavailable, start with these steps:

  1. Use systemctl status <service-name> to check its current state and error summary.
  2. Use journalctl -u <service-name> to inspect the service's logs in more detail.
  3. Confirm the service name, unit configuration, and ExecStart path are correct.
  4. If you just changed a unit file, run sudo systemctl daemon-reload.
  5. After the service is working again, check whether it should be enabled to start automatically at boot.

Keep the roles of these three pieces in mind: systemd manages the system and units, a service unit describes a service, and systemctl is the tool for querying and controlling them. In day-to-day work, distinguish between “start now” and “start at boot,” then use status and journalctl as a reliable starting point for managing and troubleshooting Linux services.