add shutdown and SIG quit signal capture

update manpage
pull/135/head
Simon Stürz 2016-01-23 18:52:11 +01:00 committed by Michael Zanetti
parent cfc965489f
commit 03381cc25c
19 changed files with 147 additions and 56 deletions

5
debian/guhd.1 vendored
View File

@ -1,6 +1,6 @@
.\" Manpage for guhd.
.\" Contact simon.stuerz@guh.guru to correct errors or typos.
.TH man 1 "December 2015" "1.3" "guhd man page"
.TH man 1 "January 2016" "1.4" "guhd man page"
.SH NAME
guhd \- An open source IoT (Internet of Things) server
.SH SYNOPSIS
@ -102,8 +102,9 @@ How to report bugs: <https://github.com/guh/guh/wiki/Reporting-bugs>
.SH AUTHOR
Written by Simon Stürz and Michael Zanetti
.SH COPYRIGHT
Copyright \(co 2013-2015 ARGE guh.
Copyright \(co 2014-2016 guh GmbH.
.br
License GPLv2: GNU GPL version 2 <http://gnu.org/licenses/gpl.html>.
.br
This is free software: you are free to change and redistribute it.

View File

@ -238,7 +238,7 @@ DeviceManager::DeviceManager(QObject *parent) :
/*! Destructor of the DeviceManager. Each loaded \l{DevicePlugin} will be deleted. */
DeviceManager::~DeviceManager()
{
qCDebug(dcDeviceManager) << "Shutting down DeviceManager";
qCDebug(dcApplication) << "Shutting down device manager";
foreach (DevicePlugin *plugin, m_devicePlugins) {
delete plugin;
}

73
server/guhapplication.cpp Normal file
View File

@ -0,0 +1,73 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2016 Simon Stuerz <simon.stuerz@guh.guru> *
* *
* This file is part of guh. *
* *
* Guh is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 2 of the License. *
* *
* Guh is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "guhapplication.h"
#include "loggingcategories.h"
#include "guhcore.h"
#include "unistd.h"
#include "signal.h"
namespace guhserver {
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;
default:
break;
}
qCDebug(dcApplication) << "=====================================";
qCDebug(dcApplication) << "Shutting down guh daemon";
qCDebug(dcApplication) << "=====================================";
GuhCore::instance()->destroy();
GuhApplication::quit();
};
// all these signals will be ignored.
for (int sig : ignoreSignals)
signal(sig, SIG_IGN);
for (int sig : quitSignals)
signal(sig, handler);
}
GuhApplication::GuhApplication(int &argc, char **argv) :
QCoreApplication(argc, argv)
{
catchUnixSignals({SIGQUIT, SIGINT, SIGTERM, SIGHUP});
}
}

37
server/guhapplication.h Normal file
View File

@ -0,0 +1,37 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2016 Simon Stuerz <simon.stuerz@guh.guru> *
* *
* This file is part of guh. *
* *
* Guh is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 2 of the License. *
* *
* Guh is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef GUHAPPLICATION_H
#define GUHAPPLICATION_H
#include <QObject>
#include <QSocketNotifier>
#include <QCoreApplication>
namespace guhserver {
class GuhApplication : public QCoreApplication
{
public:
GuhApplication(int &argc, char **argv);
};
}
#endif // GUHAPPLICATION_H

View File

