Systemd Services & Unit Files
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
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
16 Mar 2026
Edited
22 Mar 2026
Views
42
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 2
Amazonbot 1
Amazonbot 1
Amazonbot 18
Perplexity 8
Unknown AI 4
Ahrefs 3
Google 3
ChatGPT 1
Bing 1
How they use it
crawler 36
crawler_json 1
pre-tracking 1
Related categories
⚡
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