From cfb6b41c57484a9c8c96ae5ee1cc2be60cf56b05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Sat, 5 Dec 2015 00:29:52 +0100 Subject: [PATCH] add systemd --- data/logrotate/guhd | 8 ++++---- data/systemd/guhd.service | 14 ++++++++++++++ debian/guhd.1 | 23 ++++++++++++++++++++--- debian/guhd.install | 1 - server/guhservice.cpp | 16 ++++++++++++---- server/guhservice.h | 1 + server/main.cpp | 18 +++++++++--------- 7 files changed, 60 insertions(+), 21 deletions(-) create mode 100644 data/systemd/guhd.service diff --git a/data/logrotate/guhd b/data/logrotate/guhd index 88de1ef5..b80ba4f7 100644 --- a/data/logrotate/guhd +++ b/data/logrotate/guhd @@ -1,11 +1,11 @@ /var/log/guhd.log { - weekly - rotate 5 - size 200M + daily + dateext + rotate 7 + size 10M compress delaycompress missingok notifempty create 644 root root } - diff --git a/data/systemd/guhd.service b/data/systemd/guhd.service new file mode 100644 index 00000000..2fb4a2b3 --- /dev/null +++ b/data/systemd/guhd.service @@ -0,0 +1,14 @@ +[Unit] +Description=guhd - IoT server +Documentation=https://github.com/guh/guh/wiki +After=network.target syslog.target + +[Service] +ExecStart=/usr/bin/guhd --print-all +StandardOutput=journal +StandardError=journal +Restart=on-failure +Type=forking + +[Install] +WantedBy=multi-user.target diff --git a/debian/guhd.1 b/debian/guhd.1 index 85bbbcbd..5e6ca2da 100644 --- a/debian/guhd.1 +++ b/debian/guhd.1 @@ -23,6 +23,10 @@ Displays version information. \fB\-n\fR, \fB\-\-no\-daemon\fR Run guhd in the foreground, not as daemon. .TP +\fB\-p\fR, \fB\-\-print\-all\fR +Enables all debug categories. This parameter overrides all debug +category parameters. +.TP \fB\-d\fR, \fB\-\-debug\fR, \fB\<[No\]DebugCategory>\fR Debug categories to enable. In order to disable a category which is enabled by default, you can add \"No\" to the category. Warnings from all @@ -72,8 +76,21 @@ and enable debug messages for JsonRpc and LogEngine: .IP $ guhd -n -d NoDeviceManager -d JsonRpc -d LogEngine .SH FILES -.TP -The settings of the guh server can be found in \fI/etc/guh/guhd.conf\fR +The server config file: \fI/etc/guh/guhd.conf\fR +.br +The devices config file: \fI/etc/guh/devices.conf\fR +.br +The rules config file: \fI/etc/guh/rules.conf\fR +.br +The plugins config file: \fI/etc/guh/plugins.conf\fR +.br +The log file: \fI/var/log/guhd.log\fR +.br +The logging database: \fI/var/log/guhd.sqlite\fR +.br +The systemd unit file: \fI/etc/systemd/system/guhd.service\fR +.br +The plugins directory: \fI/usr/lib/guh/plugins/\fR .SH SEE ALSO Full developer documentation at: .br @@ -81,7 +98,7 @@ Wiki on github: .SH "REPORTING BUGS" Issue tracker on github: .br -How to report bugs can: +How to report bugs: .SH AUTHOR Written by Simon Stürz and Michael Zanetti .SH COPYRIGHT diff --git a/debian/guhd.install b/debian/guhd.install index 1072265b..1311612f 100644 --- a/debian/guhd.install +++ b/debian/guhd.install @@ -1,4 +1,3 @@ usr/bin/guhd -data/init/* /etc/init.d data/config/guhd.conf /etc/guh/ data/logrotate/guhd /etc/logrotate.d/ diff --git a/server/guhservice.cpp b/server/guhservice.cpp index dbc2116e..abcbb79e 100644 --- a/server/guhservice.cpp +++ b/server/guhservice.cpp @@ -31,7 +31,6 @@ \sa QtService */ - #include #include "guhservice.h" #include "loggingcategories.h" @@ -40,16 +39,15 @@ namespace guhserver { /*! Constructs the forked guhd application with the given argument count \a argc and argument vector \a argv. */ GuhService::GuhService(int argc, char **argv): - QtService(argc, argv, "guh daemon") + QtService(argc, argv, "guh - IoT server") { - qDebug() << "guhd started as daemon."; application()->setOrganizationName("guh"); application()->setApplicationName("guhd"); application()->setApplicationVersion(GUH_VERSION_STRING); close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO); - setServiceDescription("guh daemon"); + setServiceDescription("guh - IoT server"); setServiceFlags(QtServiceBase::CanBeSuspended); } @@ -61,7 +59,17 @@ GuhService::~GuhService() /*! Starts the forked guhd application. */ 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) << "====================================="; +} + } diff --git a/server/guhservice.h b/server/guhservice.h index 8b7b8e6d..2903e737 100644 --- a/server/guhservice.h +++ b/server/guhservice.h @@ -37,6 +37,7 @@ public: protected: void start(); + void stop(); }; } diff --git a/server/main.cpp b/server/main.cpp index b2e077fc..75304ac5 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -60,26 +60,26 @@ void consoleLogHandler(QtMsgType type, const QMessageLogContext& context, const QString timeString = QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss.zzz"); switch (type) { case QtDebugMsg: - messageString = QString("I %1 | %2: %3").arg(timeString).arg(context.category).arg(message); - fprintf(stdout, "I | %s: %s\n", context.category, message.toUtf8().data()); + messageString = QString(" I %1 | %2: %3").arg(timeString).arg(context.category).arg(message); + fprintf(stdout, " I | %s: %s\n", context.category, message.toUtf8().data()); break; case QtWarningMsg: - messageString = QString("W %1 | %2: %3").arg(timeString).arg(context.category).arg(message); - fprintf(stdout, "W | %s: %s\n", context.category, message.toUtf8().data()); + messageString = QString(" W %1 | %2: %3").arg(timeString).arg(context.category).arg(message); + fprintf(stdout, " W | %s: %s\n", context.category, message.toUtf8().data()); break; case QtCriticalMsg: - messageString = QString("C %1 | %2: %3").arg(timeString).arg(context.category).arg(message); - fprintf(stdout, "C | %s: %s\n", context.category, message.toUtf8().data()); + messageString = QString(" C %1 | %2: %3").arg(timeString).arg(context.category).arg(message); + fprintf(stdout, " C | %s: %s\n", context.category, message.toUtf8().data()); break; case QtFatalMsg: - messageString = QString("F %1 | %2: %3").arg(timeString).arg(context.category).arg(message); - fprintf(stdout, "F | %s: %s\n", context.category, message.toUtf8().data()); + messageString = QString(" F %1 | %2: %3").arg(timeString).arg(context.category).arg(message); + fprintf(stdout, " F | %s: %s\n", context.category, message.toUtf8().data()); break; } QFile logFile(GuhSettings::consoleLogPath()); if (!logFile.open(QIODevice::WriteOnly | QIODevice::Append)) { - fprintf(stdout, "W | Application: Could not open logfile.\n"); + fprintf(stdout, " W | Application: Could not open logfile.\n"); return; } QTextStream textStream(&logFile);