Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to run zigbee2mqtt as a service #1138

Closed
RefineryX opened this issue Feb 21, 2019 · 6 comments
Closed

Not able to run zigbee2mqtt as a service #1138

RefineryX opened this issue Feb 21, 2019 · 6 comments

Comments

@RefineryX
Copy link

RefineryX commented Feb 21, 2019

Followed the Running Zigbee2mqtt in Virtual Environment docs perfectly. Then at step 5: Running as a daemon with systemctl....

I create the filesudo nano /etc/systemd/system/zigbee2mqtt.service and add

[Unit]
Description=zigbee2mqtt
After=network.target

[Service]
ExecStart=/bin/bash -c 'source /opt/zigbee2mqtt/bin/activate; /opt/zigbee2mqtt/bin/npm start'
WorkingDirectory=/opt/zigbee2mqtt
StandardOutput=inherit
StandardError=inherit
Restart=always
User=dietpi

[Install]
WantedBy=multi-user.target

I check start sudo systemctl start zigbee2mqtt

Upon checking the status, I get this error

dietpi@SmartHome:~$ sudo systemctl status zigbee2mqtt
● zigbee2mqtt.service - zigbee2mqtt
   Loaded: loaded (/etc/systemd/system/zigbee2mqtt.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Thu 2019-02-21 15:37:26 GMT; 1min 32s ago
  Process: 1479 ExecStart=/bin/bash -c source /opt/zigbee2mqtt/bin/activate; /opt/zigbee2mqtt/bin/npm start (code=exited, status=217/USER)
 Main PID: 1479 (code=exited, status=217/USER)

Feb 21 15:37:26 SmartHome systemd[1]: zigbee2mqtt.service: Service hold-off time over, scheduling restart.
Feb 21 15:37:26 SmartHome systemd[1]: Stopped zigbee2mqtt.
Feb 21 15:37:26 SmartHome systemd[1]: zigbee2mqtt.service: Start request repeated too quickly.
Feb 21 15:37:26 SmartHome systemd[1]: Failed to start zigbee2mqtt.
Feb 21 15:37:26 SmartHome systemd[1]: zigbee2mqtt.service: Unit entered failed state.
Feb 21 15:37:26 SmartHome systemd[1]: zigbee2mqtt.service: Failed with result 'exit-code'.
@RefineryX
Copy link
Author

Actually... the above error was down to the fact I don't have a pi user on my system - instead I use diepi user. I corrected this and rebooted - however it does not start upon boot.

dietpi@SmartHome:~$ sudo systemctl status zigbee2mqtt
● zigbee2mqtt.service - zigbee2mqtt
   Loaded: loaded (/etc/systemd/system/zigbee2mqtt.service; disabled; vendor preset: enabled)
   Active: inactive (dead)

I started again sudo systemctl start zigbee2mqtt and checked the status and it looks as though its online.

Do you know how I can get this to run after a restart?

@RefineryX
Copy link
Author

Fixed. Had to enable using sudo systemctl enable zigbee2mqtt.service - wasn't clear in the virtual environment documentation. Having to switch between to pages.

@mercs600
Copy link

mercs600 commented Apr 3, 2019

For everyone else who doesn't use virtual env. I got the same issue but with clean installation. I used node as runner instead of npm.

ExecStart=/home/pi/.nvm/versions/node/v10.15.3/bin/node index.js

Please make sure your node path is correct by:

whereis node

@Sir-Ironic
Copy link

WORKS !!!!
Really thanks.

2 days to read and try everything
nodejs (v12.16.3) is installed from root and haven't pi user, juste 'root' and i created 'jeed'

So, i just replace :

ExecStart=/usr/bin/npm start
by
ExecStart=/root/.nvm/versions/node/v12.16.3/bin/node index.js
and
User=pi
by
User=root

Now, service is launched at boot

@JaraZem
Copy link

JaraZem commented Jun 19, 2024

2024.06.19 WORKS !!!

So, i change :

User=pi >>>>> User=root

my file today looks:

[Unit]
Description=zigbee2mqtt
After=network.target

[Service]
Environment=NODE_ENV=production
Type=notify
ExecStart=/usr/bin/node index.js
WorkingDirectory=/opt/zigbee2mqtt
StandardOutput=null
StandardError=inherit
WatchdogSec=10s
Restart=always
RestartSec=10s
User=root

[Install]
WantedBy=multi-user.target


AČIŪ !!!

@adnev
Copy link

adnev commented Jun 24, 2024

Hi!
I am facing this the same problem of the second post at every restart.
Active: inactive (dead)
I need to use the systemctl restart zigbee2mqtt command to make it run.

@JaraZem Thanks for the solution but is it safe to use the root user to run z2m ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants