Skip to Content
This project is a work in progress. If you have any questions or suggestions, feel free to contact me.

What Is systemd? (Need Revision from linkedIn series PTC)

systemd is a system and service manager for Linux operating systems. It initializes the system at boot, manages background services (daemons), and handles logging via journald.

A service in systemd is a unit of work that typically runs in the background. These are defined by .service files located in:

  • /etc/systemd/system/ — Custom or user-defined services
  • /lib/systemd/system/ — Installed by packages
  • /run/systemd/system/ — Runtime-generated services

Here’s a minimal example of a systemd service:

[Unit] Description=My Sample Web Server After=network.target [Service] ExecStart=/usr/bin/python3 -m http.server 8080 Restart=always User=www-data [Install] WantedBy=multi-user.target

Key Sections

SectionPurpose
[Unit]Metadata and dependencies
[Service]How the service starts/stops
[Install]When/where to start the service
TaskCommand
Start a servicesudo systemctl start nginx
Stop a servicesudo systemctl stop nginx
Restart a servicesudo systemctl restart nginx
Reload without restartingsudo systemctl reload nginx
Enable (auto-start at boot)sudo systemctl enable nginx
Disablesudo systemctl disable nginx
Check if runningsystemctl status nginx
View all active servicessystemctl list-units --type=service
View all installed service filessystemctl list-unit-files
Show detailssystemctl show nginx
Analyze boot time of servicessystemd-analyze blame
$ systemctl status ssh

Sample output:

● ssh.service - OpenBSD Secure Shell server Loaded: loaded (/lib/systemd/system/ssh.service; enabled) Active: active (running) since Mon 2025-07-21 10:00:00 IST; 3h 22min ago Main PID: 1234 (sshd) Tasks: 1 Memory: 2.5M
FieldMeaning
LoadedService file is recognized and configured
ActiveCurrent state (active, inactive, failed, etc.)
Main PIDThe main process ID of the running service
# Create a custom service file sudo nano /etc/systemd/system/hello.service

Content:

[Unit] Description=Hello Service [Service] ExecStart=/bin/echo "Hello, world!" [Install] WantedBy=multi-user.target

Then:

sudo systemctl daemon-reexec # Reload systemd itself (rarely needed) sudo systemctl daemon-reload # Reload unit files sudo systemctl start hello sudo systemctl enable hello systemctl status hello
  • Reload after editing services: sudo systemctl daemon-reload

  • Check logs: journalctl -u servicename

  • Debug a failing service: Add StandardOutput=journal+console to your [Service] block.

FlagDescription
--type=serviceFilter for services only
--state=failedShow failed services
--nowUsed with enable/disable to act immediately
--userFor user-level services
Last updated on