mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Fix 'Restart' RPC command (#894)
This commit is contained in:
parent
30f04a326b
commit
df0d411ba1
@ -76,6 +76,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Decrease compile time (#886)
|
- Decrease compile time (#886)
|
||||||
- Fix some data synchronization error (#890)
|
- Fix some data synchronization error (#890)
|
||||||
- Fix Qt screenhot crash (#889)
|
- Fix Qt screenhot crash (#889)
|
||||||
|
- Fix RPC restart of Hyperion (#894)
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
|
@ -71,6 +71,28 @@ public:
|
|||||||
return *option;
|
return *option;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class OptionT>
|
||||||
|
OptionT &addHidden(
|
||||||
|
const char shortOption,
|
||||||
|
const QString longOption,
|
||||||
|
const QString description,
|
||||||
|
const QString default_ = QString())
|
||||||
|
{
|
||||||
|
OptionT * option = new OptionT(
|
||||||
|
_getNames(shortOption, longOption),
|
||||||
|
_getDescription(description, default_),
|
||||||
|
longOption,
|
||||||
|
default_);
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
|
||||||
|
option->setFlags(QCommandLineOption::HiddenFromHelp);
|
||||||
|
#else
|
||||||
|
option->setHidden(true);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
addOption(option);
|
||||||
|
return *option;
|
||||||
|
}
|
||||||
|
|
||||||
Parser(QString description=QString())
|
Parser(QString description=QString())
|
||||||
{
|
{
|
||||||
if(description.size())setApplicationDescription(description);
|
if(description.size())setApplicationDescription(description);
|
||||||
|
@ -868,12 +868,16 @@ void JsonAPI::handleConfigCommand(const QJsonObject &message, const QString &com
|
|||||||
{
|
{
|
||||||
if (_adminAuthorized)
|
if (_adminAuthorized)
|
||||||
{
|
{
|
||||||
_hyperion->freeObjects(true);
|
Debug(_log, "Restarting due to RPC command");
|
||||||
|
|
||||||
Process::restartHyperion();
|
Process::restartHyperion();
|
||||||
sendErrorReply("failed to restart hyperion", full_command, tan);
|
|
||||||
|
sendSuccessReply(command + "-" + subcommand, tan);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
sendErrorReply("No Authorization", command, tan);
|
sendErrorReply("No Authorization", command, tan);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -18,6 +18,7 @@ QByteArray command_exec(QString /*cmd*/, QByteArray /*data*/)
|
|||||||
#include <utils/Logger.h>
|
#include <utils/Logger.h>
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
#include <QProcess>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -31,26 +32,20 @@ namespace Process {
|
|||||||
void restartHyperion(bool asNewProcess)
|
void restartHyperion(bool asNewProcess)
|
||||||
{
|
{
|
||||||
Logger* log = Logger::getInstance("Process");
|
Logger* log = Logger::getInstance("Process");
|
||||||
|
Info(log, "Restarting hyperion ...");
|
||||||
|
|
||||||
std::cout << std::endl
|
std::cout << std::endl
|
||||||
<< " *******************************************" << std::endl
|
<< " *******************************************" << std::endl
|
||||||
<< " * hyperion will restart now *" << std::endl
|
<< " * hyperion will restart now *" << std::endl
|
||||||
<< " *******************************************" << std::endl << std::endl;
|
<< " *******************************************" << std::endl << std::endl;
|
||||||
|
|
||||||
|
auto arguments = QCoreApplication::arguments();
|
||||||
|
if (!arguments.contains("--wait-hyperion"))
|
||||||
|
arguments << "--wait-hyperion";
|
||||||
|
|
||||||
QStringList qargs = QCoreApplication::arguments();
|
QProcess::startDetached(QCoreApplication::applicationFilePath(), 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);
|
QCoreApplication::quit();
|
||||||
Error(log, "error while restarting hyperion");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray command_exec(QString cmd, QByteArray data)
|
QByteArray command_exec(QString cmd, QByteArray data)
|
||||||
|
@ -61,7 +61,7 @@ QStringList getProcessIdsByProcessName(const char *processName)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
QFile cmdline("/proc/" + pid + "/cmdline");
|
QFile cmdline("/proc/" + pid + "/comm");
|
||||||
if (!cmdline.open(QFile::ReadOnly | QFile::Text))
|
if (!cmdline.open(QFile::ReadOnly | QFile::Text))
|
||||||
{
|
{
|
||||||
/* Can not open cmdline file */
|
/* Can not open cmdline file */
|
||||||
|
@ -151,12 +151,6 @@ int main(int argc, char** argv)
|
|||||||
#else
|
#else
|
||||||
const char* processName = "hyperiond";
|
const char* processName = "hyperiond";
|
||||||
#endif
|
#endif
|
||||||
const QStringList listOfPids = getProcessIdsByProcessName(processName);
|
|
||||||
if (listOfPids.size() > 1)
|
|
||||||
{
|
|
||||||
Error(log, "The Hyperion Daemon is already running, abort start");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialising QCoreApplication
|
// Initialising QCoreApplication
|
||||||
QScopedPointer<QCoreApplication> app(createApplication(argc, argv));
|
QScopedPointer<QCoreApplication> app(createApplication(argc, argv));
|
||||||
@ -181,18 +175,37 @@ int main(int argc, char** argv)
|
|||||||
Option & userDataOption = parser.add<Option> ('u', "userdata", "Overwrite user data path, defaults to home directory of current user (%1)", QDir::homePath() + "/.hyperion");
|
Option & userDataOption = parser.add<Option> ('u', "userdata", "Overwrite user data path, defaults to home directory of current user (%1)", QDir::homePath() + "/.hyperion");
|
||||||
BooleanOption & resetPassword = parser.add<BooleanOption> (0x0, "resetPassword", "Lost your password? Reset it with this option back to 'hyperion'");
|
BooleanOption & resetPassword = parser.add<BooleanOption> (0x0, "resetPassword", "Lost your password? Reset it with this option back to 'hyperion'");
|
||||||
BooleanOption & deleteDB = parser.add<BooleanOption> (0x0, "deleteDatabase", "Start all over? This Option will delete the database");
|
BooleanOption & deleteDB = parser.add<BooleanOption> (0x0, "deleteDatabase", "Start all over? This Option will delete the database");
|
||||||
BooleanOption & silentOption = parser.add<BooleanOption> ('s', "silent", "do not print any outputs");
|
BooleanOption & silentOption = parser.add<BooleanOption> ('s', "silent", "Do not print any outputs");
|
||||||
BooleanOption & verboseOption = parser.add<BooleanOption> ('v', "verbose", "Increase verbosity");
|
BooleanOption & verboseOption = parser.add<BooleanOption> ('v', "verbose", "Increase verbosity");
|
||||||
BooleanOption & debugOption = parser.add<BooleanOption> ('d', "debug", "Show debug messages");
|
BooleanOption & debugOption = parser.add<BooleanOption> ('d', "debug", "Show debug messages");
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
BooleanOption & consoleOption = parser.add<BooleanOption> ('c', "console", "Open a console window to view log output");
|
BooleanOption & consoleOption = parser.add<BooleanOption> ('c', "console", "Open a console window to view log output");
|
||||||
#endif
|
#endif
|
||||||
parser.add<BooleanOption> (0x0, "desktop", "show systray on desktop");
|
parser.add<BooleanOption> (0x0, "desktop", "Show systray on desktop");
|
||||||
parser.add<BooleanOption> (0x0, "service", "force hyperion to start as console service");
|
parser.add<BooleanOption> (0x0, "service", "Force hyperion to start as console service");
|
||||||
Option & exportEfxOption = parser.add<Option> (0x0, "export-effects", "export effects to given path");
|
Option & exportEfxOption = parser.add<Option> (0x0, "export-effects", "Export effects to given path");
|
||||||
|
|
||||||
|
/* Internal options, invisible to help */
|
||||||
|
BooleanOption & waitOption = parser.addHidden<BooleanOption> (0x0, "wait-hyperion", "Do not exit if other Hyperion instances are running, wait them to finish");
|
||||||
|
|
||||||
parser.process(*qApp);
|
parser.process(*qApp);
|
||||||
|
|
||||||
|
if (!parser.isSet(waitOption))
|
||||||
|
{
|
||||||
|
if (getProcessIdsByProcessName(processName).size() > 1)
|
||||||
|
{
|
||||||
|
Error(log, "The Hyperion Daemon is already running, abort start");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (getProcessIdsByProcessName(processName).size() > 1)
|
||||||
|
{
|
||||||
|
QThread::msleep(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
if (parser.isSet(consoleOption))
|
if (parser.isSet(consoleOption))
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user