#!/sbin/openrc-run
# Copyright 2013 Alpine Linux 
# Distributed under the terms of the GNU General Public License v2

extra_stopped_commands="compile"

: ${SVCHOME:=/var/lib/$SVCNAME}
: ${pidfile:=/var/run/${SVCNAME%%.*}/${SVCNAME#*.}.pid}

depend() {
	use net
	need localmount
}
compile() {
	ebegin "Compiling configuration for ${SVCNAME}"
	cd ${SVCHOME}
	./clean.py
	./compile.py
	eend $?
}

start() {
	compile || return 1
	checkpath --directory --owner iris ${pidfile%/*}
	ebegin "Starting ${SVCNAME}"
	start-stop-daemon --exec ${SVCHOME}/run.py \
		--pidfile $pidfile \
		--chdir $SVCHOME \
		--user iris:iris \
		--background \
		--stdout /dev/null \
		--stderr /dev/null \
		--wait 500 \
		-- \
		-P $pidfile \
		$ARGS

	eend $?
}
