Manually installing zwaveJS on Centos 8 with Sample systemd unit file

I opted to run and install zwaveJS manually (I have a background in system administration and maybe I just like pain as opposed to containerization). Regardless, this is how I did it:

With a user who can is part of the sudoers, run:

sudo dnf module install nodeJS:12

As I mentioned in the title, I’m on Centos 8, but the instructions linked below should get you going on ubuntu:

https://github.com/nodesource/distributions/blob/master/README.md#debinstall

I created a separate user for the zwaveJS service- you have to add the user to the dialout group the user can talk to the serial devices:

sudo useradd zwaveJS -g dialout

I then sudo’ed as the newly created zwaveJS user:

sudo -u zwaveJS -H -s

Making sure I watched for ERRORS and WARNS, I ran the following commands:

cd /~
npm install [email protected]
npm install -d typescript
npm install -d ts-node
npm install --save-dev tslib @types/node
npm install [email protected]^8.1.1
npm install @zwave-js/server
npm install --save-dev @types/ws
npm install --save-dev @types/triple-beam
npm install --save-dev @types/minimist

From there, all I needed was the path to my usb zwave bridge, and I’ll leave that to you to figure out, but make sure you replace /dev/serial/by-id/XXXXXXX with your true path below in the service file.

If you read the documentation for ts-node, it tells you that you should have a really nice ts-node command, but this is elusive- when I tested the commands on my main user, I installed it with nmp install -g ts-node it installed, but when I did it with my tested isolated user, ts-node was not a command. It runs out, ts-node just symlinks to a node_modules/ts-node/dist/bin.js with the node_module directory itself, so I formatted the ExecStart command to just call that absolute path when I crafted the service:

[Unit]
Description=zwaveJS

[Service]
ExecStart=/usr/bin/node /home/zwaveJS/node_modules/ts-node/dist/bin.js /home/zwaveJS/node_modules/@zwave-js/server/src/bin/server.ts /dev/serial/by-id/XXXXXXX
# Required on some systems
WorkingDirectory=/home/zwaveJS
Restart=always
# Restart service after 10 seconds if node service crashes
RestartSec=10
StandardOutput=journal
StandardError=journal
User=zwaveJS
Restart=on-failure

[Install]
WantedBy=multi-user.target

I put the file in /etc/systemd/system/zwaveJS.service, so after running sudo systemctl daemon-reload, I’m able to start the service with:

sudo systemctl start zwaveJS

and don’t forget to enable the service for auto start on boot:

sudo systemctl enable zwaveJS.service

and the logs get dropped to JournalD, so you can view logs with:

journalctl -u zwaveJS.service