systemd: Creating a Unit File for Auto-Starting a Service on Linux

VDS / VPS Servers · 19.04.2026
systemd: Creating a Unit File for Auto-Starting a Service on Linux

Minimal Unit File

# /etc/systemd/system/myapp.service
[Unit]
Description=My Application
After=network.target

[Service]
ExecStart=/usr/bin/node /opt/myapp/app.js
WorkingDirectory=/opt/myapp
User=www-data
Restart=on-failure

[Install]
WantedBy=multi-user.target

Enable and Start

sudo systemctl daemon-reload
sudo systemctl enable --now myapp
sudo systemctl status myapp
sudo journalctl -u myapp -f
💡 Secrets: Never put passwords directly in the unit file. Use EnvironmentFile=/etc/myapp.env with mode 600. Even better — use systemd credentials or a secrets manager.
← Back to Knowledge Base Ask Support