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
systemdregularly in production environments.
Learning Path¶
Course Progress
What You'll Learn¶
After completing this lesson, you'll be able to:
- Understand what
systemdis - 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:
Verify:
Output:
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:
Listing Unit Files¶
Display installed unit files.
List active units.
Service Status¶
Check the status of a service.
Example:
Start a Service¶
Stop a Service¶
Restart a Service¶
Reload Configuration¶
Some services support reloading configuration without restarting.
Note
Reloading applies configuration changes without stopping the service, if the service supports this operation.
Enable a Service¶
Start automatically during boot.
Disable a Service¶
Prevent automatic startup.
Check Startup Status¶
Determine whether a service starts at boot.
Example:
Check Running Status¶
Example:
Reload systemd Configuration¶
After creating or modifying a unit file:
This reloads unit definitions without rebooting the system.
View Service Logs¶
Use journalctl.
View recent logs.
Follow logs in real time.
Unit File Location¶
System unit files are commonly stored in:
or
Administrator-created or overridden unit files are typically stored in:
Example Service Unit¶
[Unit]
Description=My Web Application
[Service]
ExecStart=/opt/app/server
Restart=always
[Install]
WantedBy=multi-user.target
Common Commands¶
List units.
Check status.
Start service.
Restart service.
Enable at boot.
View logs.
Real Production Examples¶
Restart Docker.
Check SSH.
Enable Kubernetes service.
View PostgreSQL logs.
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.
Task 2¶
List running units.
Task 3¶
Check the SSH service.
Note
On Ubuntu, the service name may be ssh instead of sshd.
Task 4¶
Check whether the service is active.
Task 5¶
Check whether it starts automatically.
Task 6¶
View recent logs.
Task 7¶
Reload the systemd manager configuration.
Task 8¶
List installed 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:
Output:
Review logs.
The logs reveal a configuration error introduced during the last deployment.
After correcting the configuration:
Verify:
The service is now running and the website is accessible.
Best Practices¶
- Manage services using
systemctlrather than manually starting background processes. - Review service status before restarting.
- Check logs with
journalctlwhen troubleshooting. - Enable only required services at boot.
- Run
daemon-reloadafter modifying unit files.
Common Mistakes¶
❌ Editing a unit file without running:
✅ Use:
❌ 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¶
- What is
systemd? - Which process runs as PID 1 on most modern Linux systems?
- Which command checks the status of a service?
- How do you start a service?
Intermediate¶
- What is a systemd unit?
- What is the difference between
start,restart, andreload? - How do you enable a service at boot?
- How do you view service logs?
Architect Level¶
- Why is
systemdpreferred over older init systems? - How would you troubleshoot a service that fails during system startup?
- How would you deploy and manage a custom application as a systemd service?
Summary¶
In this lesson, you learned:
- What
systemdis - 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¶
systemdis the default init system on most modern Linux distributions.- It typically runs as PID 1.
- Use
systemctlto manage services. - Use
journalctlto 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.