Add shutdown process for server

This commit is contained in:
Simon Stürz 2018-08-16 19:55:06 +02:00
parent 481cddb869
commit da1d43a0c3
12 changed files with 180 additions and 21 deletions

View File

@ -6,7 +6,7 @@ Wants=network-online.target
[Service]
Type=simple
ExecStart=/usr/bin/nymea-remoteproxy -c /etc/nymea/nymea-remoteproxy.conf --verbose
ExecStart=/usr/bin/nymea-remoteproxy -c /etc/nymea/nymea-remoteproxy.conf
StandardOutput=journal
StandardError=journal
Restart=on-failure

View File

@ -1,5 +1,6 @@
#include "authenticationprocess.h"
#include "loggingcategories.h"
#include "userinformation.h"
#include <QUrl>
#include <QFile>
@ -152,8 +153,16 @@ void AuthenticationProcess::onProcessFinished(int exitCode, QProcess::ExitStatus
}
bool isValid = response.value("isValid").toBool();
if (isValid) {
QVariantMap verifiedDataMap = response.value("verifiedData").toMap();
QString vendorId = verifiedDataMap.value("vendorId").toString();
QString userPoolId = verifiedDataMap.value("userPoolId").toString();
QVariantMap verifiedParsedTokenMap = verifiedDataMap.value("verifiedParsedToken").toMap();
QString email = verifiedParsedTokenMap.value("email").toString();
QString cognitoUsername = verifiedParsedTokenMap.value("cognito:username").toString();
UserInformation userInformation(email, cognitoUsername, vendorId, userPoolId);
emit authenticationFinished(Authenticator::AuthenticationErrorNoError);
} else {
emit authenticationFinished(Authenticator::AuthenticationErrorAuthenticationFailed);

View File

@ -0,0 +1,42 @@
#include "userinformation.h"
namespace remoteproxy {
UserInformation::UserInformation(const QString &email, const QString &cognitoUsername, const QString &vendorId, const QString &userPoolId) :
m_email(email),
m_cognitoUsername(cognitoUsername),
m_vendorId(vendorId),
m_userPoolId(userPoolId)
{
}
QString UserInformation::email() const
{
return m_email;
}
QString UserInformation::cognitoUsername() const
{
return m_cognitoUsername;
}
QString UserInformation::vendorId() const
{
return m_vendorId;
}
QString UserInformation::userPoolId() const
{
return m_userPoolId;
}
bool UserInformation::isValid()
{
return !m_email.isEmpty()
&& !m_cognitoUsername.isEmpty()
&& !m_vendorId.isEmpty()
&& !m_userPoolId.isEmpty();
}
}

View File

@ -0,0 +1,30 @@
#ifndef USERINFORMATION_H
#define USERINFORMATION_H
#include <QString>
namespace remoteproxy {
class UserInformation
{
public:
UserInformation(const QString &email = QString(), const QString &cognitoUsername = QString(), const QString &vendorId = QString(), const QString &userPoolId = QString());
QString email() const;
QString cognitoUsername() const;
QString vendorId() const;
QString userPoolId() const;
bool isValid();
private:
QString m_email;
QString m_cognitoUsername;
QString m_vendorId;
QString m_userPoolId;
};
}
#endif // USERINFORMATION_H

View File

@ -169,9 +169,9 @@ void Engine::setRunning(bool running)
if (m_running == running)
return;
qCDebug(dcEngine()) << "----------------------------------------------------------";
//qCDebug(dcEngine()) << "----------------------------------------------------------";
qCDebug(dcEngine()) << "Engine is" << (running ? "now running." : "not running any more.");
qCDebug(dcEngine()) << "----------------------------------------------------------";
//qCDebug(dcEngine()) << "----------------------------------------------------------";
m_running = running;
emit runningChanged(m_running);
}

View File

@ -3,12 +3,6 @@ include(../nymea-remoteproxy.pri)
TEMPLATE = lib
TARGET = nymea-remoteproxy
# -L/home/timon/guh/development/cloud/aws-sdk-cpp/build/install/lib
# -laws-cpp-sdk-access-management \
# -laws-cpp-sdk-cognito-identity \
# -laws-cpp-sdk-iam \
# -laws-cpp-sdk-kinesis\
HEADERS += \
engine.h \
loggingcategories.h \
@ -16,6 +10,9 @@ HEADERS += \
websocketserver.h \
proxyclient.h \
proxyserver.h \
monitorserver.h \
proxyconfiguration.h \
tunnelconnection.h \
jsonrpcserver.h \
jsonrpc/jsonhandler.h \
jsonrpc/jsonreply.h \
@ -24,11 +21,9 @@ HEADERS += \
authentication/authenticator.h \
authentication/awsauthenticator.h \
authentication/authenticationreply.h \
proxyconfiguration.h \
tunnelconnection.h \
authentication/userinformation.h \
authentication/authenticationprocess.h \
authentication/dummyauthenticator.h \
monitorserver.h
SOURCES += \
engine.cpp \
@ -37,6 +32,9 @@ SOURCES += \
websocketserver.cpp \
proxyclient.cpp \
proxyserver.cpp \
monitorserver.cpp \
proxyconfiguration.cpp \
tunnelconnection.cpp \
jsonrpcserver.cpp \
jsonrpc/jsonhandler.cpp \
jsonrpc/jsonreply.cpp \
@ -45,11 +43,9 @@ SOURCES += \
authentication/authenticator.cpp \
authentication/awsauthenticator.cpp \
authentication/authenticationreply.cpp \
proxyconfiguration.cpp \
tunnelconnection.cpp \
authentication/userinformation.cpp \
authentication/authenticationprocess.cpp \
authentication/dummyauthenticator.cpp \
monitorserver.cpp
# install header file with relative subdirectory

