#!/bin/bash # # Init file for Zigbee2mqtt [ -x /usr/bin/node ] || exit 1 if ! [ -f /opt/zigbee2mqtt/index.js ]; then echo "Zigbee2mqtt not installed, exiting" exit 2 fi start() { echo -n "Starting Zigbee2mqtt: " pid=`ps -aefw | grep "node index.js" | grep -v " grep " | grep "^zigbee" | awk '{print $2}'` if [ -z "$(echo $pid)" ]; then cd /opt/zigbee2mqtt su - zigbee -c "PATH=/sbin:/bin:/usr/sbin:/usr/bin node index.js" >/dev/null 2>/dev/null & echo "done." else echo "already running with pid $pid" fi } stop() { echo -n "Stopping Zigbee2mqtt: " pid=`ps -aefw | grep "node index.js" | grep -v " grep " | grep "^zigbee" | awk '{print $2}'` if [ -z "$(echo $pid)" ]; then echo "not running." else kill $(echo $pid) echo "done." fi } case "$1" in start) start ;; stop) stop ;; restart) stop sleep 1 start ;; status) pid=`ps -aefw | grep "node index.js" | grep -v " grep " | grep "^zigbee" | awk '{print $2}'` if [ -z "$(echo $pid)" ]; then echo "Status Zigbee2mqtt: not running." else echo "Status Zigbee2mqtt: running with pid $pid." fi ;; *) echo "Usage: $0 {start|stop|restart|status}" esac