Skip to content

Instantly share code, notes, and snippets.

@risyasin
Last active March 2, 2016 15:21
Show Gist options
  • Save risyasin/f3cad42c6e84a3820c50 to your computer and use it in GitHub Desktop.
Save risyasin/f3cad42c6e84a3820c50 to your computer and use it in GitHub Desktop.
Systemd service for Node.js app

Copy this myapp.service file under /etc/systemd/system

Enable service (starts at boot time) systemctl enable myapp.service

Start service immediately systemctl start myapp.service

Display logs of service (stdout) journalctl -u myapp.service

[Unit]
Description=MyApp Daemon
After=elasticsearch.service
[Service]
WorkingDirectory=/web/myapp
ExecStart=/opt/nodejs/bin/node index.js
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=myapp
User=www-data
Group=www-data
Environment=NODE_ENV=production
[Install]
WantedBy=multi-user.target
@risyasin
Copy link
Author

Save it as /etc/systemd/system/myapp.service
Runs at boot
systemctl enable myapp
Start it immediately
systemctl start myapp
View status
systemctl status myapp
View all logs from app stdout
journalctl -u myapp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment