1

If this is not the right place to post a this question, please say.

I’m running zigbee2mqtt (Zigbee broker) on a USB dongle device (CC2531 with antenna, forgot the antenna model) and a Linux machine (KDE neon User Edition 5.19, based on Ubuntu 18.04). Sometimes zigbee2mqtt stops working and I have to change the ownership of the device (with chown) to successfully run it again. So I put it in one script:

~/my_services/zigbee2mqtt_service $ cat z2m.sh 
sudo chown gal /dev/ttyACM0
cd /opt/zigbee2mqtt
npm start

and created a service in systemd to run the script:

~/my_services/zigbee2mqtt_service $ systemctl cat zigbee2mqtt.service 
# /etc/systemd/system/zigbee2mqtt.service
[Unit]
Description=zigbee2mqtt
After=network.target
[Service]
# ExecStart=/usr/local/bin/npm start
# WorkingDirectory=/opt/zigbee2mqtt
ExecStart=/home/gal/my_services/zigbee2mqtt_service/z2m.sh
StandardOutput=inherit
StandardError=inherit
Restart=always
User=gal
[Install]
WantedBy=multi-user.target

This used to work, but for some reason, now the service won't start. I’m tried enabling it, starting manually, and to reload daemon. If I run the z2m.sh script manually it works well, but I’m working from a remote machine so I have to disconnect, which stops zigbee2mqtt.

It’d be great if you can point me to what to fix, or to a different way to recover from the ‘revoked ownership’.

Edit: This is what I get when checking the service status:

~ $ systemctl status zigbee2mqtt.service 
● zigbee2mqtt.service - zigbee2mqtt
   Loaded: loaded (/etc/systemd/system/zigbee2mqtt.service; enabled; vendor pres
   Active: failed (Result: exit-code) since Mon 2020-07-20 11:00:57 IDT; 2 days 
  Process: 4059 ExecStart=/home/gal/my_services/zigbee2mqtt_service/z2m.sh (code
 Main PID: 4059 (code=exited, status=203/EXEC)

Jul 20 11:00:57 phoenix systemd[1]: zigbee2mqtt.service: Service hold-off time o
Jul 20 11:00:57 phoenix systemd[1]: zigbee2mqtt.service: Scheduled restart job, 
Jul 20 11:00:57 phoenix systemd[1]: Stopped zigbee2mqtt.
Jul 20 11:00:57 phoenix systemd[1]: zigbee2mqtt.service: Start request repeated 
Jul 20 11:00:57 phoenix systemd[1]: zigbee2mqtt.service: Failed with result 'exi
Jul 20 11:00:57 phoenix systemd[1]: Failed to start zigbee2mqtt.
lines 1-12/12 (END)
  • What information about the systemd service do you get via systemctl status zigbee2mqttand via journalctl -u zigbee2mqtt? As a workaround you can start the script with nohup ~/my_services/zigbee2mqtt_service/z2m.shso that it continues after you disconnected from the remote machine. – palto Jul 22 at 17:54
  • @palto Right, I forgot about nohup, I'll use it in the meanwhile. I'm adding the systemctl status print to the post! – Gal Jul 22 at 18:11
  • Try to reference the full path to npm in your script. In another forum I found this hint which might help zigbee2mqtt.discourse.group/t/zigbee2mqtt-not-starting/713/12 – palto Jul 22 at 18:32
  • Thanks@palto, I've however found a more correct way to sovle the original problem and have the service deal only with zigbee2mqtt, and not the ownership. Then the scipt becomes redundent. – Gal Jul 25 at 12:31
1

Thanks to DrTron at this post, I've found the correct way to fix this issue which is to add the user to the group that has permissions to USB devices.

case someone else is interested, I’ve add my user ‘gal’ to the dialout group with

sudo adduser gal dialout

Then, the systemd service only needs to take care to zigbee2mqtt so I’ve changed the service to:

$ systemctl cat zigbee2mqtt.service 
# /etc/systemd/system/zigbee2mqtt.service
[Unit]
Description=zigbee2mqtt
After=network.target

[Service]
ExecStart=/usr/local/bin/npm start
WorkingDirectory=/opt/zigbee2mqtt
StandardOutput=inherit
StandardError=inherit
Restart=always
User=gal

[Install]
WantedBy=multi-user.target

Lastly, I’ve logged out and logged in and started the service with the new configuration.

$ systemctl daemon-reload
$ systemctl start zigbee2mqtt.service
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.