#!/bin/sh /etc/rc.common

START=95
STOP=10
USE_PROCD=1

EXTRA_COMMANDS="status"
EXTRA_HELP="	status	Show mail server status"

SERVICE_BIN="/usr/sbin/mailinaboxctl"

start_service() {
	local enabled
	config_load mailinabox
	config_get enabled main enabled 0

	[ "$enabled" != "1" ] && {
		echo "Mail server is disabled. Enable with: uci set mailinabox.main.enabled=1"
		return 0
	}

	procd_open_instance
	procd_set_param command "$SERVICE_BIN" service-run
	procd_set_param respawn 3600 5 5
	procd_set_param stdout 1
	procd_set_param stderr 1
	procd_close_instance
}

stop_service() {
	"$SERVICE_BIN" service-stop >/dev/null 2>&1
}

restart_service() {
	stop_service
	sleep 2
	start_service
}

status() {
	"$SERVICE_BIN" status
}
