From 5fe738d662ebedd19fb0c8a03a6dac98b0065efc Mon Sep 17 00:00:00 2001 From: llsth Date: Sun, 3 Apr 2016 12:43:04 +0200 Subject: [PATCH] Scripts for native execution --- INSTALL | 2 +- script/ntpa | 81 +------------------------------------------------ script/ntpa.rc | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++ script/ntpac | 3 ++ script/ntpav | 3 ++ 5 files changed, 90 insertions(+), 81 deletions(-) mode change 100644 => 100755 script/ntpa create mode 100755 script/ntpa.rc create mode 100755 script/ntpac create mode 100755 script/ntpav diff --git a/INSTALL b/INSTALL index 20cb6955..6dfe3f8d 100644 --- a/INSTALL +++ b/INSTALL @@ -38,7 +38,7 @@ suitable location and copy ntpa.stat.conf from example to On FreeBSD copy content of bin to /usr/local/ntpa/ Copy example/ntpa.stat.conf to /usr/local/etc/ntpa/ntpa.conf -Copy script/ntpa to /usr/local/etc/rc.d/ntpa +Copy script/ntpa.rc to /usr/local/etc/rc.d/ntpa Touch /var/log/ntpa.log and adjust pid file location if needed. diff --git a/script/ntpa b/script/ntpa old mode 100644 new mode 100755 index fe5cde26..5d92c57a --- a/script/ntpa +++ b/script/ntpa @@ -1,82 +1,3 @@ #!/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. -# -# Run additional instances of ntpa with: -# Use ln -s ntpa ntpa_graph -# -. /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" - -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}." - cd /usr/local/ntpa/ - ${MONO} ntpa.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/\"}" - -config="$(eval echo \${${name}_config})" -tempdir="$(eval echo \${${name}_tempdir})" - -pidfile="/var/run/${name}.pid" - -run_rc_command "$1" +exec mono "/usr/local/ntpa/ntpa.exe" "$@" diff --git a/script/ntpa.rc b/script/ntpa.rc new file mode 100755 index 00000000..fe5cde26 --- /dev/null +++ b/script/ntpa.rc @@ -0,0 +1,82 @@ +#!/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. +# +# Run additional instances of ntpa with: +# Use ln -s ntpa ntpa_graph +# + +. /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" + +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}." + cd /usr/local/ntpa/ + ${MONO} ntpa.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/\"}" + +config="$(eval echo \${${name}_config})" +tempdir="$(eval echo \${${name}_tempdir})" + +pidfile="/var/run/${name}.pid" + +run_rc_command "$1" diff --git a/script/ntpac b/script/ntpac new file mode 100755 index 00000000..928fbf4d --- /dev/null +++ b/script/ntpac @@ -0,0 +1,3 @@ +#!/bin/sh + +exec mono "/usr/local/ntpa/ntpac.exe" "$@" diff --git a/script/ntpav b/script/ntpav new file mode 100755 index 00000000..8a8a709a --- /dev/null +++ b/script/ntpav @@ -0,0 +1,3 @@ +#!/bin/sh + +exec mono "/usr/local/ntpa/ntpav.exe" "$@"