diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a59fca0..2975135d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,6 +76,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Decrease compile time (#886) - Fix some data synchronization error (#890) - Fix Qt screenhot crash (#889) +- Fix RPC restart of Hyperion (#894) ### Removed diff --git a/include/commandline/Parser.h b/include/commandline/Parser.h index 129d5184..7b1a806e 100644 --- a/include/commandline/Parser.h +++ b/include/commandline/Parser.h @@ -71,6 +71,28 @@ public: return *option; } + template + 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()) { if(description.size())setApplicationDescription(description); diff --git a/libsrc/api/JsonAPI.cpp b/libsrc/api/JsonAPI.cpp index 108ba5ec..6b0c3072 100644 --- a/libsrc/api/JsonAPI.cpp +++ b/libsrc/api/JsonAPI.cpp @@ -868,12 +868,16 @@ void JsonAPI::handleConfigCommand(const QJsonObject &message, const QString &com { if (_adminAuthorized) { - _hyperion->freeObjects(true); + Debug(_log, "Restarting due to RPC command"); + Process::restartHyperion(); - sendErrorReply("failed to restart hyperion", full_command, tan); + + sendSuccessReply(command + "-" + subcommand, tan); } else + { sendErrorReply("No Authorization", command, tan); + } } else { diff --git a/libsrc/utils/Process.cpp b/libsrc/utils/Process.cpp index eaa3c71a..3403398d 100644 --- a/libsrc/utils/Process.cpp +++ b/libsrc/utils/Process.cpp @@ -18,6 +18,7 @@ QByteArray command_exec(QString /*cmd*/, QByteArray /*data*/) #include #include +#include #include #include @@ -31,26 +32,20 @@ namespace Process { void restartHyperion(bool asNewProcess) { Logger* log = Logger::getInstance("Process"); + Info(log, "Restarting hyperion ..."); + std::cout << std::endl << " *******************************************" << std::endl << " * hyperion will restart now *" << std::endl << " *******************************************" << std::endl << std::endl; + auto arguments = QCoreApplication::arguments(); + if (!arguments.contains("--wait-hyperion")) + arguments << "--wait-hyperion"; - QStringList qargs = QCoreApplication::arguments(); - int size = qargs.size(); - char *args[size+1]; - args[size] = nullptr; - for(int i=0; i 1) - { - Error(log, "The Hyperion Daemon is already running, abort start"); - return 0; - } // Initialising QCoreApplication QScopedPointer app(createApplication(argc, argv)); @@ -181,18 +175,37 @@ int main(int argc, char** argv) Option & userDataOption = parser.add