diff --git a/scripts/service_controls.php b/scripts/service_controls.php index 97a3d6e..506eb3a 100644 --- a/scripts/service_controls.php +++ b/scripts/service_controls.php @@ -14,11 +14,17 @@ function service_status($name) { return; } } - $op = shell_exec("sudo systemctl status ".$name." | grep Active | grep ' active\| activating\|running\|waiting\|start'"); - if(strlen($op) > 0) { - echo "(active)"; + $op = shell_exec("sudo systemctl status ".$name." | grep Active"); + if (stripos($op, " active (running)")) { + echo "(active)"; + } elseif (stripos($op, " inactive ")) { + echo "(inactive)"; } else { - echo "(inactive)"; + $status = "ERROR"; + if (preg_match("/(\S*)\s*\((\S+)\)/", $op, $matches)) { + $status = $matches[1]. " [" . $matches[2] . "]"; + } + echo "($status)"; } } ?>