Added advanced reboot commands
This commit is contained in:
parent
f126b340a0
commit
50b059cace
20
webcron.php
20
webcron.php
|
@ -42,8 +42,16 @@ if (file_exists("cache/get-services.trigger")) {
|
||||||
|
|
||||||
foreach($rebootjobs as $job) {
|
foreach($rebootjobs as $job) {
|
||||||
$services = array();
|
$services = array();
|
||||||
$url = "ssh " . $job['host'] . " '" . "sudo systemctl list-units | cat" . "' 2>&1";
|
parse_str(str_replace("reboot ", "", $job['url']), $rebootcommands);
|
||||||
|
$cmd = $rebootcommands['services'];
|
||||||
|
|
||||||
|
if ($cmd == '') {
|
||||||
|
$cmd = "sudo systemctl list-units | cat";
|
||||||
|
}
|
||||||
|
$url = "ssh " . $job['host'] . " '" . $cmd . "' 2>&1";
|
||||||
exec($url, $services);
|
exec($url, $services);
|
||||||
|
|
||||||
|
$cmd = '';
|
||||||
$services = implode("\n", $services);
|
$services = implode("\n", $services);
|
||||||
|
|
||||||
$stmt = $db->prepare("INSERT INTO runs(job, statuscode, result, timestamp) VALUES(?, ?, ?, ?)");
|
$stmt = $db->prepare("INSERT INTO runs(job, statuscode, result, timestamp) VALUES(?, ?, ?, ?)");
|
||||||
|
@ -86,6 +94,8 @@ foreach ($results as $result) {
|
||||||
}
|
}
|
||||||
if (!job_in_array($result['jobID'], $rebootjobs)) {
|
if (!job_in_array($result['jobID'], $rebootjobs)) {
|
||||||
$rebootjobs[] = $result;
|
$rebootjobs[] = $result;
|
||||||
|
$rebootser = serialize($rebootjobs);
|
||||||
|
file_put_contents("cache/get-services.trigger", $rebootser);
|
||||||
touch("cache/reboot.trigger");
|
touch("cache/reboot.trigger");
|
||||||
$nosave = true;
|
$nosave = true;
|
||||||
}
|
}
|
||||||
|
@ -118,9 +128,15 @@ if(file_exists("cache/reboot.trigger")) {
|
||||||
file_put_contents("cache/reboot-time.trigger", time() + (get_configvalue('jobs.reboottime') * 60));
|
file_put_contents("cache/reboot-time.trigger", time() + (get_configvalue('jobs.reboottime') * 60));
|
||||||
$rebooted_hosts = array();
|
$rebooted_hosts = array();
|
||||||
foreach($rebootjobs as $job) {
|
foreach($rebootjobs as $job) {
|
||||||
|
parse_str(str_replace("reboot ", "", $job['url']), $rebootcommands);
|
||||||
|
$cmd = $rebootcommands['cmd'];
|
||||||
|
|
||||||
$url = "ssh " . $job['host'] . " '" . 'sudo shutdown -r +' . get_configvalue('jobs.reboottime') . ' "A reboot has been scheduled. Please save your work."' . "'";
|
if ($cmd == '') {
|
||||||
|
$cmd = 'sudo shutdown -r +' . get_configvalue('jobs.reboottime') . ' "A reboot has been scheduled. Please save your work."';
|
||||||
|
}
|
||||||
|
$url = "ssh " . $job['host'] . " '" . $cmd . "'";
|
||||||
exec($url);
|
exec($url);
|
||||||
|
$cmd = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
require_once 'include/finalize.inc.php';
|
require_once 'include/finalize.inc.php';
|
||||||
|
|
Loading…
Reference in New Issue
Block a user