0Pricing
Linux Command Line & Bash Scripting Mastery · Lesson

Controlling systemd Services and Writing Unit Files

Drive services with systemctl and author custom unit and timer files for scripted daemons.

Introduction to systemd and systemctl

systemd is the init system and service manager used by most modern Linux distributions. It is responsible for starting, stopping, and managing system services, as well as handling boot sequences and system state.

The primary tool for interacting with systemd is systemctl. With it you can:

  • Start and stop services
  • Enable or disable services at boot
  • Inspect service status and logs
  • Reload configuration without restarting

All services managed by systemd are defined by unit files, which are declarative configuration files stored under /etc/systemd/system/ (system-wide) or ~/.config/systemd/user/ (per-user).

Essential systemctl Commands

These are the most commonly used systemctl commands for day-to-day service management. Each command operates on a unit name such as nginx.service or simply nginx.

  • systemctl start <unit> — start a service immediately
  • systemctl stop <unit> — stop a running service
  • systemctl restart <unit> — stop then start (full restart)
  • systemctl reload <unit> — send SIGHUP to reload config without stopping
  • systemctl enable <unit> — create symlinks so the unit starts at boot
  • systemctl disable <unit> — remove those symlinks
  • systemctl status <unit> — show state, PID, recent log lines
#!/usr/bin/env bash
# Quick reference: inspect and control an nginx service
# (Requires nginx to be installed; run as root or with sudo)

systemctl status nginx
systemctl start nginx
systemctl enable nginx
systemctl reload nginx
systemctl restart nginx
systemctl stop nginx
systemctl disable nginx

All lessons in this course

  1. Automating User and Group Provisioning
  2. Controlling systemd Services and Writing Unit Files
  3. Disk, Filesystem, and Mount Automation
  4. Building System Health Check and Alert Scripts
← Back to Linux Command Line & Bash Scripting Mastery