#!/sbin/openrc-run

LOGS=/var/log/xandikos.log
USER=xandikos

name=xandikos
description="xandikos caldav/carddav server"

supervisor=supervise-daemon
supervise_daemon_args="-1 $LOGS -2 $LOGS"

command=/usr/bin/xandikos
command_args="-d $ROOT_DIR -l $LISTEN_ADDRESS -p $LISTEN_PORT --current-user-principal $USER_PRINCIPAL --autocreate"
command_background="yes"

start_stop_daemon_args="--user $USER:$USER"
pidfile="/run/${RC_SVCNAME}.pid"

depend() {
	need net
	after firewall
}

start_pre() {
	if [ -z "$USER_PRINCIPAL" ]; then
		eerror "You must specify a user principal"
		return 1
	fi

	checkpath -f "$LOGS" -m 644 -o "$USER:$USER"
	checkpath -d "$ROOT_DIR" -m 750 -o "$USER:$USER"
}
