🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now β†’
Menu

Categories

systemd Service Management: Complete Linux Guide (2026)

systemd Service Management: Complete Linux Guide (2026)

Quick Summary: systemd is the init system and service manager used by virtually all modern Linux distributions. It manages the entire boot process, system services, logging, and more. The primary command for interacting with systemd is systemctl, which starts, stops, enables, and monitors services. This guide covers everything from basic service management to creating custom unit files.

systemd service management on Linux

What Is systemd?

systemd is the first process (PID 1) that starts when your Linux system boots. It replaces the older SysVinit and Upstart init systems. systemd manages service startup order, handles dependencies between services, monitors running services, and provides centralized logging through journald.

Essential systemctl Commands

CommandPurpose
systemctl start nginxStart a service immediately
systemctl stop nginxStop a running service
systemctl restart nginxStop then start (brief downtime)
systemctl reload nginxReload config without stopping
systemctl enable nginxStart automatically on boot
systemctl disable nginxDo not start on boot
systemctl enable --now nginxEnable AND start immediately
systemctl status nginxShow service status and recent logs
systemctl is-active nginxCheck if running (for scripts)
systemctl is-enabled nginxCheck if enabled on boot
systemctl list-units --type=serviceList all loaded services
systemctl list-units --failedList failed services

Understanding Unit Files

Every service managed by systemd has a unit file that defines how it behaves. Unit files are typically stored in /etc/systemd/system/ (custom) or /usr/lib/systemd/system/ (package-installed).

Unit File Structure

SectionPurposeKey Directives
[Unit]Metadata and dependenciesDescription, After, Requires, Wants
[Service]How the service runsExecStart, Type, Restart, User
[Install]When to start the serviceWantedBy (usually multi-user.target)

Creating a Custom Service

  1. Create the unit file at /etc/systemd/system/myapp.service
  2. Define the [Unit] section with Description and After directives
  3. Define the [Service] section with Type, User, WorkingDirectory, ExecStart, and Restart
  4. Define the [Install] section with WantedBy=multi-user.target
  5. Reload systemd: sudo systemctl daemon-reload
  6. Enable and start: sudo systemctl enable --now myapp

Service Types

TypeBehaviorUse Case
simpleExecStart process IS the serviceMost applications (default)
forkingProcess forks and parent exitsTraditional daemons (Apache)
oneshotRuns once then exitsSetup scripts, cleanup tasks
notifyService signals readinessApplications using sd_notify
idleRuns after other jobs finishLow-priority background tasks

Restart Policies

DirectiveBehavior
Restart=alwaysAlways restart when the process exits
Restart=on-failureRestart only on non-zero exit codes
Restart=on-abnormalRestart on signals, timeouts, watchdog
RestartSec=5Wait 5 seconds before restart
StartLimitIntervalSec=300Rate limit: max restarts per interval
StartLimitBurst=5Maximum 5 restarts per interval

Logging with journald

  • journalctl -u nginx β€” View logs for a specific service
  • journalctl -u nginx --since "1 hour ago" β€” Time-filtered logs
  • journalctl -u nginx -f β€” Follow logs in real time
  • journalctl -p err β€” Show only error messages
  • journalctl --disk-usage β€” Check journal disk usage
  • journalctl --vacuum-size=500M β€” Limit journal to 500MB

Dependencies and Ordering

DirectiveMeaning
After=network.targetStart after network is up
Requires=postgresql.serviceHard dependency: fails if PostgreSQL fails
Wants=redis.serviceSoft dependency: starts Redis but continues if it fails
Before=nginx.serviceStart before NGINX

Frequently Asked Questions

What is the difference between enable and start?

systemctl start starts a service immediately but it will not survive a reboot. systemctl enable configures the service to start automatically on boot but does not start it now. Use systemctl enable --now to do both at once.

How do I find why a service failed?

Run systemctl status servicename for a quick overview, then journalctl -u servicename -n 50 for detailed logs. Look for error messages, permission denied errors, or missing files/directories.

What does daemon-reload do?

systemctl daemon-reload tells systemd to re-read all unit files from disk. You must run this after creating or modifying any unit file before the changes take effect. It does not restart any services.

How do I make a service restart automatically after crashes?

Add Restart=on-failure (or Restart=always) and RestartSec=5 to the [Service] section. This tells systemd to automatically restart the service 5 seconds after it exits with a non-zero status code.

Related Resources

Share this article:
Dargslan Editorial Team (Dargslan)
About the Author

Dargslan Editorial Team (Dargslan)

Collective of Software Developers, System Administrators, DevOps Engineers, and IT Authors

Dargslan is an independent technology publishing collective formed by experienced software developers, system administrators, and IT specialists.

The Dargslan editorial team works collaboratively to create practical, hands-on technology books focused on real-world use cases. Each publication is developed, reviewed, and...

Programming Languages Linux Administration Web Development Cybersecurity Networking

Stay Updated

Subscribe to our newsletter for the latest tutorials, tips, and exclusive offers.