From db3b3afb055c5a9f7f53b45984e585fcbeff1cb5 Mon Sep 17 00:00:00 2001 From: jim-p Date: Fri, 14 Jul 2017 14:46:57 -0400 Subject: Use an alternate method to stop unbound and fix #7326 (cherry picked from commit 782453b4dbb77e5bc97a43f56b95a006c5434d65) (cherry picked from commit 67fea036201f5af338338f6113033574ec25777e) --- src/etc/inc/services.inc | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/etc/inc/services.inc b/src/etc/inc/services.inc index 8081e81..94e1ad8 100644 --- a/src/etc/inc/services.inc +++ b/src/etc/inc/services.inc @@ -2289,12 +2289,21 @@ function services_unbound_configure($restart_dhcp = true) { echo "services_unbound_configure() being called $mt\n"; } - // kill any running Unbound instance - if (file_exists("{$g['varrun_path']}/unbound.pid")) { - sigkillbypid("{$g['varrun_path']}/unbound.pid", "TERM"); - } - if (isset($config['unbound']['enable'])) { + require_once('/etc/inc/unbound.inc'); + + /* Stop Unbound using TERM */ + if (file_exists("{$g['varrun_path']}/unbound.pid")) { + sigkillbypid("{$g['varrun_path']}/unbound.pid", "TERM"); + } + + /* If unbound is still running, wait up to 30 seconds for it to terminate. */ + for ($i=1; $i <= 30; $i++) { + if (is_process_running('unbound')) { + sleep(1); + } + } + if (platform_booting()) { echo gettext("Starting DNS Resolver..."); } else { @@ -2306,13 +2315,17 @@ function services_unbound_configure($restart_dhcp = true) { $return = 1; } - require_once('/etc/inc/unbound.inc'); sync_unbound_service(); if (platform_booting()) { echo gettext("done.") . "\n"; } system_dhcpleases_configure(); + } else { + /* kill Unbound since it should not be enabled */ + if (file_exists("{$g['varrun_path']}/unbound.pid")) { + sigkillbypid("{$g['varrun_path']}/unbound.pid", "KILL"); + } } if (!platform_booting() && $restart_dhcp) { -- cgit v1.1