#!/bin/sh
#
# SNFServer	This shell script takes care of starting and stopping
#		the ARM Research SNFServer daemon for FreeBSD systems.
#
# Author--  Alban Deniz
#
# Copyright (C) 2008 ARM Research Labs, LLC.
# See www.armresearch.com for the copyright terms.
#

# PROVIDE: SNFServer
# REQUIRE: FILESYSTEMS
# KEYWORD: shutdown

. /etc/rc.subr

# Location of programs.
installedDir="PREFIX"

# Location of programs.
dir="$installedDir/sbin"

# Name of config file.
configFile="CONFFILE"

# Name of daemon.
prog="SNFServer"

# Name of client.
clientProg="SNFClient"

name="snfserver"
rcvar=`set_rcvar`
command=$dir/$prog
command_args="$configFile > /dev/null 2>&1 &"
required_dirs=$dir
required_files="$dir/$prog $dir/$clientProg $configFile"
snf_user=snfilter
snf_group=snfilter

start_postcmd="${name}_poststart"

snfserver_poststart()
{
    $dir/$clientProg -status.second > /dev/null 2>&1
    return $?
}

stop_cmd="${name}_stop"
snfserver_stop()
{
    echo "Stopping $name."
    $dir/$clientProg -shutdown > /dev/null 2>&1
    sleep 10
}

stop_postcmd="${name}_poststop"

snfserver_poststop()
{
    SNFPID=$(check_process $dir/$prog)
    if [ -n "$SNFPID" ]; then
	kill $SNFPID
	RETVAL=$?
    else
	RETVAL=0
    fi
    return $RETVAL
}

load_rc_config $name
run_rc_command "$1"
