Skip to content

Commit

Permalink
emonhub systemd service support
Browse files Browse the repository at this point in the history
  • Loading branch information
glynhudson committed Feb 21, 2019
1 parent f38b465 commit 703865b
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions config_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,37 @@ function config_controller()
$emonhub_config_file = "/home/pi/data/emonhub.conf";
$emonhub_logfile = "/var/log/emonhub/emonhub.log";

if (!$session['write']) return array('content'=>false);
if (!$session['write']) return false;

if ($route->action == 'view') {
$route->format = "html";
$result = view("Modules/config/edit.php", array());
return array('content'=>$result, 'fullwidth'=>false);
}

if ($route->action == 'get') {
else if ($route->action == 'get') {
$route->format = "text";
$result = file_get_contents($emonhub_config_file);
return file_get_contents($emonhub_config_file);
}

if ($route->action == 'getemonhublog') {
else if ($route->action == 'getemonhublog') {
$route->format = "text";
ob_start();
passthru("tail -30 ".$emonhub_logfile);
$result = trim(ob_get_clean());
passthru("journalctl -u emonhub -n 30 --no-pager");
return trim(ob_get_clean());
}


if ($route->action == 'set' && isset($_POST['config'])) {
else if ($route->action == 'set' && isset($_POST['config'])) {
$route->format = "text";
$config = $_POST['config'];
$fh = fopen($emonhub_config_file,"w");
fwrite($fh,$config);
fclose($fh);
$result = "Config Saved";
return "Config Saved";
}

if ($route->action == 'downloadlog')
else if ($route->action == 'downloadlog')
{
header("Content-Type: application/octet-stream");
header("Content-Transfer-Encoding: Binary");
Expand All @@ -71,12 +71,13 @@ function config_controller()
exit;
}

// emonHub restart requires added to /etc/sudoers:
// www-data ALL=(ALL) NOPASSWD:/etc/init.d/emonhub restart
if ($route->action == 'restart')
{
exec("sudo /etc/init.d/emonhub restart > /dev/null &");
}
// emonHub restart requires added to /etc/sudoers:
// www-data ALL=(ALL) NOPASSWD:service emonhub restart
else if ($route->action == 'restart')
{
exec("sudo service emonhub restart > /dev/null &");
return true;
}

return array('content'=>$result);
}

0 comments on commit 703865b

Please sign in to comment.