mirror of
https://github.com/overte-org/overte.git
synced 2025-07-26 06:29:50 +02:00
add ability for domain-server to restart after setting save
This commit is contained in:
parent
e6449da890
commit
3c71d4d96e
5 changed files with 29 additions and 5 deletions
|
@ -30,6 +30,8 @@
|
||||||
|
|
||||||
#include "DomainServer.h"
|
#include "DomainServer.h"
|
||||||
|
|
||||||
|
int const DomainServer::EXIT_CODE_REBOOT = 234923;
|
||||||
|
|
||||||
DomainServer::DomainServer(int argc, char* argv[]) :
|
DomainServer::DomainServer(int argc, char* argv[]) :
|
||||||
QCoreApplication(argc, argv),
|
QCoreApplication(argc, argv),
|
||||||
_shutdownEventListener(this),
|
_shutdownEventListener(this),
|
||||||
|
@ -56,7 +58,7 @@ DomainServer::DomainServer(int argc, char* argv[]) :
|
||||||
QSettings::setDefaultFormat(QSettings::IniFormat);
|
QSettings::setDefaultFormat(QSettings::IniFormat);
|
||||||
|
|
||||||
_settingsManager.loadSettingsMap(arguments());
|
_settingsManager.loadSettingsMap(arguments());
|
||||||
|
|
||||||
installNativeEventFilter(&_shutdownEventListener);
|
installNativeEventFilter(&_shutdownEventListener);
|
||||||
connect(&_shutdownEventListener, SIGNAL(receivedCloseEvent()), SLOT(quit()));
|
connect(&_shutdownEventListener, SIGNAL(receivedCloseEvent()), SLOT(quit()));
|
||||||
|
|
||||||
|
@ -77,6 +79,11 @@ DomainServer::DomainServer(int argc, char* argv[]) :
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DomainServer::restart() {
|
||||||
|
qDebug() << "domain-server is restarting.";
|
||||||
|
exit(DomainServer::EXIT_CODE_REBOOT);
|
||||||
|
}
|
||||||
|
|
||||||
bool DomainServer::optionallyReadX509KeyAndCertificate() {
|
bool DomainServer::optionallyReadX509KeyAndCertificate() {
|
||||||
const QString X509_CERTIFICATE_OPTION = "cert";
|
const QString X509_CERTIFICATE_OPTION = "cert";
|
||||||
const QString X509_PRIVATE_KEY_OPTION = "key";
|
const QString X509_PRIVATE_KEY_OPTION = "key";
|
||||||
|
|
|
@ -35,16 +35,17 @@
|
||||||
typedef QSharedPointer<Assignment> SharedAssignmentPointer;
|
typedef QSharedPointer<Assignment> SharedAssignmentPointer;
|
||||||
typedef QMultiHash<QUuid, WalletTransaction*> TransactionHash;
|
typedef QMultiHash<QUuid, WalletTransaction*> TransactionHash;
|
||||||
|
|
||||||
|
|
||||||
class DomainServer : public QCoreApplication, public HTTPSRequestHandler {
|
class DomainServer : public QCoreApplication, public HTTPSRequestHandler {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
DomainServer(int argc, char* argv[]);
|
DomainServer(int argc, char* argv[]);
|
||||||
|
|
||||||
|
static int const EXIT_CODE_REBOOT;
|
||||||
|
|
||||||
bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url);
|
bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url);
|
||||||
bool handleHTTPSRequest(HTTPSConnection* connection, const QUrl& url);
|
bool handleHTTPSRequest(HTTPSConnection* connection, const QUrl& url);
|
||||||
|
|
||||||
void exit(int retCode = 0);
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
/// Called by NodeList to inform us a node has been added
|
/// Called by NodeList to inform us a node has been added
|
||||||
void nodeAdded(SharedNodePointer node);
|
void nodeAdded(SharedNodePointer node);
|
||||||
|
@ -53,6 +54,8 @@ public slots:
|
||||||
|
|
||||||
void transactionJSONCallback(const QJsonObject& data);
|
void transactionJSONCallback(const QJsonObject& data);
|
||||||
|
|
||||||
|
void restart();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void loginFailed();
|
void loginFailed();
|
||||||
void readAvailableDatagrams();
|
void readAvailableDatagrams();
|
||||||
|
|
|
@ -146,6 +146,10 @@ bool DomainServerSettingsManager::handleAuthenticatedHTTPRequest(HTTPConnection
|
||||||
QString jsonSuccess = "{\"status\": \"success\"}";
|
QString jsonSuccess = "{\"status\": \"success\"}";
|
||||||
connection->respond(HTTPConnection::StatusCode200, jsonSuccess.toUtf8(), "application/json");
|
connection->respond(HTTPConnection::StatusCode200, jsonSuccess.toUtf8(), "application/json");
|
||||||
|
|
||||||
|
// defer a restart to the domain-server, this gives our HTTPConnection enough time to respond
|
||||||
|
const int DOMAIN_SERVER_RESTART_TIMER_MSECS = 1000;
|
||||||
|
QTimer::singleShot(DOMAIN_SERVER_RESTART_TIMER_MSECS, qApp, SLOT(restart()));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,8 @@ public:
|
||||||
|
|
||||||
QByteArray getJSONSettingsMap() const;
|
QByteArray getJSONSettingsMap() const;
|
||||||
const QVariantMap& getSettingsMap() const { return _settingsMap; }
|
const QVariantMap& getSettingsMap() const { return _settingsMap; }
|
||||||
|
signals:
|
||||||
|
void saveRequiresRestart();
|
||||||
private:
|
private:
|
||||||
void recurseJSONObjectAndOverwriteSettings(const QJsonObject& postedObject, QVariantMap& settingsVariant,
|
void recurseJSONObjectAndOverwriteSettings(const QJsonObject& postedObject, QVariantMap& settingsVariant,
|
||||||
QJsonArray descriptionArray);
|
QJsonArray descriptionArray);
|
||||||
|
|
|
@ -28,8 +28,16 @@ int main(int argc, char* argv[]) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
qInstallMessageHandler(Logging::verboseMessageHandler);
|
qInstallMessageHandler(Logging::verboseMessageHandler);
|
||||||
DomainServer domainServer(argc, argv);
|
|
||||||
|
|
||||||
return domainServer.exec();
|
int currentExitCode = 0;
|
||||||
|
|
||||||
|
// use a do-while to handle domain-server restart
|
||||||
|
do {
|
||||||
|
DomainServer domainServer(argc, argv);
|
||||||
|
currentExitCode = domainServer.exec();
|
||||||
|
} while (currentExitCode == DomainServer::EXIT_CODE_REBOOT);
|
||||||
|
|
||||||
|
|
||||||
|
return currentExitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue