-
-
Save ryanburnette/a008fc7bcebda4e7a7335d1f304c6cfe to your computer and use it in GitHub Desktop.
[Unit] | |
Description=service | |
After=network.target | |
[Service] | |
Type=simple | |
User=ubuntu | |
WorkingDirectory=/opt/service | |
ExecStart=/bin/bash -c 'exec bin/node app.js 2>&1 >> logs/console.log' | |
Restart=always | |
[Install] | |
WantedBy=multi-user.target |
You may want Restart=always
because when v8 crashes it gives a success status code.
@coolaj86 Thanks for the insight. Done.
For logging...
https://gist.github.com/ryanburnette/a008fc7bcebda4e7a7335d1f304c6cfe#file-node-service-L10-L11
Read these...
https://stackoverflow.com/a/43830129/2535178
systemd/systemd#7198 (comment)
If you don't have a new enough version of systemd on Ubuntu... read this...
The last comment about logging isn't working as intended. It also requires that I use Ubuntu 18.04, which I don't have the ability to do in all my environments.
I'm going to try this approach next. https://www.axllent.org/docs/view/nodejs-service-with-systemd/#comment-3322013904
@coolaj86 just DEPRECATED this approach in favor of https://git.coolaj86.com/coolaj86/go-serviceman
https://nodesource.com/blog/running-your-node-js-app-with-systemd-part-1/
https://www.linode.com/docs/quick-answers/linux/start-service-at-boot/