#!/sbin/openrc-run

retry="30"

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} --exec /usr/bin/zigbee2mqtt --background --make-pidfile --pidfile /run/${SVCNAME}.pid
	eend $?
}

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