Lesson 08 — Linux Services & Systemd
Lesson 08 — Linux Services & Systemd
Section titled “Lesson 08 — Linux Services & Systemd”Lesson Overview
Section titled “Lesson Overview”Imagine you’ve deployed an Ubuntu server in AWS to host a company website.
The web server must:
- Start automatically after every reboot.
- Continue running even if no user is logged in.
- Restart if it crashes.
- Be monitored by the operating system.
Linux accomplishes this using Services managed by systemd.
Services run quietly in the background and power almost every part of a Linux system—from networking and SSH to databases, web servers, Docker, and Kubernetes.
Whether you’re a Linux Administrator, Cloud Engineer, DevOps Engineer, or Cybersecurity Professional, understanding Linux services is essential because nearly every enterprise application depends on them.
Learning Objectives
Section titled “Learning Objectives”After completing this lesson, you will be able to:
- Explain what Linux services are.
- Understand systemd and systemctl.
- Manage services.
- Configure services to start automatically.
- Understand service units and targets.
- Troubleshoot failed services.
- Apply enterprise service management best practices.
What is a Linux Service?
Section titled “What is a Linux Service?”A Linux Service is a background process that performs a specific function without requiring user interaction.
Examples include:
- SSH Server
- NGINX
- Apache
- Docker
- MySQL
- PostgreSQL
- Cron
- Network Manager
Services continue running even after users log out.
Why Services Matter
Section titled “Why Services Matter”Without services:
- Websites would stop.
- Databases would become unavailable.
- SSH access would fail.
- Containers would stop.
- Enterprise applications would become inaccessible.
Services keep Linux systems available and reliable.
What is systemd?
Section titled “What is systemd?”systemd is the default service manager used by most modern Linux distributions.
It is responsible for:
- Starting the operating system.
- Managing services.
- Tracking running processes.
- Handling system startup.
- Managing dependencies.
- Recording service logs.
The first process started during boot is:
systemd
PID 1What is systemctl?
Section titled “What is systemctl?”systemctl is the command-line tool used to manage services controlled by systemd.
Using systemctl, administrators can:
- Start services
- Stop services
- Restart services
- Enable services
- Disable services
- Check service status
Viewing Service Status
Section titled “Viewing Service Status”Check whether a service is running.
systemctl status sshExample output:
Active: active (running)This command displays:
- Service state
- Process ID
- Startup time
- Recent log entries
Starting a Service
Section titled “Starting a Service”Start a stopped service.
sudo systemctl start nginxThe service begins running immediately.
Stopping a Service
Section titled “Stopping a Service”Stop a running service.
sudo systemctl stop nginxThis gracefully shuts down the service.
Restarting a Service
Section titled “Restarting a Service”Restart a service after configuration changes.
sudo systemctl restart nginxRestarting applies new settings without rebooting the server.
Reloading a Service
Section titled “Reloading a Service”Some services can reload configuration without restarting.
sudo systemctl reload nginxThis minimizes downtime.
Enabling a Service
Section titled “Enabling a Service”Enable automatic startup during boot.
sudo systemctl enable nginxNow the service starts every time Linux boots.
Disabling a Service
Section titled “Disabling a Service”Prevent automatic startup.
sudo systemctl disable nginxThe service remains installed but no longer starts automatically.
Checking if a Service is Enabled
Section titled “Checking if a Service is Enabled”Verify startup configuration.
systemctl is-enabled nginxExample:
enabledor
disabledListing Running Services
Section titled “Listing Running Services”Display active services.
systemctl list-units --type=serviceThis shows all running services managed by systemd.
Listing Failed Services
Section titled “Listing Failed Services”Identify services that failed to start.
systemctl --failedThis is useful during troubleshooting.
Service Unit Files
Section titled “Service Unit Files”Every service has a unit file.
Typical location:
/etc/systemd/system/
/usr/lib/systemd/system/Example:
nginx.serviceA unit file defines:
- Service name
- Startup command
- Dependencies
- Restart behavior
Understanding Unit Types
Section titled “Understanding Unit Types”systemd manages different unit types.
| Unit | Purpose |
|---|---|
| .service | Background services |
| .target | Boot targets |
| .socket | Socket activation |
| .mount | Mounted file systems |
| .timer | Scheduled tasks |
| .device | Hardware devices |
The most common unit is the .service file.
Targets
Section titled “Targets”Targets define system startup states.
Examples:
| Target | Purpose |
|---|---|
| multi-user.target | Multi-user server mode |
| graphical.target | Desktop environment |
| rescue.target | Recovery mode |
| emergency.target | Emergency maintenance |
Targets replace the older Linux runlevel system.
Viewing Boot Time
Section titled “Viewing Boot Time”Display system startup performance.
systemd-analyzeExample:
Startup finished in
4.5 secondsThis helps administrators identify slow boot processes.
Viewing Service Logs
Section titled “Viewing Service Logs”systemd integrates with journalctl.
View logs for a service.
journalctl -u nginxView recent logs.
journalctl -xeLogs are essential for troubleshooting production systems.
Service Dependencies
Section titled “Service Dependencies”Many services depend on other services.
Example:
Application
↓
Database
↓
Network
↓
Storagesystemd automatically starts services in the correct order.
Services in Cloud Computing
Section titled “Services in Cloud Computing”Cloud Engineers commonly manage services such as:
- SSH
- Docker
- Kubernetes Kubelet
- NGINX
- Apache
- MySQL
- PostgreSQL
- Cloud Monitoring Agents
Managing services is a daily task in cloud environments.
Services in DevOps
Section titled “Services in DevOps”DevOps Engineers frequently:
- Deploy services
- Restart applications
- Monitor services
- Configure automatic startup
- Troubleshoot failed deployments
Automation tools like Ansible often use systemd to manage services.
Services in Cybersecurity
Section titled “Services in Cybersecurity”Security teams investigate:
- Unexpected services
- Disabled security services
- Malware running as services
- Unauthorized startup services
- Failed authentication services
Monitoring services helps detect security incidents.
Common Commands
Section titled “Common Commands”Check service status:
systemctl status service-nameStart service:
systemctl start service-nameStop service:
systemctl stop service-nameRestart service:
systemctl restart service-nameReload configuration:
systemctl reload service-nameEnable at boot:
systemctl enable service-nameDisable at boot:
systemctl disable service-nameView logs:
journalctl -u service-nameReal-World Example
Section titled “Real-World Example”A company deploys an internal web application.
Ubuntu Server
↓
systemd
↓
NGINX Service
↓
Application Service
↓
MySQL Service
↓
Users Access WebsiteIf the server reboots, systemd automatically starts all required services in the correct sequence, ensuring the application becomes available without manual intervention.
Best Practices
Section titled “Best Practices”As a Linux administrator:
- Enable only required services.
- Disable unused services.
- Monitor service health regularly.
- Restart services after configuration changes.
- Review logs before troubleshooting.
- Keep service configurations documented.
- Use descriptive custom service names.
- Test startup behavior after system updates.
Proper service management improves system reliability, security, and availability.
Key Takeaways
Section titled “Key Takeaways”After completing this lesson, you should understand:
- What Linux services are.
- The role of systemd.
- How to use systemctl.
- Service unit files.
- Startup targets.
- Viewing service logs.
- Enterprise service management best practices.
Summary
Section titled “Summary”Linux services are the foundation of every modern Linux server.
From SSH and web servers to databases, containers, and monitoring agents, nearly every enterprise application runs as a managed service.
By mastering systemd and systemctl, you’ll be able to deploy, manage, monitor, and troubleshoot Linux servers confidently in cloud, DevOps, and enterprise environments.
These skills are used daily by Linux Administrators, Cloud Engineers, DevOps Engineers, Site Reliability Engineers (SREs), and Cybersecurity Professionals.
Next Lesson
Section titled “Next Lesson”➡️ Lesson 09 — Linux Networking
In the next lesson, you’ll learn how Linux communicates over networks, configure IP addresses, troubleshoot connectivity, understand network interfaces, DNS configuration, routing, and use essential networking commands like ip, ping, ss, netstat, traceroute, and curl.