#!/sbin/openrc-run
# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

LOGFILE=/var/log/spectrum2/std.log
piddir=${pid_dir:-/var/run/spectrum2}

depend() {
	need net
	use jabber-server
}

start() {
	ebegin "Starting ${PROTOCOL} Spectrum Transport"
	if [ ! -d ${piddir} ]; then
		checkpath -q -d -o jabber:jabber -m 0755 ${piddir} || return
	fi
	start-stop-daemon --start --user jabber --group jabber \
		--exec /usr/bin/spectrum2_manager start &> $LOGFILE
	eend $?
}

stop() {
	ebegin "Stopping ${PROTOCOL} Spectrum Transport"
	start-stop-daemon --user jabber --group jabber \
		--exec /usr/bin/spectrum2_manager stop 1>>$LOGFILE 2>&1
	eend $?
}

status() {
	local _retval
	einfon ""
	/usr/bin/spectrum2_manager status &> /dev/null
	_retval=$?
	if [ x${_retval} = 'x0' ]; then
		mark_service_started "${SVCNAME}"
		eend 0
	else
		mark_service_stopped "${SVCNAME}"
		eend 3
	fi
}