#!/bin/sh
#
# Xymon site monitoring server
# Startup script contributed by Nathan Arthur (originally for hobbitmon)
#
# PROVIDE: xymon
# REQUIRE: DAEMON xymonclient

name="xymon"

# user-settable rc.conf variables
: ${xymon_launchcfg:="/usr/pkg/etc/xymon/tasks.cfg"}
: ${xymon_servercfg:="/usr/pkg/etc/xymon/xymonserver.cfg"}
: ${xymon_log:="/var/log/xymon/xymonlaunch.log"}
: ${xymon_pidfile:="/var/run/${name}.pid"}

if [ -f /etc/rc.subr ]; then
	. /etc/rc.subr
fi

rcvar=${name}
xymon_user="xymon"
pidfile=${xymon_pidfile}
required_files="${xymon_launchcfg} ${xymon_servercfg}"
command="/usr/pkg/libexec/xymon/xymonlaunch"
command_args="--config=${xymon_launchcfg} --env=${xymon_servercfg} --log=${xymon_log} --pidfile=${xymon_pidfile}"

xymon_precmd()
{
	XYMONHOME="/usr/pkg/share/xymon/xymonhome"
        export XYMONHOME
	XYMONCLIENTHOME="/usr/pkg/share/xymon/xymonhome/client"
        export XYMONCLIENTHOME

	touch ${xymon_pidfile} && chown ${xymon_user} ${xymon_pidfile}
}

start_precmd="xymon_precmd"

load_rc_config $name
run_rc_command "$1"
