#!/bin/sh
# $FreeBSD$

# PROVIDE: sysadm-rest
# REQUIRE: LOGIN cleanvar
# KEYWORD: shutdown

#
# Add the following lines to /etc/rc.conf to enable sysadm:
# sysadmr_rest_enable (bool):	Set to "NO" by default.
#				Set it to "YES" to enable sysadm

. /etc/rc.subr

name="sysadm_rest"
rcvar=sysadm_rest_enable

start_cmd="sysadm_rest_start"
stop_cmd="sysadm_rest_stop"
flags="-rest"

[ -z "$sysadm_rest_enable" ] && sysadm_rest_enable="NO"

load_rc_config $name

sysadm_rest_stop()
{
  if [ -e "/var/run/sysadm-rest.pid" ] ; then
    pkill -9 -F /var/run/sysadm-rest-daemon.pid >/dev/null 2>/dev/null
    pkill -9 -F /var/run/sysadm-rest.pid >/dev/null 2>/dev/null
  fi
}

sysadm_rest_start()
{
  export PATH="${PATH}:/usr/local/bin:/usr/local/sbin"
  sysadm_rest_stop
  echo "Starting sysadm (REST)..."
  command="/usr/local/bin/sysadm-server"
  daemon -r -P /var/run/sysadm-rest-daemon.pid -p /var/run/sysadm-rest.pid $command $flags
  chmod 744 /var/run/sysadm-rest.pid >/dev/null 2>/dev/null
}

run_rc_command "$1"
