Commit 762fa53f authored by Franco Fichtner's avatar Franco Fichtner

inc: align service configure

o Add $waitforit flag to killbypid() and use it to simplify code.

o When requesting a configure via id, do not exclude the service
  because it is disabled.  The pidfile needs to be killed still.

o Unwind the convoluted code paths in the VPN plugin during early
  configure: kill service, probe for active, then do work.

(cherry picked from commit 2ddb95f7)
parent 909c271d
......@@ -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 */
......
......@@ -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;
......
......@@ -97,28 +97,20 @@ function vpn_pptpd_configure()
$syscfg = $config['system'];
$pptpdcfg = $config['pptpd'];
if (file_exists("/var/run/booting")) {
if (!$pptpdcfg['mode'] || ($pptpdcfg['mode'] == "off"))
return 0;
echo gettext("Configuring PPTP VPN service... ");
} else {
/* kill mpd */
killbypid('/var/run/pptp-vpn.pid');
killbypid('/var/run/pptp-vpn.pid', 'TERM', true);
/* wait for process to die */
sleep(3);
if (!isset($pptpdcfg['mode']) || $pptpdcfg['mode'] == 'off') {
return 0;
}
if (is_process_running("mpd -b")) {
killbypid('/var/run/pptp-vpn.pid');
log_error(gettext("Could not kill mpd within 3 seconds. Trying again."));
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.");
......@@ -307,8 +299,9 @@ EOD;
break;
}
if (file_exists("/var/run/booting"))
echo "done\n";
if (file_exists('/var/run/booting')) {
echo gettext("done") . "\n";
}
return 0;
}
......@@ -332,9 +325,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;
......@@ -355,27 +345,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")
......@@ -542,8 +528,6 @@ EOD;
chmod("/var/etc/pppoe{$pppoecfg['pppoeid']}-vpn/mpd.secret", 0600);
}
killbypid("/var/run/pppoe{$pppoecfg['pppoeid']}-vpn.pid");
pfSense_ngctl_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");
......@@ -551,8 +535,9 @@ EOD;
break;
}
if (file_exists("/var/run/booting"))
if (file_exists('/var/run/booting')) {
echo gettext("done") . "\n";
}
return 0;
}
......@@ -561,6 +546,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'];
......@@ -568,16 +555,12 @@ function vpn_l2tp_configure()
return 0;
}
if (file_exists("/var/run/booting")) {
if (!isset($l2tpcfg['mode']) || $l2tpcfg['mode'] == "off")
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');
......@@ -744,8 +727,9 @@ EOD;
break;
}
if (file_exists("/var/run/booting"))
echo "done\n";
if (file_exists('/var/run/booting')) {
echo gettext("done") . "\n";
}
return 0;
}
......@@ -1478,10 +1478,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'])) {
......
......@@ -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)
......
......@@ -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']);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment