Commit 050331cb authored by Franco Fichtner's avatar Franco Fichtner

services: restructure restart, work in progress

(cherry picked from commit 9784c8b0)
parent 29b4cb46
......@@ -2518,6 +2518,7 @@ function services_get()
$pconfig = array();
$pconfig['name'] = "radvd";
$pconfig['description'] = gettext("Router Advertisement Daemon");
$pconfig['php']['restart'] = array('services_radvd_configure');
$pconfig['php']['start'] = array('services_radvd_configure');
$pconfig['pidfile'] = '/var/run/radvd.pid';
$services[] = $pconfig;
......@@ -2527,6 +2528,7 @@ function services_get()
$pconfig = array();
$pconfig['name'] = "dnsmasq";
$pconfig['description'] = gettext("DNS Forwarder");
$pconfig['php']['restart'] = array('services_dnsmasq_configure');
$pconfig['php']['start'] = array('services_dnsmasq_configure');
$pconfig['pidfile'] = '/var/run/dnsmasq.pid';
$services[] = $pconfig;
......@@ -2536,6 +2538,7 @@ function services_get()
$pconfig = array();
$pconfig['name'] = "unbound";
$pconfig['description'] = gettext("Unbound DNS Resolver");
$pconfig['php']['restart'] = array('services_unbound_configure');
$pconfig['php']['start'] = array('services_unbound_configure');
$pconfig['pidfile'] = '/var/run/unbound.pid';
$services[] = $pconfig;
......@@ -2544,6 +2547,7 @@ function services_get()
$pconfig = array();
$pconfig['name'] = "ntpd";
$pconfig['description'] = gettext("NTP clock sync");
$pconfig['php']['restart'] = array('system_ntp_configure');
$pconfig['php']['start'] = array('system_ntp_configure');
$pconfig['pidfile'] = '/var/run/ntpd.pid';
$services[] = $pconfig;
......@@ -2561,6 +2565,7 @@ function services_get()
$pconfig = array();
$pconfig['name'] = "dhcrelay";
$pconfig['description'] = gettext("DHCP Relay");
$pconfig['php']['restart'] = array('services_dhcrelay_configure');
$pconfig['php']['start'] = array('services_dhcrelay_configure');
$pconfig['pidfile'] = '/var/run/dhcrelay.pid';
$services[] = $pconfig;
......@@ -2570,6 +2575,7 @@ function services_get()
$pconfig = array();
$pconfig['name'] = "dhcrelay6";
$pconfig['description'] = gettext("DHCPv6 Relay");
$pconfig['php']['restart'] = array('services_dhcrelay6_configure');
$pconfig['php']['start'] = array('services_dhcrelay6_configure');
$pconfig['pidfile'] = '/var/run/dhcrelay6.pid';
$services[] = $pconfig;
......@@ -2579,6 +2585,7 @@ function services_get()
$pconfig = array();
$pconfig['name'] = "dhcpd";
$pconfig['description'] = gettext("DHCP Service");
$pconfig['php']['restart'] = array('services_dhcpd_configure');
$pconfig['php']['start'] = array('services_dhcpd_configure');
$pconfig['pidfile'] = "{$g['dhcpd_chroot_path']}/var/run/dhcpd.pid";
$services[] = $pconfig;
......@@ -2597,6 +2604,7 @@ function services_get()
$pconfig = array();
$pconfig['name'] = "bsnmpd";
$pconfig['description'] = gettext("SNMP Service");
$pconfig['php']['restart'] = array('services_snmpd_configure');
$pconfig['php']['start'] = array('services_snmpd_configure');
$pconfig['pidfile'] = '/var/run/snmpd.pid';
$services[] = $pconfig;
......@@ -2606,6 +2614,7 @@ function services_get()
$pconfig = array();
$pconfig['name'] = "igmpproxy";
$pconfig['description'] = gettext("IGMP proxy");
$pconfig['php']['restart'] = array('services_igmpproxy_configure');
$pconfig['php']['start'] = array('services_igmpproxy_configure');
$services[] = $pconfig;
}
......@@ -2627,6 +2636,7 @@ function services_get()
$pconfig['name'] = "ipsec";
$pconfig['description'] = gettext("IPsec VPN");
$pconfig['pidfile'] = '/var/run/charon.pid';
$pconfig['php']['restart'] = array('vpn_ipsec_force_reload');
$pconfig['php']['start'] = array('vpn_ipsec_force_reload');
$pconfig['mwexec']['stop'] = array('/usr/local/sbin/ipsec stop');
$services[] = $pconfig;
......@@ -2636,6 +2646,7 @@ function services_get()
$pconfig = array();
$pconfig['name'] = 'sshd';
$pconfig['description'] = gettext('Secure Shell Daemon');
$pconfig['configd']['restart'] = array('sshd restart');
$pconfig['configd']['start'] = array('sshd restart');
$services[] = $pconfig;
}
......@@ -2669,6 +2680,7 @@ function services_get()
$services[] = array(
'description' => gettext('Proxy server'),
'configd' => array(
'restart' => array('proxy restart'),
'start' => array('proxy start'),
'stop' => array('proxy stop'),
),
......@@ -2680,6 +2692,7 @@ function services_get()
$services[] = array(
'description' => gettext('Intrusion Detection'),
'configd' => array(
'restart' => array('ids restart'),
'start' => array('ids start'),
'stop' => array('ids stop'),
),
......@@ -2705,6 +2718,7 @@ function services_get()
'pidfile' => '/var/run/lighttpd-api-dispatcher.pid',
'description' => gettext('Captive Portal'),
'confidg' => array(
'restart' => array('captiveportal restart'),
'start' => array('captiveportal start'),
'stop' => array('captiveportal stop'),
),
......@@ -2717,7 +2731,9 @@ function services_get()
'description' => gettext('System Configuration Daemon'),
'pidfile' => '/var/run/configd.pid',
'mwexec' => array(
'restart' => array('/usr/local/etc/rc.d/configd restart'),
'start' => array('/usr/local/etc/rc.d/configd start'),
'stop' => array('/usr/local/etc/rc.d/configd stop'),
),
'name' => 'configd',
);
......
......@@ -104,7 +104,7 @@ function service_control_start($name, $extras)
mwexec($cmd);
}
} else {
$msg = sprintf(gettext("Could not launch service `%s'"), htmlspecialchars($name));
$msg = sprintf(gettext("Could not start service `%s'"), htmlspecialchars($name));
}
return $msg;
......@@ -148,49 +148,16 @@ function service_control_stop($name, $extras)
}
function service_control_restart($name, $extras) {
function service_control_restart($name, $extras)
{
$msg = sprintf(gettext("%s has been restarted."), htmlspecialchars($name));
/* XXX clean this up */
switch($name) {
case 'radvd':
services_radvd_configure();
break;
case 'ntpd':
system_ntp_configure();
break;
case 'apinger':
killbypid("/var/run/apinger.pid");
setup_gateways_monitor();
break;
case 'bsnmpd':
services_snmpd_configure();
break;
case 'dhcrelay':
services_dhcrelay_configure();
break;
case 'dhcrelay6':
services_dhcrelay6_configure();
break;
case 'dnsmasq':
services_dnsmasq_configure();
break;
case 'unbound':
services_unbound_configure();
break;
case 'dhcpd':
services_dhcpd_configure();
break;
case 'igmpproxy':
services_igmpproxy_configure();
break;
case 'miniupnpd':
upnp_stop();
upnp_start();
break;
case 'ipsec':
vpn_ipsec_force_reload();
break;
case 'sshd':
configd_run("sshd restart");
break;
return $msg;
case 'openvpn':
$vpnmode = htmlspecialchars($extras['vpnmode']);
if ($vpnmode == "server" || $vpnmode == "client") {
......@@ -200,28 +167,37 @@ function service_control_restart($name, $extras) {
openvpn_restart_by_vpnid($vpnmode, $id);
}
}
break;
return $msg;
case 'relayd':
relayd_configure(true);
filter_configure();
break;
case 'squid':
configd_run("proxy restart");
break;
case 'suricata':
configd_run("ids restart");
break;
case 'configd':
mwexec('/usr/local/etc/rc.d/configd restart');
break;
case 'captiveportal':
configd_run("captiveportal restart");
break;
return $msg;
default:
log_error(sprintf(gettext("Could not restart unknown service `%s'"), $name));
break;
}
return sprintf(gettext("%s has been restarted."),htmlspecialchars($name));
$service = find_service_by_name($name);
if (!isset($service['name'])) {
return sprintf(gettext("Could not restart unknown service `%s'"), htmlspecialchars($name));
}
if (isset($service['configd']['restart'])) {
foreach ($service['configd']['restart'] as $cmd) {
configd_run($cmd);
}
} elseif (isset($service['php']['restart'])) {
foreach ($service['php']['restart'] as $cmd) {
$cmd();
}
} elseif (isset($service['mwexec']['restart'])) {
foreach ($service['mwexec']['restart'] as $cmd) {
mwexec($cmd);
}
} else {
$msg = sprintf(gettext("Could not restart service `%s'"), htmlspecialchars($name));
}
return $msg;
}
$services = services_get();
......
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