From 8596af32d3bf099dce8df344c90b8a525598f00f Mon Sep 17 00:00:00 2001 From: Renato Botelho Date: Tue, 30 Apr 2013 18:29:19 -0300 Subject: Fix unbound_monitor.sh (Ticket #2817) . Use a PID file to keep track if it's running or not . Move it to /usr/local/bin, it doesn't need to be started by rc.start_packages since it's already called by unbound.inc . Define PATH and remove complete path for all binaries . Remove unbound initscript symlink created when it's installed by a PBI package . Bump unbound to 1.4.20_5 --- config/unbound/unbound.inc | 7 ++++--- config/unbound/unbound.xml | 4 ++-- config/unbound/unbound_monitor.sh | 27 +++++++++++++++++++++------ pkg_config.8.xml | 2 +- pkg_config.8.xml.amd64 | 2 +- 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/config/unbound/unbound.inc b/config/unbound/unbound.inc index 3287b194..c5cbfc49 100644 --- a/config/unbound/unbound.inc +++ b/config/unbound/unbound.inc @@ -70,6 +70,7 @@ function unbound_initial_setup() { // We do not need the sample conf or the default rc.d startup file @unlink_if_exists(UNBOUND_BASE . "/etc/unbound/unbound.conf.sample"); @unlink_if_exists(UNBOUND_BASE . "/etc/rc.d/unbound"); + @unlink_if_exists("/usr/local/etc/rc.d/unbound"); // Setup rc file for startup and shutdown. unbound_rc_setup(); @@ -205,7 +206,7 @@ function unbound_control($action) { @unlink("/var/run/dnsmasq.pid"); mwexec("/bin/ln -s /var/run/unbound.pid /var/run/dnsmasq.pid"); } - mwexec_bg("/usr/local/etc/rc.d/unbound_monitor.sh start"); + mwexec_bg("/usr/local/bin/unbound_monitor.sh"); fetch_root_hints(); } break; @@ -213,14 +214,14 @@ function unbound_control($action) { case "stop": //Stop unbound and unmount the file system if($unbound_config['unbound_status'] == "on") { - mwexec_bg("/usr/local/etc/rc.d/unbound_monitor.sh stop"); + mwexec_bg("/usr/local/bin/unbound_monitor.sh stop"); unbound_ctl_exec("stop"); } break; case "termstop": //Stop Unbound by sigkillbypid(); - mwexec_bg("/usr/local/etc/rc.d/unbound_monitor.sh stop"); + mwexec_bg("/usr/local/bin/unbound_monitor.sh stop"); sigkillbypid("{$g['varrun_path']}/unbound.pid", "TERM"); break; diff --git a/config/unbound/unbound.xml b/config/unbound/unbound.xml index 36c005a4..10de1f97 100644 --- a/config/unbound/unbound.xml +++ b/config/unbound/unbound.xml @@ -40,7 +40,7 @@ unbound - 1.4.20_4 + 1.4.20_5 Services: Unbound DNS Forwarder: Basic Settings /usr/local/pkg/unbound.inc @@ -76,7 +76,7 @@ http://www.pfsense.org/packages/config/unbound/unbound_advanced.xml - /usr/local/etc/rc.d/ + /usr/local/bin/ 0755 http://www.pfsense.org/packages/config/unbound/unbound_monitor.sh diff --git a/config/unbound/unbound_monitor.sh b/config/unbound/unbound_monitor.sh index 042866be..c277bbaa 100755 --- a/config/unbound/unbound_monitor.sh +++ b/config/unbound/unbound_monitor.sh @@ -27,33 +27,48 @@ # POSSIBILITY OF SUCH DAMAGE. # +export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin + set -e LOOP_SLEEP=5 +PIDFILE=/var/run/unbound_monitor.pid if [ -f /var/run/unbound_alarm ]; then rm /var/run/unbound_alarm fi +PID="" +if [ -f "${PIDFILE}" ]; then + PID=`head -n 1 ${PIDFILE}` +fi if [ "$1" = "stop" ]; then - pkill -f unbound_monitor.sh + if [ -n "${PID}" ] && ps -p ${PID} | grep -q unbound_monitor.sh; then + kill ${PID} + else + pkill -f unbound_monitor.sh + fi exit 0 fi -PROCS=`/bin/pgrep -f unbound_monitor.sh | wc -l | awk '{print $1}'` - -if [ ${PROCS} -gt 1 ]; then +if [ -n "${PID}" ] && ps -p ${PID} | grep -q unbound_monitor.sh; then echo "There are another unbound monitor proccess running" exit 0 fi +echo $$ > ${PIDFILE} + # Sleep 5 seconds on startup not to mangle with existing boot scripts. sleep 5 while true; do + if [ ! -f "${PIDFILE}" ]; then + echo $$ > ${PIDFILE} + fi + if [ ! -f /var/run/unbound_alarm ]; then - NUM_PROCS=`/bin/pgrep unbound | wc -l | awk '{print $1}'` + NUM_PROCS=`pgrep unbound | wc -l | awk '{print $1}'` if [ $NUM_PROCS -lt 1 ]; then # Unbound is not running echo "Unbound has exited." | logger -p daemon.info -i -t Unbound_Alarm @@ -63,7 +78,7 @@ while true; do touch /var/run/unbound_alarm fi fi - NUM_PROCS=`/bin/pgrep unbound | wc -l | awk '{print $1}'` + NUM_PROCS=`pgrep unbound | wc -l | awk '{print $1}'` if [ $NUM_PROCS -gt 0 ]; then if [ -f /var/run/unbound_alarm ]; then echo "Unbound has resumed." | logger -p daemon.info -i -t Unbound_Alarm diff --git a/pkg_config.8.xml b/pkg_config.8.xml index 40d6e119..72e6ba73 100644 --- a/pkg_config.8.xml +++ b/pkg_config.8.xml @@ -1533,7 +1533,7 @@ Unbound is a validating, recursive, and caching DNS resolver. This package is a drop in replacement for Services: DNS Forwarder and also supports DNSSEC extensions. Once installed please configure the Unbound service by visiting Services: Unbound DNS. http://www.unbound.net/ Services - 1.4.20_4 + 1.4.20_5 Alpha warren@decoy.co.za 2.0 diff --git a/pkg_config.8.xml.amd64 b/pkg_config.8.xml.amd64 index c2958e5d..7217deb4 100644 --- a/pkg_config.8.xml.amd64 +++ b/pkg_config.8.xml.amd64 @@ -1520,7 +1520,7 @@ Unbound is a validating, recursive, and caching DNS resolver. This package is a drop in replacement for Services: DNS Forwarder and also supports DNSSEC extensions. Once installed please configure the Unbound service by visiting Services: Unbound DNS. http://www.unbound.net/ Services - 1.4.20_4 + 1.4.20_5 Alpha warren@decoy.co.za 2.0 -- cgit v1.2.3