#!/bin/sh

# PROVIDE: thelounge
# REQUIRE: networking
# KEYWORD: shutdown

. /etc/rc.subr

name="thelounge"
rcvar="thelounge_enable"
start_precmd="thelounge_precmd"
procname="/usr/local/bin/node"
pidfile="/var/run/${name}.pid"

load_rc_config $name

: ${thelounge_enable:="NO"}
: ${thelounge_home:="/usr/local/etc/thelounge"}
: ${thelounge_user:="thelounge"}

export THELOUNGE_HOME=${thelounge_home}

command="/usr/sbin/daemon"
command_args="-f -p ${pidfile} /usr/local/bin/node /usr/local/bin/thelounge start"

thelounge_precmd() {
        if [ ! -e "${pidfile}" ]; then
                install -o "${thelounge_user}" -g "wheel" "/dev/null" "${pidfile}"
        fi
}

run_rc_command "$1"