Skip to content

Commit

Permalink
Merge pull request #16 from alexandrecuer/master
Browse files Browse the repository at this point in the history
Fix #14 EmonHub Restart button
  • Loading branch information
glynhudson authored May 20, 2019
2 parents f60c658 + a68a288 commit a3f2fbb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
20 changes: 14 additions & 6 deletions config_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@

function config_controller()
{
global $route, $session, $redis;
global $route, $session, $redis, $homedir;
$result = false;

$emonhub_config_file = "/home/pi/data/emonhub.conf";
$emonhub_config_file = "$homedir/data/emonhub.conf";
$emonhub_logfile = "/var/log/emonhub/emonhub.log";
$restart_log= "$homedir/restart.log";

if (!$session['write']) return false;

Expand All @@ -45,7 +46,7 @@ function config_controller()
$route->format = "text";
ob_start();
passthru("journalctl -u emonhub -n 30 --no-pager");
return trim(ob_get_clean());
$result = trim(ob_get_clean());
}


Expand Down Expand Up @@ -83,9 +84,16 @@ function config_controller()
// www-data ALL=(ALL) NOPASSWD:service emonhub restart
else if ($route->action == 'restart')
{
exec("sudo /bin/systemctl restart emonhub > /dev/null &");
return true;
list($scriptPath) = get_included_files();
$basedir = str_replace("/index.php","",$scriptPath);
$restart_script = "$basedir/Modules/config/./restart.sh";
if ($redis->rpush("service-runner","$restart_script>$restart_log")){
$result= "service-runner trigger sent for $restart_script $homedir";
} else {
$result= "could not send trigger";
}

}

return array('content'=>$result);
return array('content'=>$result, 'fullwidth'=>false);
}
6 changes: 6 additions & 0 deletions restart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
date=$(date +"%Y-%m-%d")
date
echo "emonhub restarted by user $USER...."

sudo /bin/systemctl restart emonhub > /dev/null &

0 comments on commit a3f2fbb

Please sign in to comment.