Goran58 / node-spc-mqtt

MIT License
1 stars 2 forks source link

Run node-spb-mqtt.js as a service #1

Open mauriceflier opened 5 years ago

mauriceflier commented 5 years ago

On ubuntu, o make this js run in the background i've created a .service file and placed it in /etc/systemd/system Next I placed the application folder in /var/opt/node-spc-mqtt.

node-spc-mqtt.service

[Unit]
Description=SPC Gateway MQTT module

[Service]
ExecStart=/var/opt/node-spc-mqtt/node-spc-mqtt.js

Restart=always
User=administrator
# Note Debian/Ubuntu uses 'nogroup', RHEL/Fedora uses 'nobody'
Group=nogroup
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
WorkingDirectory=/var/opt/node-spc-mqtt

[Install]
WantedBy=multi-user.target
systemctl enable node-spc-mqtt.service
systemctl start node-spc-mqtt.service

Maybe it's an idea to create embed something like this by default.

https://stackoverflow.com/questions/4018154/how-do-i-run-a-node-js-app-as-a-background-service