@ -29,13 +29,6 @@
instantiate, set up and connect all the other components.
*/
/*! \enum guhserver::GuhCore::RunningMode
\value RunningModeApplication
Guh runns as application.
\value RunningModeService
Guh is started as service (daemon).
*/
/*! \fn void guhserver::GuhCore::eventTriggered(const Event &event);
This signal is emitted when an \a event happend.
*/
@ -129,28 +122,17 @@ GuhCore *GuhCore::instance()
GuhCore::~GuhCore()
{
m_logger->logSystemEvent(false);
qCDebug(dcApplication) << "Shutting down. Bye.";
}
/*! Destroyes the \l{GuhCore} instance. */
void GuhCore::destroy()
{
if (s_instance)
delete s_instance;
s_instance = 0;
}
/*! Returns the runningMode of this instance. */
GuhCore::RunningMode GuhCore::runningMode() const
{
return m_runningMode;
}
/*! Set the \a runningMode of this instance. */
void GuhCore::setRunningMode(const RunningMode &runningMode)
{
m_runningMode = runningMode;
}
/*! Calls the metheod DeviceManager::plugins().
* \sa DeviceManager::plugins(), */
QList<DevicePlugin *> GuhCore::plugins() const
@ -557,6 +539,7 @@ RuleEngine *GuhCore::ruleEngine() const
GuhCore::GuhCore(QObject *parent) :
QObject(parent)
{
qCDebug(dcApplication) << "Creating Log Engine";
m_logger = new LogEngine(this);
qCDebug(dcApplication) << "Creating Device Manager";
@ -565,7 +548,6 @@ GuhCore::GuhCore(QObject *parent) :
qCDebug(dcApplication) << "Creating Rule Engine";
m_ruleEngine = new RuleEngine(this);
qCDebug(dcApplication) << "Creating Server Manager";
m_serverManager = new ServerManager(this);

View File

@ -46,20 +46,11 @@ class GuhCore : public QObject
{
Q_OBJECT
public:
enum RunningMode {
RunningModeApplication,
RunningModeService
};
static GuhCore* instance();
~GuhCore();
// Used for testing
void destroy();
RunningMode runningMode() const;
void setRunningMode(const RunningMode &runningMode);
QList<DevicePlugin *> plugins() const;
DeviceManager::DeviceError setPluginConfig(const PluginId &pluginId, const ParamList &params);
@ -126,7 +117,6 @@ private:
explicit GuhCore(QObject *parent = 0);
static GuhCore *s_instance;
RunningMode m_runningMode;
ServerManager *m_serverManager;
DeviceManager *m_deviceManager;

View File

@ -62,14 +62,7 @@ void GuhService::start()
qCDebug(dcApplication) << "=====================================";
qCDebug(dcApplication) << "guhd" << GUH_VERSION_STRING << "started as daemon.";
qCDebug(dcApplication) << "=====================================";
GuhCore::instance()->setRunningMode(GuhCore::RunningModeService);
}
void GuhService::stop()
{
qCDebug(dcApplication) << "=====================================";
qCDebug(dcApplication) << "Shutting down guh daemon";
qCDebug(dcApplication) << "=====================================";
GuhCore::instance();
}
}

View File

@ -37,7 +37,6 @@ public:
protected:
void start();
void stop();
};
}

View File

