Files
ntpa/script/ntpa.rc
T
2016-04-16 14:19:42 +02:00

86 lines
1.8 KiB
Bash
Executable File

#!/bin/sh
#
# $FreeBSD
#
# PROVIDE: ntpa
# REQUIRE: networking
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable ntpa:
# ntpa_enable (bool): Set to "NO" by default.
# Set it to "YES" to enable ntpa
# ntpa_config (file): Set to "/usr/local/etc/ntpa/ntpa.conf" by default.
# ntpa_tempdir (path): Set to "/tmp/" by default.
# ntpa_user (use): Set to "ntpa" by default.
#
# Run additional instances of ntpa with:
# ln -s ntpa ntpa_name
#
. /etc/rc.subr
name="$0"
name="${name##*/}"
rcvar=${name}_enable
start_cmd="ntpa_start"
stop_cmd="ntpa_stop"
reload_cmd="ntpa_reload"
extra_commands="reload"
load_rc_config ${name}
MONO="/usr/local/bin/mono"
EXE="/usr/local/ntpa/ntpa.exe"
ntpa_start()
{
if [ -f ${pidfile} ]; then
rc_pid=`cat ${pidfile}`
echo 1>&2 "${name} already running? (pid=$rc_pid)."
return 1
else
echo "Starting ${name}."
su -m ${ntpauser} -c "sh -c '${MONO} ${EXE} --config ${config} --writepid ${pidfile} --temp ${tempdir} --daemon ${name} &'"
fi
}
ntpa_reload()
{
if [ ! -f ${pidfile} ]; then
_run_rc_notrunning
return 1
else
echo "Reloading ${name}."
rc_pid=`cat ${pidfile}`
kill -USR1 $rc_pid
fi
}
ntpa_stop()
{
if [ ! -f ${pidfile} ]; then
_run_rc_notrunning
return 1
else
echo "Stopping ${name}."
rc_pid=`cat ${pidfile}`
kill -TERM $rc_pid
wait_for_pids ${rc_pid}
fi
}
eval ": \${${name}_enable:=\"NO\"}"
eval ": \${${name}_config:=\"/usr/local/etc/ntpa/${name}.conf\"}"
eval ": \${${name}_tempdir:=\"/tmp/\"}"
eval ": \${${name}_user:=\"ntpa\"}"
config="$(eval echo \${${name}_config})"
tempdir="$(eval echo \${${name}_tempdir})"
ntpauser="$(eval echo \${${name}_user})"
pidfile="/var/run/ntpa/${name}.pid"
run_rc_command "$1"