Skip to content

Commit bff7156

Browse files
authored
Use Type=notify in systemd service files (Koenkk#2475)
This documents the feature added in Koenkk/zigbee2mqtt#20482.
1 parent a32da90 commit bff7156

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

β€Ždocs/guide/installation/01_linux.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,13 @@ After=network.target
156156

157157
[Service]
158158
Environment=NODE_ENV=production
159-
Type=exec
160-
ExecStart=/usr/bin/npm start
159+
Type=notify
160+
ExecStart=/usr/bin/node index.js
161161
WorkingDirectory=/opt/zigbee2mqtt
162162
StandardOutput=inherit
163163
# Or use StandardOutput=null if you don't want Zigbee2MQTT messages filling syslog, for more options see systemd.exec(5)
164164
StandardError=inherit
165+
WatchdogSec=10s
165166
Restart=always
166167
RestartSec=10s
167168
User=pi
@@ -170,7 +171,7 @@ User=pi
170171
WantedBy=multi-user.target
171172
```
172173
173-
> If you are using a Raspberry Pi 1 or Zero AND if you followed this [guide](https://gist.github.com/Koenkk/11fe6d4845f5275a2a8791d04ea223cb), replace `ExecStart=/usr/bin/npm start` with `ExecStart=/usr/local/bin/npm start`.
174+
> If you are using a Raspberry Pi 1 or Zero AND if you followed this [guide](https://gist.github.com/Koenkk/11fe6d4845f5275a2a8791d04ea223cb), replace `ExecStart=/usr/bin/node index.js` with `ExecStart=/usr/local/bin/node index.js`.
174175
175176
> If you are using a Raspberry Pi or a system running from a SD card, you will likely want to minimize the amount of log files written to disk. Systemd service with `StandardOutput=inherit` will result in logging everything twice: once in `journalctl` through the systemd unit and once from Zigbee2MQTT default logging to files under `data/log`. You will likely want to keep only one of them:
176177
> > Keep only the logs under `data/log` --> use `StandardOutput=null` in the systemd unit. **or**
@@ -179,7 +180,7 @@ WantedBy=multi-user.target
179180
180181
> If you want to use another directory to place all Zigbee2MQTT data, add `Environment=ZIGBEE2MQTT_DATA=/path/to/data` below `[Service]`
181182
182-
> Using `Type=exec` is convenient so the systemctl is informed if the service can't start because of problems in the unit definition.
183+
> Using `Type=notify` makes systemd aware of when zigbee2mqtt has started up and is e.g. listening on its [Frontend](../configuration/frontend.md) sockets. This is useful for starting other, dependent systemd units or for using the `ExecStartPost=` attribute. For example, to allow a [Reverse Proxy](../configuration/frontend.md#nginx-proxy-configuration) to access zigbee2mqtt's Unix socket, you could add `ExecStartPost=setfacl -m u:www-data:rw /run/zigbee2mqtt/zigbee2mqtt.sock` to the `[Service]` section and `apt install acl`.
183184
184185
Save the file and exit.
185186
@@ -200,9 +201,7 @@ pi@raspberry:/opt/zigbee2mqtt $ systemctl status zigbee2mqtt.service
200201
Active: active (running) since Thu 2018-06-07 20:27:22 BST; 3s ago
201202
Main PID: 665 (npm)
202203
CGroup: /system.slice/zigbee2mqtt.service
203-
β”œβ”€665 npm
204-
β”œβ”€678 sh -c node index.js
205-
└─679 node index.js
204+
└─679 /usr/bin/node index.js
206205
207206
Jun 07 20:27:22 raspberry systemd[1]: Started zigbee2mqtt.
208207
Jun 07 20:27:23 raspberry npm[665]: > [email protected] start /opt/zigbee2mqtt

β€Ždocs/guide/installation/07_python_virtual_environment.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ Description=zigbee2mqtt
7575
After=network.target
7676

7777
[Service]
78-
ExecStart=/bin/bash -c 'source /opt/zigbee2mqtt/bin/activate; /opt/zigbee2mqtt/bin/npm start'
78+
Type=notify
79+
Environment=NODE_PATH=/opt/zigbee2mqtt/lib/node_modules
80+
Environment=NPM_CONFIG_PREFIX=/opt/zigbee2mqtt
81+
Environment=npm_config_prefix=/opt/zigbee2mqtt
82+
Environment=NODE_ENV=production
83+
ExecStart=/opt/zigbee2mqtt/bin/node index.js
7984
WorkingDirectory=/opt/zigbee2mqtt
8085
StandardOutput=inherit
8186
StandardError=inherit

0 commit comments

Comments
Β (0)