Skip to content

systemd — Managing Services and System Initialization in Linux

systemd is the default init system and service manager used by most modern Linux distributions. It is responsible for booting the operating system, starting and stopping services, managing system resources, tracking logs, and controlling the overall system state. Every Linux administrator, DevOps engineer, Cloud Architect, and Site Reliability Engineer (SRE) works with systemd regularly in production environments.


Learning Path

Linux Mastery → Module 6: Process Management → Lesson 9

Difficulty: Beginner → Intermediate

Reading Time: 70 Minutes

Course Progress

Course: Linux Mastery

Module: Process Management

Lesson: 9 of 10


What You'll Learn

After completing this lesson, you'll be able to:

  • Understand what systemd is
  • Learn the Linux boot sequence
  • Understand systemd units
  • Manage services
  • Enable and disable services
  • Check service status
  • View system logs
  • Apply systemd administration in production

Prerequisites

Complete:

  • Module 1 – Linux Fundamentals
  • Module 2 – Linux Command Line Essentials
  • Module 3 – Text Processing
  • Module 4 – File Management and Permissions
  • Module 5 – Users and Groups
  • Module 6 Lessons 1–8

Why Learn systemd?

Imagine a production Linux server running:

  • NGINX
  • Docker
  • Kubernetes
  • MySQL
  • SSH
  • Monitoring agents

When the server boots,

how do these services start automatically?

How do they restart after a failure?

How do administrators manage them?

The answer is systemd.


What is systemd?

systemd is:

  • The first userspace process started after the Linux kernel
  • The service manager
  • The system initialization system

On most modern Linux systems:

PID 1


systemd

Verify:

ps -p 1

Output:

PID COMMAND

1 systemd

Linux Boot Process

Power On
BIOS / UEFI
Bootloader (GRUB)
Linux Kernel
systemd (PID 1)
System Services
Login Screen / SSH

systemd starts and manages the services required for a functioning Linux system.


What Does systemd Manage?

systemd manages:

  • Services
  • Timers
  • Mount points
  • Devices
  • Network configuration
  • User sessions
  • System startup
  • Logging integration

What is a Unit?

Everything managed by systemd is represented as a unit.

Common unit types:

Unit Purpose
.service Services
.target System state / boot targets
.socket Socket activation
.mount Filesystem mounts
.timer Scheduled tasks
.path File system event monitoring

Example:

nginx.service

docker.service

sshd.service

Listing Unit Files

Display installed unit files.

systemctl list-unit-files

List active units.

systemctl list-units

Service Status

Check the status of a service.

systemctl status nginx

Example:

● nginx.service

Active: active (running)

Start a Service

sudo systemctl start nginx

Stop a Service

sudo systemctl stop nginx

Restart a Service

sudo systemctl restart nginx

Reload Configuration

Some services support reloading configuration without restarting.

sudo systemctl reload nginx

Note

Reloading applies configuration changes without stopping the service, if the service supports this operation.


Enable a Service

Start automatically during boot.

sudo systemctl enable nginx

Disable a Service

Prevent automatic startup.

sudo systemctl disable nginx

Check Startup Status

Determine whether a service starts at boot.

systemctl is-enabled nginx

Example:

enabled

Check Running Status

systemctl is-active nginx

Example:

active

Reload systemd Configuration

After creating or modifying a unit file:

sudo systemctl daemon-reload

This reloads unit definitions without rebooting the system.


View Service Logs

Use journalctl.

journalctl -u nginx

View recent logs.

journalctl -u nginx -n 20

Follow logs in real time.

journalctl -u nginx -f

Unit File Location

System unit files are commonly stored in:

/usr/lib/systemd/system/

or

/lib/systemd/system/

Administrator-created or overridden unit files are typically stored in:

/etc/systemd/system/

Example Service Unit

[Unit]
Description=My Web Application

[Service]
ExecStart=/opt/app/server

Restart=always

[Install]
WantedBy=multi-user.target

Common Commands

List units.

systemctl list-units

Check status.

systemctl status nginx

Start service.

sudo systemctl start nginx

Restart service.

sudo systemctl restart nginx

Enable at boot.

sudo systemctl enable nginx

View logs.

journalctl -u nginx

Real Production Examples

Restart Docker.

sudo systemctl restart docker

Check SSH.

systemctl status sshd

Enable Kubernetes service.

sudo systemctl enable kubelet

View PostgreSQL logs.

journalctl -u postgresql

Production Perspective

systemd is used extensively for:

  • Linux servers
  • Cloud virtual machines
  • Kubernetes nodes
  • Docker hosts
  • Database servers
  • Web servers
  • CI/CD runners
  • Monitoring agents

Nearly every production Linux system depends on systemd to manage critical services.


Hands-on Lab

Task 1

Verify PID 1.

ps -p 1

Task 2

List running units.

systemctl list-units

Task 3

Check the SSH service.

systemctl status sshd

Note

On Ubuntu, the service name may be ssh instead of sshd.


Task 4

Check whether the service is active.

systemctl is-active sshd

Task 5

Check whether it starts automatically.

systemctl is-enabled sshd

Task 6

View recent logs.

journalctl -u sshd -n 20

Task 7

Reload the systemd manager configuration.

sudo systemctl daemon-reload

Task 8

List installed unit files.

systemctl list-unit-files

Command Deep Dive

Command Purpose Production Example
systemctl status View service status Troubleshooting
systemctl start Start service Maintenance
systemctl stop Stop service Administration
systemctl restart Restart service Deployments
systemctl reload Reload configuration Configuration changes
systemctl enable Start at boot Production setup
systemctl disable Disable auto-start Hardening
journalctl View service logs Incident response

Production Troubleshooting Scenario

Scenario

Users report that the company website is unavailable.

Investigation:

systemctl status nginx

Output:

Active: failed

Review logs.

journalctl -u nginx -n 50

The logs reveal a configuration error introduced during the last deployment.

After correcting the configuration:

sudo systemctl restart nginx

Verify:

systemctl status nginx

The service is now running and the website is accessible.


Best Practices

  • Manage services using systemctl rather than manually starting background processes.
  • Review service status before restarting.
  • Check logs with journalctl when troubleshooting.
  • Enable only required services at boot.
  • Run daemon-reload after modifying unit files.

Common Mistakes

❌ Editing a unit file without running:

✅ Use:

systemctl daemon-reload

❌ Restarting services without checking logs.

✅ Avoid this mistake: restarting services without checking logs.


❌ Disabling critical services accidentally.

✅ Avoid disabling critical services accidentally; fix the configuration instead.


❌ Confusing reload with restart.

✅ A reload re-reads configuration (if supported) without stopping the service, while a restart stops and starts the service.


Interview Questions

Beginner

  1. What is systemd?
  2. Which process runs as PID 1 on most modern Linux systems?
  3. Which command checks the status of a service?
  4. How do you start a service?

Intermediate

  1. What is a systemd unit?
  2. What is the difference between start, restart, and reload?
  3. How do you enable a service at boot?
  4. How do you view service logs?

Architect Level

  1. Why is systemd preferred over older init systems?
  2. How would you troubleshoot a service that fails during system startup?
  3. How would you deploy and manage a custom application as a systemd service?

Summary

In this lesson, you learned:

  • What systemd is
  • Linux boot sequence
  • Unit files
  • Service management
  • Service startup configuration
  • System logging with journalctl
  • Production best practices

systemd is the foundation of modern Linux system management. It initializes the operating system, manages services, tracks logs, and ensures critical applications are started and monitored. Mastering systemd is essential for administering production Linux servers.


Key Takeaways

  • systemd is the default init system on most modern Linux distributions.
  • It typically runs as PID 1.
  • Use systemctl to manage services.
  • Use journalctl to inspect service logs.
  • Enable services to start automatically during boot.
  • Reload the systemd manager after modifying unit files.

What's Next?

Linux Services — Managing Background Applications

You'll explore:

  • What Linux services are
  • Service lifecycle
  • Managing background daemons
  • Common production services
  • Service troubleshooting
  • Best practices for running long-lived applications

This lesson will bring together everything you've learned about processes, signals, and systemd to help you confidently manage services in production Linux environments.