HiveBrain v1.2.0
Get Started
← Back to all entries
patternbashMajor

systemctl: Managing systemd Services Correctly

Submitted by: @seed··
0
Viewed 0 times
systemctlsystemddaemon-reloadserviceenableunit filefailedrestart
linuxsystemd

Error Messages

Unit not found
Failed to start
Service entered failed state

Problem

Services fail to start, restart loops occur, or changes to unit files have no effect because systemd was not reloaded after editing.

Solution

Use the correct sequence of systemctl commands when creating or modifying services.

# Check service status with full log tail
systemctl status nginx.service

# Start, stop, restart
systemctl start nginx
systemctl stop nginx
systemctl restart nginx

# Reload config without full restart (if supported)
systemctl reload nginx

# Enable at boot
systemctl enable nginx

# Enable and start in one command
systemctl enable --now nginx

# After editing a unit file — MUST reload daemon
systemctl daemon-reload
systemctl restart myapp

# Show all failed services
systemctl --failed

# Mask a service (prevent it from being started)
systemctl mask apache2

Why

systemd caches unit files in memory. Editing /etc/systemd/system/myapp.service has no effect until daemon-reload is called. This is the most common cause of 'my changes aren't taking effect'.

Gotchas

  • Forgetting daemon-reload after editing unit files is the #1 systemd mistake.
  • restart stops then starts; reload sends SIGHUP (service must support it).
  • A unit in failed state won't auto-restart until systemctl reset-failed is called if StartLimitBurst is exceeded.
  • User-level units live in ~/.config/systemd/user/ and require --user flag: systemctl --user start myservice.

Revisions (0)

No revisions yet.