Skip to content

Instantly share code, notes, and snippets.

@hotohoto
Created August 23, 2017 05:27
Show Gist options
  • Save hotohoto/51c4a6504000dbf388aa9150e07cf892 to your computer and use it in GitHub Desktop.
Save hotohoto/51c4a6504000dbf388aa9150e07cf892 to your computer and use it in GitHub Desktop.
Run Node.js web server via systemctl

Make a configuration file like below at /etc/systemd/system/nodejs_www.service.

[Unit]
Description=My Node.js Web Server

[Service]
ExecStart=/usr/bin/yarn start

WorkingDirectory=/home/hotohoto/app
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=nodejs_www
User=hotohoto
Group=hotohoto
Environment=XXX=1234 YYY=5678

[Install]
WantedBy=multi-user.target

Enable the service.

sudo systemctl enable nodejs_www.service
Created symlink from /etc/systemd/system/multi-user.target.wants/nodejs_www.service to /etc/systemd/system/nodejs_www.service.

Show service status

sudo systemctl status nodejs_www

Reload service after changing

sudo systemctl daemon-reload

Restart the service

sudo systemctl restart nodejs_www

Show logs

tail -f /var/log/syslog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment