Skip to content

Instantly share code, notes, and snippets.

@kaisbaccour
Created January 16, 2024 18:09
Show Gist options
  • Save kaisbaccour/692490563d759ef9d7bede03e9cb94f5 to your computer and use it in GitHub Desktop.
Save kaisbaccour/692490563d759ef9d7bede03e9cb94f5 to your computer and use it in GitHub Desktop.

Add systemd

#add config file
sudo echo "[Unit]
Description=Randdrop
After=network.target

[Service]
Environment=NODE_ENV=production
Type=simple
User=root
WorkingDirectory=/root/randdrop-api
ExecStart=/usr/bin/node dist/index.js
Restart=always
RestartSec=3
# Node.js application logs
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=randdrop

[Install]
WantedBy=multi-user.target" > /lib/systemd/system/randdrop-api.service
# turn off current randdrop process so you dont get port conflict afterwards
# reload deamon to take the new service into account
sudo systemctl daemon-reload
# make sure service starts on machine boot
sudo systemctl enable randdrop-api
sudo systemctl start randdrop-api
# check logs and status
sudo systemctl status randdrop-api
journalctl -u randdrop-api
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment