35 lines
1.1 KiB
PHP
35 lines
1.1 KiB
PHP
<?php
|
|
// define restartable services
|
|
$restartables = array("minidlna");
|
|
|
|
// make sure script is called through a web server, not the command line
|
|
if (PHP_SAPI === 'cli') {
|
|
echo "This script needs to be run through a web server; aborting.";
|
|
die(1);
|
|
}
|
|
// retrieve query value for key "s" (as in service)
|
|
$service = $_GET['s'];
|
|
// make sure command exists and is not empty
|
|
if ($service === "" || empty($service)) {
|
|
echo "No service to restart; aborting.";
|
|
die(2);
|
|
}
|
|
// make sure service from query is available for restart
|
|
if ( ! in_array($service, $restartables) ) {
|
|
echo "Can't restart service ", $service, "; aborting";
|
|
die(3);
|
|
}
|
|
// put together command
|
|
$command = "/usr/bin/sudo /usr/bin/systemctl restart " . $service . ".service";
|
|
echo "Command is <code>", $command, "</code><br>";//DEBUG
|
|
// execute command
|
|
echo "Restarting service ", $service, " … ";
|
|
exec($command, $output, $exitcode);
|
|
// echo "Output is <pre>", join("<br>", $output), "</pre><br>";//DEBUG
|
|
if ( $exitcode == "0" ) {
|
|
echo "OK";
|
|
} else {
|
|
echo "failed with exit code ", $exitcode;
|
|
}
|
|
?>
|