Soo. I can start zigbee2mqtt with "npm start" from /opt/zigbee2mqtt. But when I try to start it as a service I get this Error:
Loaded: loaded (/etc/systemd/system/zigbee2mqtt.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sat 2019-05-04 14:57:45 CEST; 3s ago
Process: 24824 ExecStart=/usr/bin/npm start (code=exited, status=203/EXEC)
Main PID: 24824 (code=exited, status=203/EXEC)
May 04 14:57:45 hassbian systemd[1]: zigbee2mqtt.service: Failed with result 'exit-code'.
May 04 14:57:45 hassbian systemd[1]: zigbee2mqtt.service: Service hold-off time over, scheduling restart.
May 04 14:57:45 hassbian systemd[1]: Stopped zigbee2mqtt.
May 04 14:57:45 hassbian systemd[1]: zigbee2mqtt.service: Start request repeated too quickly.
May 04 14:57:45 hassbian systemd[1]: Failed to start zigbee2mqtt.
May 04 14:57:45 hassbian systemd[1]: zigbee2mqtt.service: Unit entered failed state.
May 04 14:57:45 hassbian systemd[1]: zigbee2mqtt.service: Failed with result 'exit-code'.
My service file looks like this:
[Unit]
Description=zigbee2mqtt
After=network.target
[Service]
ExecStart=/usr/bin/npm start
WorkingDirectory=/opt/zigbee2mqtt
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi
[Install]
WantedBy=multi-user.target
I already deleted /opt/zigbee2mqtt and reinstalled it. Still the same error message.
Also tried as user "pi" and "root".
No clue where to go from here. Can anyone help me with this?
Could you post the zigbee2mqtt log when starting as a service? Log can be found in the data/log folder.
There is no log being created when starting it as a service. Its just created when starting it with npm start from the folder.
What is the output of sudo journalctl -u zigbee2mqtt.service -f?
Tried that already to see if it gives me more information but the same as the above error message unfortunately.
May 05 19:42:19 hassbian systemd[1]: Started zigbee2mqtt.
May 05 19:42:19 hassbian systemd[1]: zigbee2mqtt.service: Main process exited, code=exited, status=203/EXEC
May 05 19:42:19 hassbian systemd[1]: zigbee2mqtt.service: Unit entered failed state.
May 05 19:42:19 hassbian systemd[1]: zigbee2mqtt.service: Failed with result 'exit-code'.
May 05 19:42:19 hassbian systemd[1]: zigbee2mqtt.service: Service hold-off time over, scheduling restart.
May 05 19:42:19 hassbian systemd[1]: Stopped zigbee2mqtt.
May 05 19:42:19 hassbian systemd[1]: zigbee2mqtt.service: Start request repeated too quickly.
May 05 19:42:19 hassbian systemd[1]: Failed to start zigbee2mqtt.
May 05 19:42:19 hassbian systemd[1]: zigbee2mqtt.service: Unit entered failed state.
May 05 19:42:19 hassbian systemd[1]: zigbee2mqtt.service: Failed with result 'exit-code'.
Can you try running with:
[Unit]
Description=zigbee2mqtt
After=network.target
[Service]
ExecStart=/usr/bin/npm start
WorkingDirectory=/opt/zigbee2mqtt
StandardOutput=/tmp/zigbee2mqtt
StandardError=/tmp/zigbee2mqtt
Restart=always
User=pi
[Install]
WantedBy=multi-user.target
and post the content of /tmp/zigbee2mqtt ?
There is nothing being created in /tmp when starting/restarting the service with that.
Is there something logged to syslog when starting the service? (tail -f /var/log/syslog)
Actually, it does. Something odd, tbh.
May 7 18:19:27 hassbian systemd[1]: Started zigbee2mqtt.
May 7 18:19:27 hassbian systemd[11421]: zigbee2mqtt.service: Failed at step EXEC spawning /usr/bin/npm: No such file or directory
May 7 18:19:27 hassbian systemd[1]: zigbee2mqtt.service: Main process exited, code=exited, status=203/EXEC
May 7 18:19:27 hassbian systemd[1]: zigbee2mqtt.service: Unit entered failed state.
May 7 18:19:27 hassbian systemd[1]: zigbee2mqtt.service: Failed with result 'exit-code'.
May 7 18:19:28 hassbian systemd[1]: zigbee2mqtt.service: Service hold-off time over, scheduling restart.
May 7 18:19:28 hassbian systemd[1]: Stopped zigbee2mqtt.
That's pretty odd. Because:

The only thing that's not normal compared to the other files in there is that npm is red colored. Not sure what that means, though.
[Unit]
Description=zigbee2mqtt
After=network.target
[Service]
ExecStart=npm start
WorkingDirectory=/opt/zigbee2mqtt
StandardOutput=/tmp/zigbee2mqtt
StandardError=/tmp/zigbee2mqtt
Restart=always
User=pi
[Install]
WantedBy=multi-user.target
That gives me:
May 07 18:44:23 hassbian systemd[1]: [/etc/systemd/system/zigbee2mqtt.service:6] Executable path is not absolute, ignoring: npm start
What is the output of which npm
Yea I just tried that, as it came to my mind aswell. Its giving me:
/home/pi/.nvm/versions/node/v10.15.3/bin/npm
So I tried something like this:
[Unit]
Description=zigbee2mqtt
After=network.target
[Service]
ExecStart=/home/pi/.nvm/versions/node/v10.15.3/bin/npm start
WorkingDirectory=/opt/zigbee2mqtt
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi
[Install]
WantedBy=multi-user.target
And that gives me in syslog:
May 7 18:54:11 hassbian systemd[1]: Started zigbee2mqtt.
May 7 18:54:11 hassbian npm[12213]: /usr/bin/env: ‘node’: Too many levels of symbolic links
May 7 18:54:11 hassbian systemd[1]: zigbee2mqtt.service: Main process exited, code=exited, status=127/n/a
May 7 18:54:11 hassbian systemd[1]: zigbee2mqtt.service: Unit entered failed state.
May 7 18:54:11 hassbian systemd[1]: zigbee2mqtt.service: Failed with result 'exit-code'.
May 7 18:54:12 hassbian systemd[1]: zigbee2mqtt.service: Service hold-off time over, scheduling restart.
May 7 18:54:12 hassbian systemd[1]: Stopped zigbee2mqtt.
ls -All /home/pi/.nvm/versions/node/v10.15.3/bin/npm
lrwxrwxrwx 1 pi pi 38 Mar 5 16:07 /home/pi/.nvm/versions/node/v10.15.3/bin/npm -> ../lib/node_modules/npm/bin/npm-cli.js
Also what I just notice that, things like:
npm install npm -g
works but
sudo npm install npm -g throws out sudo: npm: command not found
Maybe thats a hint in the right direction idk.
Did you follow the installing section of http://www.zigbee2mqtt.io/getting_started/running_zigbee2mqtt.html ?
Yes.
Well I just fixed it myself. It turned out that my npm installation was broken somehow.
I completly uninstalled npm and nodejs, like did some google research where all the files are located. And then reinstalled it with:
sudo curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs git make g++ gcc
Now its working.
Thanks for the help!
I had this issue and solved it by changing:
ExecStart=/usr/bin/npm start
To
ExecStart=/usr/local/bin/npm start
I have the same problem but y I change
ExecStart=/usr/bin/npm start
to
ExecStart=/usr/local/bin/npm start
I change error
systemctl status zigbee2mqtt.service
● zigbee2mqtt.service - zigbee2mqtt
Loaded: loaded (/etc/systemd/system/zigbee2mqtt.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2020-01-03 18:19:48 CET; 7s ago
Process: 8946 ExecStart=/usr/bin/npm start (code=exited, status=1/FAILURE)
Main PID: 8946 (code=exited, status=1/FAILURE)
to
zigbee2mqtt.service - zigbee2mqtt
Loaded: loaded (/etc/systemd/system/zigbee2mqtt.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2020-01-03 18:16:04 CET; 6s ago
Process: 8197 ExecStart=/usr/local/bin/npm start (code=exited, status=203/EXEC)
Main PID: 8197 (code=exited, status=203/EXEC)
somebody can help me?
Sorry
I solved my problem yet, I change user=pi to user=root
easy.
I had very similar problem with similar solution (adding "local" to the path) so I will post my log from raspbian for somebody to find it here and to find the solution as well.
-- Logs begin at Thu 2020-01-23 20:17:01 CET. --
Jan 23 21:16:07 raspberrypi systemd[1]: zigbee2mqtt.service: Failed with result 'exit-code'.
Jan 23 21:16:07 raspberrypi systemd[1]: zigbee2mqtt.service: Service RestartSec=100ms expired, scheduling restart.
Jan 23 21:16:07 raspberrypi systemd[1]: zigbee2mqtt.service: Scheduled restart job, restart counter is at 5.
Jan 23 21:16:07 raspberrypi systemd[1]: Stopped zigbee2mqtt.
Jan 23 21:16:07 raspberrypi systemd[1]: zigbee2mqtt.service: Start request repeated too quickly.
Jan 23 21:16:07 raspberrypi systemd[1]: zigbee2mqtt.service: Failed with result 'exit-code'.
Jan 23 21:16:07 raspberrypi systemd[1]: Failed to start zigbee2mqtt.
I just had a similar problem, the zigbee2mqtt systemd service wouldn't start at bootup. In my case, I found some zigbee2mqtt:error lines stating Error while opening serialport 'Error: Error: Device or resource busy, cannot open /dev/... lines in the syslog. Close to these lines there were some other log messages which read ModemManager: <warn> Could not grab port (tty/ttyACM0): 'Cannot add port 'tty/ttyACM0', unhandled serial type'.
I assumed that the problem with zigbee2mqtt not starting might have something to do with the zigbee2mqtt and ModemManager systemd services both trying to access /dev/ttyACM0 at the same time. I tried disabling the ModemManager service via sudo systemctl disable ModemManager.service (I assume I don't need that service anyway), and on the next boot the problem was indeed solved.
More info on this:
If you install it on a Pi Zero which requires you to use THIS GUIDE to install NPM instead of the one linked on the Z2M Wiki Page you HAVE to replace the ExecStart=/usr/bin/npm start with ExecStart=/usr/local/bin/npm start since that guide installs the npm binaries into another folder than the usual installer does.
@Koenkk A mention of this on the installation page would be nice so others don't fall into the same trap :D
@EpicLPer updated, thanks!
Most helpful comment
I had this issue and solved it by changing:
ExecStart=/usr/bin/npm start
To
ExecStart=/usr/local/bin/npm start