#!/bin/sh
# $FreeBSD$

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

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

. /etc/rc.subr

name="sysadm"
rcvar=sysadm_enable

start_cmd="sysadm_start"
stop_cmd="sysadm_stop"
flags=""

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

load_rc_config $name

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

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

run_rc_command "$1"
