diff --git a/src/etc/inc/ipsec.inc b/src/etc/inc/ipsec.inc index 50631a195..e60c9976b 100644 --- a/src/etc/inc/ipsec.inc +++ b/src/etc/inc/ipsec.inc @@ -489,7 +489,7 @@ function ipsec_configure() @mkdir('/usr/local/etc/ipsec.d/reqs'); if (file_exists("/var/run/booting")) { - echo gettext("Configuring IPsec VPN... "); + echo gettext("Configuring IPsec VPN..."); } /* fastforwarding is not compatible with ipsec tunnels */ diff --git a/src/etc/inc/openvpn.inc b/src/etc/inc/openvpn.inc index cf914a643..8613c89e8 100644 --- a/src/etc/inc/openvpn.inc +++ b/src/etc/inc/openvpn.inc @@ -815,9 +815,6 @@ function openvpn_restart_by_id($mode, $id) if (isset($config['openvpn']["openvpn-$mode"])) { foreach ($config['openvpn']["openvpn-$mode"] as $settings) { - if (isset($settings['disable'])) { - continue; - } if ($id != 0 && $id == $settings['vpnid']) { $found = $settings; break; @@ -839,12 +836,7 @@ function openvpn_restart($mode, $settings) $vpnid = $settings['vpnid']; $mode_id = $mode.$vpnid; - /* kill the process if running */ - $pfile = "/var/run/openvpn_{$mode_id}.pid"; - killbypid($pfile); - while (isvalidpid($pfile)) { - usleep(250000); - } + killbypid("/var/run/openvpn_{$mode_id}.pid", 'TERM', true); if (isset($settings['disable'])) { return; diff --git a/src/etc/inc/plugins.inc.d/vpn.inc b/src/etc/inc/plugins.inc.d/vpn.inc index b82fbdc67..95487f5a9 100644 --- a/src/etc/inc/plugins.inc.d/vpn.inc +++ b/src/etc/inc/plugins.inc.d/vpn.inc @@ -110,29 +110,21 @@ function vpn_pptpd_configure() $syscfg = $config['system']; $pptpdcfg = $config['pptpd']; - if (file_exists("/var/run/booting")) { - if (!$pptpdcfg['mode'] || ($pptpdcfg['mode'] == "off")) + killbypid('/var/run/pptp-vpn.pid', 'TERM', true); + + if (!isset($pptpdcfg['mode']) || $pptpdcfg['mode'] == 'off') { return 0; - - echo gettext("Configuring PPTP VPN service... "); - } else { - /* kill mpd */ - killbypid('/var/run/pptp-vpn.pid'); - - /* wait for process to die */ - sleep(3); - - if (is_process_running("mpd -b")) { - killbypid('/var/run/pptp-vpn.pid'); - log_error(gettext("Could not kill mpd within 3 seconds. Trying again.")); - } - - /* remove mpd.conf, if it exists */ - @unlink('/var/etc/pptp-vpn/mpd.conf'); - @unlink('/var/etc/pptp-vpn/mpd.links'); - @unlink('/var/etc/pptp-vpn/mpd.secret'); } + if (file_exists('/var/run/booting')) { + echo gettext("Configuring PPTP VPN service..."); + } + + /* remove mpd.conf, if it exists */ + @unlink('/var/etc/pptp-vpn/mpd.conf'); + @unlink('/var/etc/pptp-vpn/mpd.links'); + @unlink('/var/etc/pptp-vpn/mpd.secret'); + if (empty($pptpdcfg['n_pptp_units'])) { log_error("Something wrong in the PPTPd configuration. Preventing starting the daemon because issues would arise."); return; @@ -320,8 +312,9 @@ EOD; break; } - if (file_exists("/var/run/booting")) - echo "done\n"; + if (file_exists('/var/run/booting')) { + echo gettext("done") . "\n"; + } return 0; } @@ -345,9 +338,6 @@ function vpn_pppoe_configure_by_id($id) if (isset($config['pppoes']['pppoe'])) { foreach ($config['pppoes']['pppoe'] as $pppoe) { - if (!isset($pppoe['mode']) || $pppoe['mode'] == 'off') { - continue; - } if ($id != 0 && $id == $pppoe['pppoeid']) { $found = $pppoe; break; @@ -368,27 +358,23 @@ function vpn_pppoe_configure(&$pppoecfg) $syscfg = $config['system']; - /* create directory if it does not exist */ - @mkdir("/var/etc/pppoe{$pppoecfg['pppoeid']}-vpn"); + killbypid("/var/run/pppoe{$pppoecfg['pppoeid']}-vpn.pid", 'TERM', true); - if (file_exists("/var/run/booting")) { - if (!$pppoecfg['mode'] || ($pppoecfg['mode'] == "off")) + if (!isset($pppoecfg['mode']) || $pppoecfg['mode'] == 'off') { return 0; + } - echo gettext("Configuring PPPoE VPN service... "); - } else { - /* kill mpd */ - killbypid("/var/run/pppoe{$pppoecfg['pppoeid']}-vpn.pid"); - - /* wait for process to die */ - sleep(2); - + if (file_exists('/var/run/booting')) { + echo gettext("Configuring PPPoE VPN service..."); } switch ($pppoecfg['mode']) { case 'server' : + /* create directory if it does not exist */ + @mkdir("/var/etc/pppoe{$pppoecfg['pppoeid']}-vpn"); + $pppoe_interface = get_real_interface($pppoecfg['interface']); if ($pppoecfg['paporchap'] == "chap") @@ -555,8 +541,6 @@ EOD; chmod("/var/etc/pppoe{$pppoecfg['pppoeid']}-vpn/mpd.secret", 0600); } - killbypid("/var/run/pppoe{$pppoecfg['pppoeid']}-vpn.pid"); - legacy_netgraph_attach($pppoe_interface); mwexec("/usr/local/sbin/mpd4 -b -d /var/etc/pppoe{$pppoecfg['pppoeid']}-vpn -p /var/run/pppoe{$pppoecfg['pppoeid']}-vpn.pid -s poes poes"); @@ -564,8 +548,9 @@ EOD; break; } - if (file_exists("/var/run/booting")) + if (file_exists('/var/run/booting')) { echo gettext("done") . "\n"; + } return 0; } @@ -574,6 +559,8 @@ function vpn_l2tp_configure() { global $config; + killbypid('/var/run/l2tp-vpn.pid', 'TERM', true); + $syscfg = $config['system']; if (isset($config['l2tp'])) { $l2tpcfg = $config['l2tp']; @@ -581,16 +568,12 @@ function vpn_l2tp_configure() return 0; } - if (file_exists("/var/run/booting")) { - if (!isset($l2tpcfg['mode']) || $l2tpcfg['mode'] == "off") - return 0; + if (!isset($l2tpcfg['mode']) || $l2tpcfg['mode'] == 'off') { + return 0; + } - echo gettext("Configuring l2tp VPN service... "); - } else { - while (isvalidpid('/var/run/l2tp-vpn.pid')) { - killbypid('/var/run/l2tp-vpn.pid'); - usleep(250 * 1000); - } + if (file_exists('/var/run/booting')) { + echo gettext('Configuring L2TP VPN service...'); } @mkdir('/var/etc/l2tp-vpn'); @@ -757,8 +740,9 @@ EOD; break; } - if (file_exists("/var/run/booting")) - echo "done\n"; + if (file_exists('/var/run/booting')) { + echo gettext("done") . "\n"; + } return 0; } diff --git a/src/etc/inc/system.inc b/src/etc/inc/system.inc index be1860df3..bd45362be 100644 --- a/src/etc/inc/system.inc +++ b/src/etc/inc/system.inc @@ -1474,10 +1474,8 @@ function system_ntp_configure($start_ntpd = true) { global $config; - /* if ntpd is running, kill it when restart is not delayed */ - while ($start_ntpd && isvalidpid('/var/run/ntpd.pid')) { - killbypid('/var/run/ntpd.pid'); - usleep(200 * 1000); + if ($start_ntpd) { + killbypid('/var/run/ntpd.pid', 'TERM', true); } if (!isset($config['system']['timeservers'])) { diff --git a/src/etc/inc/util.inc b/src/etc/inc/util.inc index edb03b572..ed2790b8e 100644 --- a/src/etc/inc/util.inc +++ b/src/etc/inc/util.inc @@ -37,13 +37,21 @@ function killbyname($procname, $sig = 'TERM') mwexecf('/bin/pkill -%s %s', array($sig, $procname)); } -function killbypid($pidfile, $sig = 'TERM') +function killbypid($pidfile, $sig = 'TERM', $waitforit = false) { if (!isvalidpid($pidfile)) { return; } mwexecf('/bin/pkill -%s -F %s', array($sig, $pidfile)); + + if (!$waitforit) { + return; + } + + while (isvalidpid($pidfile)) { + usleep(200 * 1000); + } } function isvalidpid($pidfile) diff --git a/src/www/status_services.php b/src/www/status_services.php index a8873cebb..464bc9bc7 100644 --- a/src/www/status_services.php +++ b/src/www/status_services.php @@ -129,7 +129,7 @@ function service_control_stop($name, $extras) mwexec($cmd); } } elseif (isset($service['pidfile'])) { - killbypid($service['pidfile']); + killbypid($service['pidfile'], 'TERM', true); } else { /* last resort, but not very elegant */ killbyname($service['name']);