mirror of
				https://github.com/hyperion-project/hyperion.ng.git
				synced 2025-03-01 10:33:28 +00:00 
			
		
		
		
	Fix 'Restart' RPC command (#894)
This commit is contained in:
		@@ -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
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -71,6 +71,28 @@ public:
 | 
			
		||||
		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())
 | 
			
		||||
	{
 | 
			
		||||
		if(description.size())setApplicationDescription(description);
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
	{
 | 
			
		||||
 
 | 
			
		||||
@@ -18,6 +18,7 @@ QByteArray command_exec(QString /*cmd*/, QByteArray /*data*/)
 | 
			
		||||
#include <utils/Logger.h>
 | 
			
		||||
 | 
			
		||||
#include <QCoreApplication>
 | 
			
		||||
#include <QProcess>
 | 
			
		||||
#include <QStringList>
 | 
			
		||||
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
@@ -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<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';
 | 
			
		||||
	}
 | 
			
		||||
	QProcess::startDetached(QCoreApplication::applicationFilePath(), arguments);
 | 
			
		||||
 | 
			
		||||
	execv(args[0],args);
 | 
			
		||||
	Error(log, "error while restarting hyperion");
 | 
			
		||||
	QCoreApplication::quit();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QByteArray command_exec(QString cmd, QByteArray data)
 | 
			
		||||
 
 | 
			
		||||
@@ -61,7 +61,7 @@ QStringList getProcessIdsByProcessName(const char *processName)
 | 
			
		||||
			continue;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		QFile cmdline("/proc/" + pid + "/cmdline");
 | 
			
		||||
		QFile cmdline("/proc/" + pid + "/comm");
 | 
			
		||||
		if (!cmdline.open(QFile::ReadOnly | QFile::Text))
 | 
			
		||||
		{
 | 
			
		||||
			/* Can not open cmdline file */
 | 
			
		||||
 
 | 
			
		||||
@@ -151,12 +151,6 @@ int main(int argc, char** argv)
 | 
			
		||||
	#else
 | 
			
		||||
		const char* processName = "hyperiond";
 | 
			
		||||
	#endif
 | 
			
		||||
	const QStringList listOfPids = getProcessIdsByProcessName(processName);
 | 
			
		||||
	if (listOfPids.size() > 1)
 | 
			
		||||
	{
 | 
			
		||||
		Error(log, "The Hyperion Daemon is already running, abort start");
 | 
			
		||||
		return 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Initialising QCoreApplication
 | 
			
		||||
	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");
 | 
			
		||||
	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 & 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 & debugOption         = parser.add<BooleanOption> ('d', "debug", "Show debug messages");
 | 
			
		||||
#ifdef WIN32
 | 
			
		||||
	BooleanOption & consoleOption       = parser.add<BooleanOption> ('c', "console", "Open a console window to view log output");
 | 
			
		||||
#endif
 | 
			
		||||
	                                      parser.add<BooleanOption> (0x0, "desktop", "show systray on desktop");
 | 
			
		||||
	                                      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");
 | 
			
		||||
	                                      parser.add<BooleanOption> (0x0, "desktop", "Show systray on desktop");
 | 
			
		||||
	                                      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");
 | 
			
		||||
 | 
			
		||||
	/* 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);
 | 
			
		||||
 | 
			
		||||
	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
 | 
			
		||||
	if (parser.isSet(consoleOption))
 | 
			
		||||
	{
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user