← Home ← Codex ← DEBT
Browse by Category
+ added · updated 7d
← Back to glossary

Systemd Services & Unit Files

Linux Intermediate
debt(d7/e3/b3/t5)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7). The detection_hints note automated=no, and the code pattern requires manually inspecting whether queue workers are running in screen/tmux with no unit files, no automatic restart, and no systemd supervision. Tools listed (systemd, journalctl) only help after the fact — there is no automated check that flags the absence of a unit file. A reviewer must notice the gap during a server audit or when a worker silently stays down after a crash.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). The quick_fix is to write a systemd unit file per worker — a small, self-contained task per service. Fixing common mistakes (adding Restart=on-failure, User=, WantedBy=) are single-file edits within one component. This is slightly more than a one-liner but well within one component and doesn't span multiple files across the codebase.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3). The applies_to scope is cli and queue-worker contexts only, not the entire web application. Properly configured unit files are self-contained — once written they impose minimal ongoing maintenance tax. The burden is localised to the operations/server layer and does not shape every future development decision.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'notable trap' (t5). The misconception field identifies a documented gotcha: developers assume Supervisor is required for PHP queue workers and overlook that systemd already handles process supervision natively. Common mistakes (omitting Restart=on-failure, missing WantedBy, forgetting daemon-reload) are documented pitfalls that most developers encounter at least once, but they are learnable and don't fundamentally contradict how similar concepts work.

About DEBT scoring →

Also Known As

systemd unit file systemctl service management

TL;DR

Systemd is the init system managing service lifecycle on modern Linux — unit files define how services start, stop, restart, and depend on each other.

Explanation

A systemd service unit file (.service) defines: ExecStart (command to run), Restart policy (on-failure, always), User/Group (run as specific user), Environment (environment variables), After/Requires (dependency ordering), and WantedBy (when to start). Key commands: systemctl start/stop/restart/status servicename, systemctl enable (start on boot), journalctl -u servicename (logs). PHP applications use systemd for PHP-FPM, queue workers (Horizon, custom workers), scheduled tasks (alternatives to cron), and WebSocket servers.

Common Misconception

Supervisor is required for PHP queue workers — systemd handles process supervision natively and is already available on every modern Linux server, making Supervisor optional for simple cases.

Why It Matters

PHP queue workers, WebSocket servers, and custom PHP daemons require process supervision — systemd provides automatic restarts, logging, resource limits, and boot-time startup without additional tooling.

Common Mistakes

  • Not setting Restart=on-failure — crashed services stay down until manually restarted.
  • Running services as root — always specify User= and Group= for security.
  • Not setting WantedBy=multi-user.target — the service doesn't start on boot after systemctl enable.
  • Not reloading systemd after editing unit files: systemctl daemon-reload.

Code Examples

✗ Vulnerable
# No systemd — manual process management:
# Start worker: php artisan queue:work &
# Worker crashes: nobody notices until queue backs up
# Server restarts: worker never comes back
# Multiple workers: manual tracking of PIDs
# Logs: mixed into syslog or lost
✓ Fixed
# /etc/systemd/system/queue-worker.service:
[Unit]
Description=Laravel Queue Worker
After=network.target

[Service]
User=www-data
Group=www-data
WorkingDirectory=/var/www/app
ExecStart=/usr/bin/php artisan queue:work --sleep=3 --tries=3
Restart=on-failure
RestartSec=5
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target

# Enable and start:
# systemctl daemon-reload
# systemctl enable --now queue-worker
# journalctl -u queue-worker -f

Added 16 Mar 2026
Edited 22 Mar 2026
Views 80
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 1 ping W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 1 ping T 0 pings W 4 pings T 2 pings F 1 ping S 0 pings S 1 ping M 1 ping T 1 ping W 0 pings T 2 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 1 ping S 0 pings S 0 pings M 1 ping T 0 pings W
No pings yet today
PetalBot 1
Amazonbot 19 Scrapy 9 Perplexity 8 Unknown AI 5 Ahrefs 5 Google 5 ChatGPT 3 Bing 3 Claude 1 Meta AI 1 Qwen 1 SEMrush 1 PetalBot 1
crawler 57 crawler_json 4 pre-tracking 1
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: Medium
⚡ Quick Fix
Write a systemd unit file for every PHP queue worker — systemd restarts crashed workers, respects boot order dependencies, and exposes logs via journalctl
📦 Applies To
any cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
Queue workers started manually in screen/tmux; no automatic restart on crash; no systemd unit for PHP-FPM workers
Auto-detectable: ✗ No systemd supervisord journalctl
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Low ✗ Manual fix Fix: Medium Context: File


✓ schema.org compliant