mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-14 00:24:40 +00:00
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.
This commit is contained in:
parent
6a6f7f3ba4
commit
2ddb95f7f8
@ -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;
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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'])) {
|
||||
|
||||
@ -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']);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user