#!/bin/sh
# kFreeBSD do not accept scripts as interpreters, using #!/bin/sh and sourcing.
if [ true != "$INIT_D_SCRIPT_SOURCED" ] ; then
    set "$0" "$@"; INIT_D_SCRIPT_SOURCED=true . /lib/init/init-d-script
fi
### BEGIN INIT INFO
# Provides:		corosync-qnetd
# Required-Start:	$remote_fs $syslog
# Required-Stop:	$remote_fs $syslog
# Default-Start:	2 3 4 5
# Default-Stop:		0 1 6
# Short-Description:	Corosync Qdevice Network daemon
# Description:		Starts and stops Corosync Qdevice Network daemon.
### END INIT INFO

NAME="corosync-qnetd"
DESC="Corosync Qdevice Network daemon"
DAEMON="/usr/bin/$NAME"
RUNDIR="/run/$NAME"
PIDFILE="/run/$NAME/$NAME.pid"

CONFIG="/etc/default/$NAME"
[ -f "$CONFIG" ] && . "$CONFIG"

DAEMON_ARGS="$COROSYNC_QNETD_OPTIONS"
USER="${COROSYNC_QNETD_RUNAS:-coroqnetd}"
START_ARGS="--chuid $USER"

do_start_prepare() {
    if grep -q nocluster /proc/cmdline; then
        log_failure_msg "not configured to run at boot"
        exit 1
    fi

    mkdir -p "$RUNDIR"
    chown "$USER:$USER" "$RUNDIR"
}