View File

@ -94,10 +94,11 @@ void MonitorServer::startServer()
void MonitorServer::stopServer()
{
m_timer->stop();
if (!m_server)
return;
qCDebug(dcMonitorServer()) << "Stopping server" << m_serverName;
qCDebug(dcMonitorServer()) << "Stop server" << m_serverName;
foreach (QLocalSocket *clientConnection, m_clients) {
clientConnection->close();
}

View File

@ -9,4 +9,3 @@ target.path = /usr/bin
INSTALLS += target
HEADERS += \
proxyclient.h

View File

@ -8,7 +8,6 @@
#include <QMessageLogger>
#include <QSslCertificate>
#include <QCoreApplication>
#include <QCoreApplication>
#include <QLoggingCategory>
#include <QSslConfiguration>
#include <QCommandLineParser>
@ -21,6 +20,7 @@
#include "engine.h"
#include "loggingcategories.h"
#include "proxyconfiguration.h"
#include "remoteproxyserverapplication.h"
#include "authentication/awsauthenticator.h"
#include "authentication/dummyauthenticator.h"
@ -87,7 +87,7 @@ int main(int argc, char *argv[])
{
qInstallMessageHandler(consoleLogHandler);
QCoreApplication application(argc, argv);
RemoteProxyServerApplication application(argc, argv);
application.setApplicationName(SERVER_NAME_STRING);
application.setOrganizationName("nymea");
application.setApplicationVersion(SERVER_VERSION_STRING);

View File

@ -0,0 +1,59 @@
#include "remoteproxyserverapplication.h"
#include "loggingcategories.h"
#include "engine.h"
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
#include <cxxabi.h>
using namespace remoteproxy;
static void catchUnixSignals(const std::vector<int>& quitSignals, const std::vector<int>& ignoreSignals = std::vector<int>())
{
auto handler = [](int sig) ->void {
switch (sig) {
case SIGQUIT:
qCDebug(dcApplication()) << "Cought SIGQUIT quit signal...";
break;
case SIGINT:
qCDebug(dcApplication()) << "Cought SIGINT quit signal...";
break;
case SIGTERM:
qCDebug(dcApplication()) << "Cought SIGTERM quit signal...";
break;
case SIGHUP:
qCDebug(dcApplication()) << "Cought SIGHUP quit signal...";
break;
case SIGSEGV: {
qCDebug(dcApplication()) << "Cought SIGSEGV signal. Segmentation fault!";
exit(1);
}
default:
break;
}
qCDebug(dcApplication()) << "==========================================================";
qCDebug(dcApplication) << "Shutting down nymea-remoteproxy";
qCDebug(dcApplication()) << "==========================================================";
Engine::instance()->destroy();
RemoteProxyServerApplication::quit();
};
// all these signals will be ignored.
for (int sig : ignoreSignals)
signal(sig, SIG_IGN);
for (int sig : quitSignals)
signal(sig, handler);
}
RemoteProxyServerApplication::RemoteProxyServerApplication(int &argc, char **argv) :
QCoreApplication(argc, argv)
{
catchUnixSignals({SIGQUIT, SIGINT, SIGTERM, SIGHUP, SIGSEGV});
}

View File

@ -0,0 +1,19 @@
#ifndef REMOTEPROXYSERVERAPPLICATION_H
#define REMOTEPROXYSERVERAPPLICATION_H
#include <QObject>
#include <QSocketNotifier>
#include <QCoreApplication>
class RemoteProxyServerApplication : public QCoreApplication
{
Q_OBJECT
public:
explicit RemoteProxyServerApplication(int &argc, char **argv);
signals:
public slots:
};
#endif // REMOTEPROXYSERVERAPPLICATION_H

View File

@ -7,7 +7,11 @@ INCLUDEPATH += ../libnymea-remoteproxy
LIBS += -L$$top_builddir/libnymea-remoteproxy/ -lnymea-remoteproxy
SOURCES += main.cpp
SOURCES += main.cpp \
remoteproxyserverapplication.cpp
target.path = /usr/bin
INSTALLS += target
HEADERS += \
remoteproxyserverapplication.h