Skip to main content
⚑ OpenDevDocs
Deployment
devopsdeploymentGuideIntermediate

Process Managers: systemd vs. PM2

Complete guide to background process management in production, auto-restarts, startup on boot, cluster mode, and comparing systemd with PM2.

Verified: 2026-09-30
Tested on:systemd 255, pm2 5.4.x
Platforms:
linux
#process-manager#systemd#pm2#nodejs#linux

In production, long-running backend processes must run in the background, automatically restart if they crash, spawn across multiple CPU cores, and persist across server reboots.


Comparison: systemd vs PM2

FeaturesystemdPM2
LayerNative Linux OS init system (PID 1)Node.js ecosystem utility
DependenciesPre-installed on almost all Linux distrosRequires Node.js and global npm install
Cluster ModeRequires manual instances or reverse proxyBuilt-in Node cluster mode (instances: 'max')
Resource UsageNear-zero CPU / memory overheadModest Node process overhead
LogsCentral journalctlLocal log files in ~/.pm2/logs/
Best ForGeneric Linux services, Docker engines, Go/Rust/Node binariesNode.js specialized development & VPS deployments

Create /etc/systemd/system/api.service:

[Unit]
Description=Production Node.js API Service
After=network.target postgresql.service

[Service]
Type=simple
User=appuser
WorkingDirectory=/var/www/api
Environment=NODE_ENV=production
EnvironmentFile=/var/www/api/.env
ExecStart=/usr/bin/node dist/server.js
Restart=always
RestartSec=5s
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target
# Reload daemon, enable on boot, and start
sudo systemctl daemon-reload
sudo systemctl enable --now api.service

# Check status and logs
sudo systemctl status api.service
journalctl -u api.service -f

Option 2: PM2 Process Manager

# Start with maximum CPU cluster workers
pm2 start dist/server.js -i max --name "api"

# Save list and generate OS boot startup script
pm2 save
pm2 startup

On this page