@ -145,6 +145,12 @@ LogEngine::LogEngine(QObject *parent):
initDB();
}
LogEngine::~LogEngine()
{
qCDebug(dcApplication) << "Shutting down log engine";
m_db.close();
}
/*! Returns the list of \l{LogEntry}{LogEntries} of the database matching the given \a filter.
\sa LogEntry, LogFilter

View File

@ -38,6 +38,7 @@ class LogEngine: public QObject
Q_OBJECT
public:
LogEngine(QObject *parent = 0);
~LogEngine();
QList<LogEntry> logEntries(const LogFilter &filter = LogFilter()) const;

View File

@ -36,6 +36,7 @@
#include "guhcore.h"
#include "guhservice.h"
#include "guhsettings.h"
#include "guhapplication.h"
#include "loggingcategories.h"
static QHash<QString, bool> s_loggingFilters;
@ -87,12 +88,11 @@ static void consoleLogHandler(QtMsgType type, const QMessageLogContext& context,
logFile.close();
}
int main(int argc, char *argv[])
{
qInstallMessageHandler(consoleLogHandler);
QCoreApplication application(argc, argv);
GuhApplication application(argc, argv);
application.setOrganizationName("guh");
application.setApplicationName("guhd");
application.setApplicationVersion(GUH_VERSION_STRING);
@ -121,13 +121,13 @@ int main(int argc, char *argv[])
parser.addHelpOption();
parser.addVersionOption();
QString applicationDescription = QString("\nguh ( /[guːh]/ ) is an open source IoT (Internet of Things) server, \n"
"which allows to control a lot of different devices from many different. \n"
"which allows to control a lot of different devices from many different \n"
"manufacturers. With the powerful rule engine you are able to connect any \n"
"device available in the system and create individual scenes and behaviors \n"
"for your environment.\n\n"
"guhd %1 (C) 2014-2015 guh\n"
"guhd %1 %2 2014-2016 guh GmbH\n"
"Released under the GNU GENERAL PUBLIC LICENSE Version 2.\n\n"
"API version: %2\n").arg(GUH_VERSION_STRING).arg(JSON_PROTOCOL_VERSION);
"API version: %3\n").arg(GUH_VERSION_STRING).arg(QChar(0xA9)).arg(JSON_PROTOCOL_VERSION);
parser.setApplicationDescription(applicationDescription);
@ -142,6 +142,7 @@ int main(int argc, char *argv[])
foreach (const QString &filterName, sortedFilterList) {
debugDescription += "\n- " + filterName + " (" + (s_loggingFilters.value(filterName) ? "yes" : "no") + ")";
}
// create sorted plugin loggingFiler list
QStringList sortedPluginList = QStringList(loggingFiltersPlugins.keys());
sortedPluginList.sort();
@ -195,7 +196,7 @@ int main(int argc, char *argv[])
}
// create core instance
GuhCore::instance()->setRunningMode(GuhCore::RunningModeApplication);
GuhCore::instance();
return application.exec();
}

View File

@ -168,7 +168,6 @@ public:
~QtService()
{
}
protected:
Application *application() const
{ return app; }

View File

@ -213,6 +213,11 @@ RuleEngine::RuleEngine(QObject *parent) :
}
}
RuleEngine::~RuleEngine()
{
qCDebug(dcApplication) << "Shutting down rule engine";
}
/*! Ask the Engine to evaluate all the rules for the given \a event.
This will search all the \l{Rule}{Rules} triggered by the given \a event
and evaluate their states in the system. It will return a

View File

@ -64,6 +64,7 @@ public:
};
explicit RuleEngine(QObject *parent = 0);
~RuleEngine();
QList<Rule> evaluateEvent(const Event &event);

View File

@ -16,7 +16,8 @@ include(server.pri)
include(qtservice/qtservice.pri)
SOURCES += main.cpp \
guhservice.cpp
guhservice.cpp \
guhapplication.cpp
boblight {
xcompile {
@ -28,4 +29,5 @@ boblight {
}
HEADERS += \
guhservice.h
guhservice.h \
guhapplication.h

View File

@ -87,6 +87,8 @@ TcpServer::TcpServer(QObject *parent) :
/*! Destructor of this \l{TcpServer}. */
TcpServer::~TcpServer()
{
qCDebug(dcApplication) << "Shutting down TCP server";
stopServer();
}
/*! Sending \a data to a list of \a clients.*/
@ -309,7 +311,6 @@ bool TcpServer::stopServer()
{
// Listen on all Networkinterfaces
foreach (QTcpServer *s, m_serverList) {
qCDebug(dcConnection) << "Closing Tcp server on" << s->serverAddress().toString() << s->serverPort();
QUuid uuid = m_serverList.key(s);
s->close();
m_serverList.take(uuid)->deleteLater();

View File

@ -167,5 +167,4 @@ void TransportInterface::validateMessage(const QUuid &clientId, const QByteArray
emit dataAvailable(clientId, targetNamespace, method, message);
}
}

View File

@ -131,6 +131,7 @@ WebServer::WebServer(const QSslConfiguration &sslConfiguration, QObject *parent)
/*! Destructor of this \l{WebServer}. */
WebServer::~WebServer()
{
qCDebug(dcApplication) << "Shutting down webserver";
this->close();
}

View File

@ -85,6 +85,7 @@ WebSocketServer::WebSocketServer(const QSslConfiguration &sslConfiguration, QObj
/*! Destructor of this \l{WebSocketServer}. */
WebSocketServer::~WebSocketServer()
{
qCDebug(dcApplication) << "Shutting down websocket server";
stopServer();
}
@ -217,7 +218,6 @@ bool WebSocketServer::startServer()
*/
bool WebSocketServer::stopServer()
{
qCDebug(dcConnection) << "Stopping websocket server";
m_server->close();
delete m_server;
m_server = 0;