Commit f759d902 authored by Ad Schellevis's avatar Ad Schellevis

move legacy service start/stop/restart to services.inc

parent 15b8b918
......@@ -2934,3 +2934,114 @@ function is_radvd_enabled() {
return false;
}
function service_control_start($name, $extras)
{
$msg = sprintf(gettext('%s has been started.'), htmlspecialchars($name));
if (!empty($extras['id'])) {
$filter['id'] = $extras['id'];
}
$service = find_service_by_name($name, $filter);
if (!isset($service['name'])) {
return sprintf(gettext("Could not start unknown service `%s'"), htmlspecialchars($name));
}
if (isset($service['configd']['start'])) {
foreach ($service['configd']['start'] as $cmd) {
configd_run($cmd);
}
} elseif (isset($service['php']['start'])) {
foreach ($service['php']['start'] as $cmd) {
$params = array();
if (isset($service['php']['args'])) {
foreach ($service['php']['args'] as $param) {
$params[] = $service[$param];
}
}
call_user_func_array($cmd, $params);
}
} elseif (isset($service['mwexec']['start'])) {
foreach ($service['mwexec']['start'] as $cmd) {
mwexec($cmd);
}
} else {
$msg = sprintf(gettext("Could not start service `%s'"), htmlspecialchars($name));
}
return $msg;
}
function service_control_stop($name, $extras)
{
$msg = sprintf(gettext("%s has been stopped."), htmlspecialchars($name));
$filter = array();
if (!empty($extras['id'])) {
$filter['id'] = $extras['id'];
}
$service = find_service_by_name($name, $filter);
if (!isset($service['name'])) {
return sprintf(gettext("Could not stop unknown service `%s'"), htmlspecialchars($name));
}
if (isset($service['configd']['stop'])) {
foreach ($service['configd']['stop'] as $cmd) {
configd_run($cmd);
}
} elseif (isset($service['php']['stop'])) {
foreach ($service['php']['stop'] as $cmd) {
$cmd();
}
} elseif (isset($service['mwexec']['stop'])) {
foreach ($service['mwexec']['stop'] as $cmd) {
mwexec($cmd);
}
} elseif (isset($service['pidfile'])) {
killbypid($service['pidfile'], 'TERM', true);
} else {
/* last resort, but not very elegant */
killbyname($service['name']);
}
return $msg;
}
function service_control_restart($name, $extras)
{
$msg = sprintf(gettext("%s has been restarted."), htmlspecialchars($name));
if (!empty($extras['id'])) {
$filter['id'] = $extras['id'];
}
$service = find_service_by_name($name, $filter);
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) {
$params = array();
if (isset($service['php']['args'])) {
foreach ($service['php']['args'] as $param) {
$params[] = $service[$param];
}
}
call_user_func_array($cmd, $params);
}
} 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;
}
......@@ -57,116 +57,6 @@ if (!empty($_POST['service'])) {
exit;
}
function service_control_start($name, $extras)
{
$msg = sprintf(gettext('%s has been started.'), htmlspecialchars($name));
if (!empty($extras['id'])) {
$filter['id'] = $extras['id'];
}
$service = find_service_by_name($name, $filter);
if (!isset($service['name'])) {
return sprintf(gettext("Could not start unknown service `%s'"), htmlspecialchars($name));
}
if (isset($service['configd']['start'])) {
foreach ($service['configd']['start'] as $cmd) {
configd_run($cmd);
}
} elseif (isset($service['php']['start'])) {
foreach ($service['php']['start'] as $cmd) {
$params = array();
if (isset($service['php']['args'])) {
foreach ($service['php']['args'] as $param) {
$params[] = $service[$param];
}
}
call_user_func_array($cmd, $params);
}
} elseif (isset($service['mwexec']['start'])) {
foreach ($service['mwexec']['start'] as $cmd) {
mwexec($cmd);
}
} else {
$msg = sprintf(gettext("Could not start service `%s'"), htmlspecialchars($name));
}
return $msg;
}
function service_control_stop($name, $extras)
{
$msg = sprintf(gettext("%s has been stopped."), htmlspecialchars($name));
$filter = array();
if (!empty($extras['id'])) {
$filter['id'] = $extras['id'];
}
$service = find_service_by_name($name, $filter);
if (!isset($service['name'])) {
return sprintf(gettext("Could not stop unknown service `%s'"), htmlspecialchars($name));
}
if (isset($service['configd']['stop'])) {
foreach ($service['configd']['stop'] as $cmd) {
configd_run($cmd);
}
} elseif (isset($service['php']['stop'])) {
foreach ($service['php']['stop'] as $cmd) {
$cmd();
}
} elseif (isset($service['mwexec']['stop'])) {
foreach ($service['mwexec']['stop'] as $cmd) {
mwexec($cmd);
}
} elseif (isset($service['pidfile'])) {
killbypid($service['pidfile'], 'TERM', true);
} else {
/* last resort, but not very elegant */
killbyname($service['name']);
}
return $msg;
}
function service_control_restart($name, $extras)
{
$msg = sprintf(gettext("%s has been restarted."), htmlspecialchars($name));
if (!empty($extras['id'])) {
$filter['id'] = $extras['id'];
}
$service = find_service_by_name($name, $filter);
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) {
$params = array();
if (isset($service['php']['args'])) {
foreach ($service['php']['args'] as $param) {
$params[] = $service[$param];
}
}
call_user_func_array($cmd, $params);
}
} 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