Systemd Service File for Node.js
Systemd unit file to run a Node.js app as a managed service with auto-restart and logging.
# /etc/systemd/system/webapp.service
[Unit]
Description=Web Application
After=network.target postgresql.service
Wants=postgresql.service
[Service]
Type=simple
User=webapp
Group=webapp
WorkingDirectory=/opt/webapp
ExecStart=/usr/bin/node dist/server.js
Restart=on-failure
RestartSec=5
StartLimitBurst=5
StartLimitIntervalSec=60
Environment=NODE_ENV=production
Environment=PORT=3000
EnvironmentFile=/opt/webapp/.env
StandardOutput=journal
StandardError=journal
SyslogIdentifier=webapp
LimitNOFILE=65535
TimeoutStopSec=30
[Install]
WantedBy=multi-user.target
# Usage:
# sudo systemctl daemon-reload
# sudo systemctl enable webapp
# sudo systemctl start webapp
# sudo journalctl -u webapp -fUse Cases
- Running production services on Linux servers
- Auto-restart on crash or reboot
- Centralized logging via journald
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
Linux Cron Job Setup Examples
Common crontab entries for database backups, log cleanup, health checks, and certificate renewal.
Logrotate Configuration for Applications
Logrotate config for application logs with daily rotation, compression, and post-rotate hooks.
Docker Compose Multi-Service Setup
Docker Compose configuration for a Node.js app with PostgreSQL, Redis, and Nginx reverse proxy.
Kubernetes Deployment Configuration
Production-ready Kubernetes deployment with replicas, resource limits, health checks, and rolling updates.