#!/bin/sh /etc/rc.common
# Copyright (C) 2011-2016 OpenWrt.org

START=99

USE_PROCD=1

BIN=/usr/bin/prosodyctl

start_service() {
	[ -d /var/run/prosody ] || {
		mkdir /var/run/prosody
		chmod 0755 /var/run/prosody
		chown prosody:prosody /var/run/prosody
	}
	[ -d /var/log/prosody ] || {
		mkdir /var/log/prosody
		chmod 0755 /var/log/prosody
		chown prosody:prosody /var/log/prosody
	}

	[ -d /var/log/prosody ] && {
		chown -R root:prosody /etc/prosody
		chown -R prosody:prosody /etc/prosody/data
	}

	procd_open_instance
	procd_set_param command "$BIN" start
	procd_set_param file /etc/prosody/prosody.cfg.lua
	procd_set_param user prosody
	procd_set_param group prosody
	procd_close_instance
}

stop_service() {
	${BIN} stop
}

reload_service() {
	${BIN} reload
}
