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