SpeedDrain
Linux Daemons · systemctl · Unit Files · Process Hardening · Journalctl

Systemd Service Unit File Generator

Generate clean, production-ready .service unit files for Linux servers. Daemonize Node.js, Python, Go, and Docker processes with automatic crash restarts and memory limits.

Presets:

Service Unit Specifications:

File: /etc/systemd/system/speeddrain-web.service
Systemd Security Sandboxing & Resource Limits:
MemoryMax:
Generated /etc/systemd/system/speeddrain-web.service:
[Unit]
Description=SpeedDrain Next.js Web Application
After=network.target network-online.target
Wants=network-online.target
StartLimitIntervalSec=60
StartLimitBurst=5

[Service]
Type=simple
User=www-data
Group=www-data
WorkingDirectory=/var/www/speeddrain
ExecStart=/usr/bin/node /var/www/speeddrain/server.js
Restart=always
RestartSec=5s
EnvironmentFile=/var/www/speeddrain/.env
Environment="NODE_ENV=production" "PORT=3000"
StandardOutput=journal
StandardError=inherit
SyslogIdentifier=speeddrain
ProtectSystem=full
PrivateTmp=true
NoNewPrivileges=true
LimitNOFILE=65536
MemoryMax=2G

[Install]
WantedBy=multi-user.target

Systemd Management Commands:

1. Save the file and reload systemd to register the new service:

sudo nano /etc/systemd/system/speeddrain-web.service
sudo systemctl daemon-reload

2. Enable service at system boot and start it immediately:

sudo systemctl enable --now speeddrain-web.service

3. Check service status and inspect live streaming logs:

sudo systemctl status speeddrain-web.service
sudo journalctl -u speeddrain-web -f -n 100

Modern Linux Process Management with Systemd

01.Why Use Systemd Instead of nohup, screen, or PM2?

In production Ubuntu, Debian, RedHat, and Rocky Linux environments, systemd is the init system (PID 1) responsible for bootstrapping the entire operating system:

  • Automatic Boot Recovery: If the physical VM or cloud instance reboots due to kernel upgrades or hypervisor maintenance, systemd starts your services automatically.
  • Cgroups Resource Isolation: Unlike legacy background scripts, systemd places processes into Linux control groups (cgroups), enforcing strict memory caps (MemoryMax) and CPU quotas.
  • Clean Process Cleanup: When stopping a service, systemd terminates all spawned child processes and worker threads, eliminating orphaned zombie processes.

02.Configuring Restart Policies & Burst Limits

When a backend process throws an unhandled exception:

  • Restart=always: Restarts the process unconditionally, regardless of whether it exited cleanly with return code 0 or failed.
  • Restart=on-failure: Recommended for web servers. Only restarts if terminated by a fatal signal or non-zero exit code.
  • Preventing Crash Loops: To prevent a broken application from thrashing 100% CPU in an infinite crash-restart loop, configure StartLimitBurst=5 and StartLimitIntervalSec=60.

03.Built-in Security Sandboxing

Systemd offers powerful Linux kernel namespace sandboxing features without needing Docker:

  • ProtectSystem=full – Mounts /usr, /boot, and /etc as read-only for this process.
  • PrivateTmp=true – Provides an isolated private /tmp directory hidden from other users.
  • NoNewPrivileges=true – Prevents child processes from gaining root privileges via setuid binaries.

04.Debugging with Journalctl

Any stdout/stderr output written by your process (such as console.log or Python tracebacks) is automatically captured by systemd-journald.

Stream live logs in real time:

journalctl -u my-service -f -n 50

Add -b to inspect logs only since the most recent system reboot.