mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
implement hyperion restart via webui (#242)
* first try * implement hyperion restart. core function is good, but needs a beeter structuring- something for next refactoring session ;-) * several fixes (including osx) merge with upstream some refactoring * add some eye candy to webui
This commit is contained in:
@@ -657,24 +657,26 @@ unsigned Hyperion::getLedCount() const
|
||||
|
||||
bool Hyperion::configModified()
|
||||
{
|
||||
bool isModified = false;
|
||||
QFile f(_configFile.c_str());
|
||||
if (f.open(QFile::ReadOnly))
|
||||
{
|
||||
QCryptographicHash hash(QCryptographicHash::Sha1);
|
||||
if (hash.addData(&f))
|
||||
if (hash.addData(&f))
|
||||
{
|
||||
if (_configHash.size() == 0)
|
||||
{
|
||||
if (_configHash.size() == 0)
|
||||
{
|
||||
_configHash = hash.result();
|
||||
qDebug(_configHash.toHex());
|
||||
return false;
|
||||
}
|
||||
return _configHash != hash.result();
|
||||
_configHash = hash.result();
|
||||
}
|
||||
else
|
||||
{
|
||||
isModified = _configHash != hash.result();
|
||||
}
|
||||
}
|
||||
}
|
||||
f.close();
|
||||
|
||||
return false;
|
||||
return isModified;
|
||||
}
|
||||
|
||||
void Hyperion::registerPriority(const std::string name, const int priority)
|
||||
|
@@ -1057,7 +1057,15 @@
|
||||
{
|
||||
"paths" :
|
||||
{
|
||||
"type" : "array"
|
||||
"type" : "array",
|
||||
"title" : "List of folders to additional effects",
|
||||
"propertyOrder" : 1
|
||||
},
|
||||
"disable" :
|
||||
{
|
||||
"type" : "array",
|
||||
"title" : "List of disabled effects",
|
||||
"propertyOrder" : 2
|
||||
}
|
||||
},
|
||||
"additionalProperties" : false
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#include <stdexcept>
|
||||
#include <cassert>
|
||||
#include <iomanip>
|
||||
#include <unistd.h>
|
||||
|
||||
// stl includes
|
||||
#include <iostream>
|
||||
@@ -15,6 +16,7 @@
|
||||
#include <QHostInfo>
|
||||
#include <QString>
|
||||
#include <QFile>
|
||||
#include <QCoreApplication>
|
||||
|
||||
// hyperion util includes
|
||||
#include <hyperion/ImageProcessorFactory.h>
|
||||
@@ -27,6 +29,7 @@
|
||||
#include <leddevice/LedDevice.h>
|
||||
#include <HyperionConfig.h>
|
||||
#include <utils/jsonschema/JsonFactory.h>
|
||||
#include <utils/Process.h>
|
||||
|
||||
// project includes
|
||||
#include "JsonClientConnection.h"
|
||||
@@ -883,6 +886,12 @@ void JsonClientConnection::handleConfigCommand(const Json::Value & message, cons
|
||||
{
|
||||
handleConfigSetCommand(message, full_command, tan);
|
||||
}
|
||||
else if (subcommand == "reload")
|
||||
{
|
||||
// restart hyperion, this code must be put in some own class ...
|
||||
Process::restartHyperion();
|
||||
sendErrorReply("failed to restart hyperion", full_command, tan);
|
||||
}
|
||||
else
|
||||
{
|
||||
sendErrorReply("unknown or missing subcommand", full_command, tan);
|
||||
|
@@ -10,7 +10,7 @@
|
||||
"subcommand": {
|
||||
"type" : "string",
|
||||
"required" : true,
|
||||
"enum" : ["getconfig","setconfig","getschema"]
|
||||
"enum" : ["getconfig","setconfig","getschema","reload"]
|
||||
},
|
||||
"tan" : {
|
||||
"type" : "integer"
|
||||
|
@@ -54,6 +54,9 @@
|
||||
"type" : "array",
|
||||
"propertyOrder" : 9,
|
||||
"default" : [1.0,1.0,1.0],
|
||||
"maxItems" : 3,
|
||||
"minItems" : 3,
|
||||
"format" : "table",
|
||||
"items" : {
|
||||
"type" : "number",
|
||||
"minimum" : 0.0,
|
||||
|
@@ -21,6 +21,8 @@ add_library(hyperion-utils
|
||||
${CURRENT_HEADER_DIR}/Sleep.h
|
||||
${CURRENT_HEADER_DIR}/FileUtils.h
|
||||
${CURRENT_SOURCE_DIR}/FileUtils.cpp
|
||||
${CURRENT_HEADER_DIR}/Process.h
|
||||
${CURRENT_SOURCE_DIR}/Process.cpp
|
||||
|
||||
${CURRENT_HEADER_DIR}/Logger.h
|
||||
${CURRENT_SOURCE_DIR}/Logger.cpp
|
||||
|
@@ -1,10 +1,5 @@
|
||||
#include <utils/FileUtils.h>
|
||||
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <QFileInfo>
|
||||
|
||||
namespace FileUtils {
|
||||
@@ -15,21 +10,5 @@ std::string getBaseName( std::string sourceFile)
|
||||
return fi.fileName().toStdString();
|
||||
}
|
||||
|
||||
std::string command_exec(const char* cmd)
|
||||
{
|
||||
char buffer[128];
|
||||
std::string result = "";
|
||||
std::shared_ptr<FILE> pipe(popen(cmd, "r"), pclose);
|
||||
if (pipe)
|
||||
{
|
||||
while (!feof(pipe.get()))
|
||||
{
|
||||
if (fgets(buffer, 128, pipe.get()) != NULL)
|
||||
result += buffer;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
};
|
57
libsrc/utils/Process.cpp
Normal file
57
libsrc/utils/Process.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#include <utils/Process.h>
|
||||
#include <utils/Logger.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QStringList>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace Process {
|
||||
|
||||
void restartHyperion(bool asNewProcess)
|
||||
{
|
||||
Logger* log = Logger::getInstance("Process");
|
||||
std::cout << std::endl
|
||||
<< " *******************************************" << std::endl
|
||||
<< " * hyperion will restart now *" << std::endl
|
||||
<< " *******************************************" << std::endl << std::endl;
|
||||
|
||||
|
||||
QStringList qargs = QCoreApplication::arguments();
|
||||
int size = qargs.size();
|
||||
char *args[size+1];
|
||||
args[size] = nullptr;
|
||||
for(int i=0; i<size; i++)
|
||||
{
|
||||
int str_size = qargs[i].toLocal8Bit().size();
|
||||
args[i] = new char[str_size+1];
|
||||
strncpy(args[i], qargs[i].toLocal8Bit().constData(),str_size );
|
||||
args[i][str_size] = '\0';
|
||||
}
|
||||
|
||||
execv(args[0],args);
|
||||
Error(log, "error while restarting hyperion");
|
||||
}
|
||||
|
||||
std::string command_exec(const char* cmd)
|
||||
{
|
||||
char buffer[128];
|
||||
std::string result = "";
|
||||
std::shared_ptr<FILE> pipe(popen(cmd, "r"), pclose);
|
||||
if (pipe)
|
||||
{
|
||||
while (!feof(pipe.get()))
|
||||
{
|
||||
if (fgets(buffer, 128, pipe.get()) != NULL)
|
||||
result += buffer;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
};
|
@@ -108,7 +108,7 @@ void QJsonSchemaChecker::validate(const QJsonValue & value, const QJsonObject &s
|
||||
; // nothing to do. value is present so always oke
|
||||
else if (attribute == "id")
|
||||
; // references have already been collected
|
||||
else if (attribute == "title" || attribute == "description" || attribute == "default" || attribute == "format"
|
||||
else if (attribute == "title" || attribute == "description" || attribute == "default" || attribute == "format"
|
||||
|| attribute == "defaultProperties" || attribute == "propertyOrder")
|
||||
; // nothing to do.
|
||||
else
|
||||
|
@@ -6,6 +6,7 @@
|
||||
#include "CgiHandler.h"
|
||||
#include "QtHttpHeader.h"
|
||||
#include <utils/FileUtils.h>
|
||||
#include <utils/Process.h>
|
||||
|
||||
CgiHandler::CgiHandler (Hyperion * hyperion, QString baseUrl, QObject * parent)
|
||||
: QObject(parent)
|
||||
@@ -96,7 +97,7 @@ void CgiHandler::cmd_runscript(const QStringList & args, QtHttpReply * reply)
|
||||
|
||||
if (QFile::exists(scriptFilePath) && !interpreter.isEmpty())
|
||||
{
|
||||
QByteArray data = FileUtils::command_exec(QString(interpreter + " " + scriptFilePath).toUtf8().constData()).c_str();
|
||||
QByteArray data = Process::command_exec(QString(interpreter + " " + scriptFilePath).toUtf8().constData()).c_str();
|
||||
|
||||
reply->addHeader ("Content-Type", "text/plain");
|
||||
reply->appendRawData (data);
|
||||
|
@@ -6,12 +6,12 @@
|
||||
WebConfig::WebConfig(QObject * parent)
|
||||
: QObject(parent)
|
||||
, _hyperion(Hyperion::getInstance())
|
||||
, _port(WEBCONFIG_DEFAULT_PORT)
|
||||
, _server(nullptr)
|
||||
{
|
||||
_baseUrl = WEBCONFIG_DEFAULT_PATH;
|
||||
const Json::Value &config = _hyperion->getJsonConfig();
|
||||
Logger* log = Logger::getInstance("WEBSERVER");
|
||||
_port = WEBCONFIG_DEFAULT_PORT;
|
||||
_baseUrl = WEBCONFIG_DEFAULT_PATH;
|
||||
const Json::Value &config = _hyperion->getJsonConfig();
|
||||
|
||||
bool webconfigEnable = true;
|
||||
|
||||
@@ -19,7 +19,7 @@ WebConfig::WebConfig(QObject * parent)
|
||||
{
|
||||
const Json::Value & webconfigConfig = config["webConfig"];
|
||||
webconfigEnable = webconfigConfig.get("enable", true).asBool();
|
||||
_port = webconfigConfig.get("port", WEBCONFIG_DEFAULT_PORT).asUInt();
|
||||
_port = webconfigConfig.get("port", _port).asUInt();
|
||||
_baseUrl = QString::fromStdString( webconfigConfig.get("document_root", _baseUrl.toStdString()).asString() );
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user