Commit d254442b authored by Franco Fichtner's avatar Franco Fichtner

services: clean up several for #1256

(cherry picked from commit b74970ee)
parent 9a5d36ae
...@@ -277,10 +277,7 @@ function services_radvd_configure($blacklist = array()) ...@@ -277,10 +277,7 @@ function services_radvd_configure($blacklist = array())
$radvdconf .= "};\n"; $radvdconf .= "};\n";
} }
/* write radvd.conf */ @file_put_contents('/var/etc/radvd.conf', $radvdconf);
if (!@file_put_contents("/var/etc/radvd.conf", $radvdconf)) {
log_error('Cannot open radvd.conf in services_radvd_configure()');
}
if (count($radvdifs) > 0) { if (count($radvdifs) > 0) {
if (isvalidpid('/var/run/radvd.pid')) { if (isvalidpid('/var/run/radvd.pid')) {
...@@ -289,14 +286,8 @@ function services_radvd_configure($blacklist = array()) ...@@ -289,14 +286,8 @@ function services_radvd_configure($blacklist = array())
mwexec('/usr/local/sbin/radvd -p /var/run/radvd.pid -C /var/etc/radvd.conf -m syslog'); mwexec('/usr/local/sbin/radvd -p /var/run/radvd.pid -C /var/etc/radvd.conf -m syslog');
} }
} else { } else {
/* we need to shut down the radvd cleanly, it will send out the prefix killbypid('/var/run/radvd.pid', 'TERM', true);
* information with a lifetime of 0 to notify clients of a (possible) new prefix */
if (isvalidpid('/var/run/radvd.pid')) {
log_error("Shutting down Router Advertisment daemon cleanly");
killbypid('/var/run/radvd.pid');
}
} }
return 0;
} }
function services_dhcpd_leasesfile() function services_dhcpd_leasesfile()
...@@ -338,7 +329,7 @@ function services_dhcpleases_configure() ...@@ -338,7 +329,7 @@ function services_dhcpleases_configure()
} }
} }
function services_dhcpd_configure($family = 'all', $blacklist = array()) function services_dhcpd_configure($family = 'all', $blacklist = array(), $verbose = false)
{ {
global $g; global $g;
...@@ -355,11 +346,11 @@ function services_dhcpd_configure($family = 'all', $blacklist = array()) ...@@ -355,11 +346,11 @@ function services_dhcpd_configure($family = 'all', $blacklist = array())
mwexecf('/usr/sbin/chown -R dhcpd:dhcpd %s', $g['dhcpd_chroot_path']); mwexecf('/usr/sbin/chown -R dhcpd:dhcpd %s', $g['dhcpd_chroot_path']);
if ($family == 'all' || $family == 'inet') { if ($family == 'all' || $family == 'inet') {
services_dhcpdv4_configure(); services_dhcpdv4_configure($verbose);
} }
if ($family == 'all' || $family == 'inet6') { if ($family == 'all' || $family == 'inet6') {
services_dhcpdv6_configure($blacklist); services_dhcpdv6_configure($blacklist, $verbose);
services_radvd_configure($blacklist); services_radvd_configure($blacklist);
} }
} }
...@@ -381,19 +372,17 @@ function is_dhcpv4_server_enabled() ...@@ -381,19 +372,17 @@ function is_dhcpv4_server_enabled()
return false; return false;
} }
function services_dhcpdv4_configure() function services_dhcpdv4_configure($verbose = false)
{ {
global $config, $g; global $config, $g;
$need_ddns_updates = false; $need_ddns_updates = false;
$ddns_zones = array(); $ddns_zones = array();
/* kill any running dhcpd */ killbypid("{$g['dhcpd_chroot_path']}/var/run/dhcpd.pid", 'TERM', true);
killbypid("{$g['dhcpd_chroot_path']}/var/run/dhcpd.pid");
/* DHCP enabled on any interfaces? */
if (!is_dhcpv4_server_enabled()) { if (!is_dhcpv4_server_enabled()) {
return 0; return;
} }
/* Only consider DNS servers with IPv4 addresses for the IPv4 DHCP server. */ /* Only consider DNS servers with IPv4 addresses for the IPv4 DHCP server. */
...@@ -406,8 +395,9 @@ function services_dhcpdv4_configure() ...@@ -406,8 +395,9 @@ function services_dhcpdv4_configure()
} }
} }
if (file_exists("/var/run/booting")) { if ($verbose) {
echo gettext("Starting DHCP service..."); echo 'Starting DHCP service...';
flush();
} }
$custoptions = ""; $custoptions = "";
...@@ -919,19 +909,8 @@ EOD; ...@@ -919,19 +909,8 @@ EOD;
$dhcpdconf .= services_dhcpd_zones($ddns_zones); $dhcpdconf .= services_dhcpd_zones($ddns_zones);
} }
/* write dhcpd.conf */ @file_put_contents("{$g['dhcpd_chroot_path']}/etc/dhcpd.conf", $dhcpdconf);
if (!@file_put_contents("{$g['dhcpd_chroot_path']}/etc/dhcpd.conf", $dhcpdconf)) {
log_error('Cannot open dhcpd.conf in services_dhcpdv4_configure()');
unset($dhcpdconf);
return 1;
}
unset($dhcpdconf);
/* create an empty leases database */
@touch("{$g['dhcpd_chroot_path']}/var/db/dhcpd.leases"); @touch("{$g['dhcpd_chroot_path']}/var/db/dhcpd.leases");
/* make sure there isn't a stale dhcpd.pid file, which can make dhcpd fail to start. */
/* if we get here, dhcpd has been killed and is not started yet */
@unlink("{$g['dhcpd_chroot_path']}/var/run/dhcpd.pid"); @unlink("{$g['dhcpd_chroot_path']}/var/run/dhcpd.pid");
/* fire up dhcpd in a chroot */ /* fire up dhcpd in a chroot */
...@@ -939,11 +918,9 @@ EOD; ...@@ -939,11 +918,9 @@ EOD;
mwexec("/usr/local/sbin/dhcpd -user dhcpd -group dhcpd -chroot {$g['dhcpd_chroot_path']} -cf /etc/dhcpd.conf -pf /var/run/dhcpd.pid " . join(" ", $dhcpdifs)); mwexec("/usr/local/sbin/dhcpd -user dhcpd -group dhcpd -chroot {$g['dhcpd_chroot_path']} -cf /etc/dhcpd.conf -pf /var/run/dhcpd.pid " . join(" ", $dhcpdifs));
} }
if (file_exists("/var/run/booting")) { if ($verbose) {
print "done.\n"; print "done.\n";
} }
return 0;
} }
function services_dhcpd_zones($ddns_zones) function services_dhcpd_zones($ddns_zones)
...@@ -1027,17 +1004,15 @@ function is_dhcpv6_server_enabled() ...@@ -1027,17 +1004,15 @@ function is_dhcpv6_server_enabled()
return false; return false;
} }
function services_dhcpdv6_configure($blacklist = array()) function services_dhcpdv6_configure($blacklist = array(), $verbose = false)
{ {
global $config, $g; global $config, $g;
/* kill any running dhcpd */
killbypid("{$g['dhcpd_chroot_path']}/var/run/dhcpdv6.pid", 'TERM', true); killbypid("{$g['dhcpd_chroot_path']}/var/run/dhcpdv6.pid", 'TERM', true);
killbypid('/var/run/dhcpleases6.pid', 'TERM', true); killbypid('/var/run/dhcpleases6.pid', 'TERM', true);
/* DHCP enabled on any interfaces? */
if (!is_dhcpv6_server_enabled()) { if (!is_dhcpv6_server_enabled()) {
return 0; return;
} }
$syscfg = $config['system']; $syscfg = $config['system'];
...@@ -1047,10 +1022,9 @@ function services_dhcpdv6_configure($blacklist = array()) ...@@ -1047,10 +1022,9 @@ function services_dhcpdv6_configure($blacklist = array())
$dhcpdv6cfg = $config['dhcpdv6']; $dhcpdv6cfg = $config['dhcpdv6'];
$Iflist = get_configured_interface_list(); $Iflist = get_configured_interface_list();
if (file_exists("/var/run/booting")) { if ($verbose) {
echo "Starting DHCPv6 service..."; echo 'Starting DHCPv6 service...';
} else { flush();
sleep(1);
} }
/* we add a fake entry for interfaces that are set to track6 another WAN */ /* we add a fake entry for interfaces that are set to track6 another WAN */
...@@ -1323,21 +1297,8 @@ EOD; ...@@ -1323,21 +1297,8 @@ EOD;
$dhcpdv6conf .= "\nddns-update-style none;\n"; $dhcpdv6conf .= "\nddns-update-style none;\n";
} }
/* write dhcpdv6.conf */ @file_put_contents("{$g['dhcpd_chroot_path']}/etc/dhcpdv6.conf", $dhcpdv6conf);
if (!@file_put_contents("{$g['dhcpd_chroot_path']}/etc/dhcpdv6.conf", $dhcpdv6conf)) {
log_error("Cannot open {$g['dhcpd_chroot_path']}/etc/dhcpdv6.conf in services_dhcpdv6_configure()");
unset($dhcpdv6conf);
return 1;
}
unset($dhcpdv6conf);
/* create an empty leases v6 database */
if (!file_exists("{$g['dhcpd_chroot_path']}/var/db/dhcpd6.leases")) {
@touch("{$g['dhcpd_chroot_path']}/var/db/dhcpd6.leases"); @touch("{$g['dhcpd_chroot_path']}/var/db/dhcpd6.leases");
}
/* make sure there isn't a stale dhcpdv6.pid file, which may make dhcpdv6 fail to start. */
/* if we get here, dhcpdv6 has been killed and is not started yet */
@unlink("{$g['dhcpd_chroot_path']}/var/run/dhcpdv6.pid"); @unlink("{$g['dhcpd_chroot_path']}/var/run/dhcpdv6.pid");
/* fire up dhcpd in a chroot */ /* fire up dhcpd in a chroot */
...@@ -1346,11 +1307,10 @@ EOD; ...@@ -1346,11 +1307,10 @@ EOD;
join(" ", $dhcpdv6ifs)); join(" ", $dhcpdv6ifs));
mwexec("/usr/local/sbin/dhcpleases6 -c \"/usr/local/bin/php -f /usr/local/sbin/prefixes.php|/bin/sh\" -l {$g['dhcpd_chroot_path']}/var/db/dhcpd6.leases"); mwexec("/usr/local/sbin/dhcpleases6 -c \"/usr/local/bin/php -f /usr/local/sbin/prefixes.php|/bin/sh\" -l {$g['dhcpd_chroot_path']}/var/db/dhcpd6.leases");
} }
if (file_exists("/var/run/booting")) {
print gettext("done.") . "\n";
}
return 0; if ($verbose) {
echo "done.\n";
}
} }
function services_dhcrelay_configure($verbose = false) function services_dhcrelay_configure($verbose = false)
...@@ -1455,12 +1415,7 @@ function services_dhcrelay_configure($verbose = false) ...@@ -1455,12 +1415,7 @@ function services_dhcrelay_configure($verbose = false)
} }
$dhcrelayifs = array_unique($dhcrelayifs); $dhcrelayifs = array_unique($dhcrelayifs);
/* fire up dhcrelay */ if (!empty($dhcrelayifs)) {
if (empty($dhcrelayifs)) {
log_error("No suitable interface found for running dhcrelay!");
return;
}
$cmd = "/usr/local/sbin/dhcrelay -i " . implode(" -i ", $dhcrelayifs); $cmd = "/usr/local/sbin/dhcrelay -i " . implode(" -i ", $dhcrelayifs);
if (isset($dhcrelaycfg['agentoption'])) { if (isset($dhcrelaycfg['agentoption'])) {
...@@ -1469,7 +1424,7 @@ function services_dhcrelay_configure($verbose = false) ...@@ -1469,7 +1424,7 @@ function services_dhcrelay_configure($verbose = false)
$cmd .= " " . implode(" ", $srvips); $cmd .= " " . implode(" ", $srvips);
mwexec($cmd); mwexec($cmd);
unset($cmd); }
if ($verbose) { if ($verbose) {
echo "done\n"; echo "done\n";
...@@ -1574,12 +1529,7 @@ function services_dhcrelay6_configure($verbose = false) ...@@ -1574,12 +1529,7 @@ function services_dhcrelay6_configure($verbose = false)
} }
} }
/* fire up dhcrelay */ if (!empty($dhcrelayifs) && !empty($srvifaces)) {
if (empty($dhcrelayifs) || empty($srvifaces) ) {
log_error("No suitable interface found for running dhcrelay -6!");
return;
}
$cmd = '/usr/local/sbin/dhcrelay -6 -pf /var/run/dhcrelay6.pid'; $cmd = '/usr/local/sbin/dhcrelay -6 -pf /var/run/dhcrelay6.pid';
foreach ($dhcrelayifs as $dhcrelayif) { foreach ($dhcrelayifs as $dhcrelayif) {
$cmd .= " -l {$dhcrelayif}"; $cmd .= " -l {$dhcrelayif}";
...@@ -1588,7 +1538,7 @@ function services_dhcrelay6_configure($verbose = false) ...@@ -1588,7 +1538,7 @@ function services_dhcrelay6_configure($verbose = false)
$cmd .= " -u \"{$srviface}\""; $cmd .= " -u \"{$srviface}\"";
} }
mwexec($cmd); mwexec($cmd);
unset($cmd); }
if ($verbose) { if ($verbose) {
echo "done\n"; echo "done\n";
......
...@@ -184,7 +184,7 @@ services_dnsmasq_configure(true); ...@@ -184,7 +184,7 @@ services_dnsmasq_configure(true);
/* start unbound service */ /* start unbound service */
services_unbound_configure(true); services_unbound_configure(true);
services_dhcpd_configure(); services_dhcpd_configure('all', array(), true);
services_dhcpleases_configure(); services_dhcpleases_configure();
services_dhcrelay_configure(true); services_dhcrelay_configure(true);
services_dhcrelay6_configure(true); services_dhcrelay6_configure(true);
......
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