#!/sbin/openrc-run

depend() {
	need mosquitto
}

checkconfig() {
	if [ ! -f /var/lib/${SVCNAME}/configuration.yaml ] ; then
		eerror "No /var/lib/${SVCNAME}/configuration.yaml file exists!"
	fi
}

start() {
	checkconfig || return 1
	ebegin "Starting ${SVCNAME}"
	start-stop-daemon --start --user zigbee2mqtt:zigbee2mqtt --env ZIGBEE2MQTT_DATA=/var/lib/${SVCNAME} --chdir /usr/lib64/node_modules/zigbee2mqtt --exec /usr/bin/npm --background --make-pidfile --pidfile /run/${SVCNAME}.pid -- start
	eend $?
}

stop() {
	ebegin "Stopping ${SVCNAME}"
	start-stop-daemon --stop --quiet --retry 10 --pidfile /run/${SVCNAME}.pid
	eend $?
}
