#!/bin/sh

# PROVIDE: hoptodesk
# REQUIRE: DAEMON NETWORKING
# KEYWORD: shutdown

. /etc/rc.subr

name=hoptodesk
rcvar=hoptodesk_enable

load_rc_config $name

: ${hoptodesk_enable:="NO"}

command="/usr/local/bin/hoptodesk"
command_args="--service"
pidfile="/var/run/${name}.pid"

start_cmd="hoptodesk_start"
stop_cmd="hoptodesk_stop"
status_cmd="hoptodesk_status"

hoptodesk_start()
{
    echo "Starting ${name}."
    /usr/sbin/daemon -p ${pidfile} -f ${command} ${command_args}
}

hoptodesk_stop()
{
    if [ -f ${pidfile} ]; then
        echo "Stopping ${name}."
        kill $(cat ${pidfile}) 2>/dev/null
        rm -f ${pidfile}
    else
        echo "${name} is not running."
    fi
}

hoptodesk_status()
{
    if [ -f ${pidfile} ] && kill -0 $(cat ${pidfile}) 2>/dev/null; then
        echo "${name} is running as pid $(cat ${pidfile})."
    else
        echo "${name} is not running."
        return 1
    fi
}

run_rc_command "$1"
