From b9eadc0ce6a24a79322baedbc71ff09a646f6ef1 Mon Sep 17 00:00:00 2001 From: Colin Smith Date: Wed, 22 Jun 2005 03:53:01 +0000 Subject: Rework services. --- usr/local/www/status_services.php | 129 +++++++++++--------------------------- 1 file changed, 38 insertions(+), 91 deletions(-) (limited to 'usr/local/www/status_services.php') diff --git a/usr/local/www/status_services.php b/usr/local/www/status_services.php index 708f020..9c02ae0 100755 --- a/usr/local/www/status_services.php +++ b/usr/local/www/status_services.php @@ -28,74 +28,36 @@ */ require("guiconfig.inc"); +require("service-utils.inc"); function gentitle_pkg($pgname) { global $config; return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname; } -function get_package_rcd_details($extd) { - global $package_name, $executable_name, $description, $raw_name; - $raw_name = str_replace(".sh","",$extd); - $package_name = ""; - $executable_name = ""; - /* XXX: needs a get_pkg_description($packagename) function */ - $description = ""; - $file_contents = return_filename_as_string("/usr/local/etc/rc.d/{$extd}"); - if (preg_match_all("/\# PACKAGE\: (.*)\n/",$file_contents,$match_array)) - $package_name = $match_array[1][0]; - if (preg_match_all("/\# EXECUTABLE\: (.*)\n/",$file_contents,$match_array)) - $executable_name = $match_array[1][0]; - /* if we cannot locate it atleast return what they passed us */ - if($package_name == "") - $package_name = str_replace(".sh","",$extd); - if($executable_name == "") - $executable_name = str_replace(".sh","",$extd); - $description = find_package_description($raw_name); - if($description == "") - $description = " "; +if($_GET['mode'] == "restartservice" and $_GET['service']) { + restart_service($_GET['service']); + $savemsg = "{$_GET['service']} has been restarted."; } -if($_GET['service'] <> "") - get_package_rcd_details($_GET['service'] . ".sh"); - -if($_GET['restartservice'] == "true") { - mwexec("/usr/bin/killall {$executable_name}"); - sleep(1); - mwexec("/bin/sh /usr/local/etc/rc.d/{$raw_name}.sh start"); - $status = is_service_running($executable_name); - if($status == 1) { - $savemsg = "{$package_name} has been restarted."; - } else { - $error_message = exec_command("/bin/sh /usr/local/etc/rc.d/{$raw_name}.sh start"); - $savemsg = "There was a error restarting {$package_name}.

{$error_message}"; - } -} - -if($_GET['stopservice'] == "true") { - mwexec("/usr/bin/killall {$executable_name}"); - sleep(1); - $status = is_service_running($executable_name); - if($status == 1) { - $savemsg = "There was an error stopping {$package_name} - {$executable_name}."; - } else { - $savemsg = "{$package_name} has been stopped."; - } +if($_GET['mode'] == "startservice" and $_GET['service']) { + start_service($_GET['service']); + $savemsg = "{$_GET['service']} has been started."; } -if($_GET['startservice'] == "true") { - mwexec("/bin/sh /usr/local/etc/rc.d/{$raw_name}.sh start"); - $status = is_service_running($executable_name); - if($status == 1) { - $savemsg = "{$package_name} has been started."; - } else { - $error_message = exec_command("/bin/sh /usr/local/etc/rc.d/{$raw_name}.sh start"); - $savemsg = "There was a error restarting {$package_name}.

{$error_message}"; - } +if($_GET['mode'] == "stopservice" and $_GET['service']) { + stop_service($_GET['service']); + $savemsg = "{$_GET['service']} has been stopped."; } /* batch mode, allow other scripts to call this script */ -if($_GET['batch'] <> "") exit; +if($_GET['batch']) exit; + +exec("/bin/ps a | awk '{ print $5 }'", $psout); +array_shift($psout); +foreach($psout as $line) { + $ps[] = array_pop(explode('/', $line)); +} ?> @@ -126,53 +88,38 @@ include("fbegin.inc");

Service
Description
Status
-
Maintenance
Running"; - else - $status_txt = "Stopped"; - echo "{$package_name}"; - echo "{$description}"; - echo "{$status_txt}"; - echo "
"; - if($status == 1) { - echo ""; +if($config['installedpackages']['service']) { + foreach($config['installedpackages']['service'] as $service) { + if(!$service['name']) continue; + echo '' . $service['name'] . ''; + echo '' . $service['description'] . ''; + if(is_service_running($service['name'], $ps)) { + echo 'Running'; + $running = true; + } else { + echo 'Stopped'; + $running = false; + } + if($running) { + echo ""; echo " "; - echo ""; + echo ""; echo " "; - echo " "; + echo ""; } else { - echo " "; + echo " "; echo " "; } - echo "
"; - echo ""; - $counter++; + echo ''; } - -if($counter == 0) - echo "
Could not locate any services."; - +} else { + echo "
No services found."; +} ?> - - -- cgit v1.1