DevOpsLesson
DevOpsLesson

Free, comprehensive DevOps tutorials and learning roadmaps. Master Docker, Kubernetes, CI/CD, and more.

Stay Updated

Get notified about new tutorials and features.

Tutorials

  • What is DevOps?
  • Docker Tutorial
  • Terraform Tutorial
  • CI/CD Pipeline
  • All Tutorials

Roadmaps

  • DevOps Engineer
  • Cloud Engineer
  • SRE Path
  • All Roadmaps

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 DevOpsLesson. All rights reserved.

DOCKERKUBERNETESTERRAFORMAWSCI/CDLINUXGITDEVOPS ROADMAPCLOUD ROADMAPSRE ROADMAPGIT CHEATSHEETDOCKER CHEATSHEETK8S CHEATSHEETTF CHEATSHEETLINUX CHEATSHEETDOCKERFILE LINTERYAML VALIDATORCRON PARSERREGEX TESTER

Linux Tutorial

Introduction to Linux
Linux Filesystem
Linux Navigation
Linux File Operations
Linux Text Processing
Linux Permissions
Linux Users and Groups
Linux Process Management
Linux systemd Basics
Linux Networking
Linux Disk and Storage
Linux Bash Scripting
Linux Package Management
Linux Environment Variables
Linux Cron Jobs
Linux SSH Keys
Linux Firewall Basics
Linux Log Management
Linux Performance Monitoring and Troubleshooting

Linux systemd Basics

PreviousPrev
Next

Learn how systemd units, targets, systemctl, and journalctl work, and create a simple service unit file.

What Is systemd?

systemd is the init system and service manager used by many modern Linux distributions. It is responsible for booting the system, starting services, tracking their state, and managing logs and dependencies.

If you run a server with Nginx, Docker, SSH, or a custom app, systemd often controls whether that service starts at boot and how it behaves.

Understanding Units and Targets

systemd manages objects called units. A unit describes something systemd knows how to manage.

Common unit types include:

  • .service for services
  • .socket for socket activation
  • .mount for mount points
  • .timer for scheduled tasks
  • .target for grouped system states

A target is roughly like a collection of units that represents a system state, such as multi-user mode.

Managing Services with systemctl

systemctl is the main command for working with systemd.

Start a service:

sudo systemctl start nginx

Stop a service:

sudo systemctl stop nginx

Restart a service:

sudo systemctl restart nginx

Check status:

systemctl status nginx

This shows whether the service is active, recent log lines, and the main process ID.

Enabling and Disabling at Boot

A service can be running now without being configured to start at boot.

Enable at boot:

sudo systemctl enable nginx

Disable at boot:

sudo systemctl disable nginx

A common beginner mistake is assuming start and enable mean the same thing. They do not.

  • start affects the current session
  • enable affects future boots

Tip: Many deployment issues happen because a service was started manually but never enabled.

Reading Logs with journalctl

systemd integrates with the system journal, which you can query using journalctl.

Show recent logs:

journalctl

Follow logs in real time:

journalctl -f

View logs for a specific unit:

journalctl -u nginx
journalctl -u sshd -f

Filter by time:

journalctl --since "2026-07-14 09:00:00"
journalctl -u nginx --since "1 hour ago"

This is incredibly useful for diagnosing why a service failed to start.

Writing a Simple Unit File

You can manage your own applications with systemd by creating a unit file.

Example:

[Unit]
Description=Demo Application Service
After=network.target

[Service]
Type=simple
WorkingDirectory=/opt/demo-app
ExecStart=/usr/bin/python3 /opt/demo-app/app.py
Restart=on-failure
User=demo
Group=demo

[Install]
WantedBy=multi-user.target

Save it as:

/etc/systemd/system/demo-app.service

Then reload systemd and start the service:

sudo systemctl daemon-reload
sudo systemctl start demo-app
sudo systemctl enable demo-app

Understanding Key Unit Sections

[Unit]

This section describes metadata and dependencies.

[Service]

This section defines how the service starts, under which user, in which directory, and what should happen if it fails.

[Install]

This section describes how the unit is tied into targets when enabled.

Practical Troubleshooting Flow

Suppose your service will not start after deployment.

A useful workflow is:

systemctl status demo-app
journalctl -u demo-app --since "10 minutes ago"

Typical causes include:

  • wrong ExecStart path
  • missing working directory
  • permission problems
  • missing environment variables
  • app crashes during startup

systemd gives you a repeatable place to inspect that behavior.

Test Your Understanding

Let's see how well you understood the concepts! These exercises will help reinforce what you just learned.

Exercise 1: Start versus enable

Question: What is the difference between systemctl start nginx and systemctl enable nginx?

Exercise

Exercise 1: Start versus enable

Identify which action affects the current runtime and which affects future boots.

Exercise 2: Filtering the journal

Scenario: A custom app service fails after deployment, and you want only its journal entries from the last 10 minutes.

Question: Which command from the lesson is the best match?

Exercise

Exercise 2: Filtering the journal

Choose the journalctl command that narrows logs to one unit and a recent time window.

Exercise 3: Making systemd notice changes

Question: Why do you run systemctl daemon-reload after creating or editing a unit file in /etc/systemd/system?

Exercise

Exercise 3: Making systemd notice changes

Pick the reason daemon-reload is necessary after unit file changes.

PreviousPrev
Next

Continue Learning

Linux Permissions

Understand Linux ownership, rwx permissions, octal notation, chmod, chown, special bits, and umask.

18 min·Medium

Linux Users and Groups

Learn how Linux accounts and groups work, and how to manage users, passwords, sudo access, and account files.

15 min·Medium

Linux Process Management

Learn how to inspect, prioritize, background, and control processes in Linux using ps, top, kill, jobs, nohup, and related tools.

20 min·Medium

Explore Related Topics

Do

Docker Tutorials

Run and manage containers on Linux

Gi

Git Tutorials

Master Git version control on the command line

Try the Tool

Cron Parser

Parse and validate cron expressions with a visual schedule preview.

Regex Tester

Test and debug regular expressions used in Bash scripts and configs.

On This Page

What Is systemd?Understanding Units and TargetsManaging Services with `systemctl`Enabling and Disabling at BootReading Logs with `journalctl`Writing a Simple Unit FileUnderstanding Key Unit Sections`[Unit]``[Service]``[Install]`Practical Troubleshooting FlowTest Your UnderstandingExercise 1: Start versus enableExercise 2: Filtering the journalExercise 3: Making systemd notice changes