From 26fe64fdfbf6228b35746a4467dbcb972abc87a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Wed, 15 Aug 2018 17:29:02 +0200 Subject: [PATCH] Add systemd service file --- .gitignore | 2 ++ client/main.cpp | 16 ++++++++++++++-- client/proxyclient.cpp | 17 +++++++++++++++++ client/proxyclient.h | 3 ++- debian/control | 1 + debian/nymea-remoteproxy.service | 16 ++++++++++++++++ debian/rules | 2 +- 7 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 debian/nymea-remoteproxy.service diff --git a/.gitignore b/.gitignore index 80d3151..5b30fa3 100644 --- a/.gitignore +++ b/.gitignore @@ -75,3 +75,5 @@ coverage-html client/nymea-remoteproxy-client tests/test-offline/nymea-remoteproxy-tests-offline tests/test-online/nymea-remoteproxy-tests-online +.crossbuilder/ +source_repository/ diff --git a/client/main.cpp b/client/main.cpp index ab20d0c..7204f4b 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -17,8 +17,8 @@ int main(int argc, char *argv[]) QCommandLineParser parser; parser.addHelpOption(); parser.addVersionOption(); - parser.setApplicationDescription(QString("\nThe nymea remote proxy server. This server allowes nymea-cloud users and " - "registered nymea deamons to establish a tunnel connection.\n\n" + parser.setApplicationDescription(QString("\nThe nymea remote proxy server client application. This client allowes to test " + "a server application as client perspective.\n\n" "Server version: %1\n" "API version: %2\n\n" "Copyright %3 2018 Simon Stürz \n") @@ -27,9 +27,19 @@ int main(int argc, char *argv[]) .arg(QChar(0xA9))); + + QCommandLineOption tokenOption(QStringList() << "t" << "token", "The AWS token for authentication.", "token"); parser.addOption(tokenOption); + QCommandLineOption addressOption(QStringList() << "a" << "address", "The proxy server host address. Default 127.0.0.1", "address"); + addressOption.setDefaultValue("127.0.0.1"); + parser.addOption(addressOption); + + QCommandLineOption portOption(QStringList() << "p" << "port", "The proxy server port. Default 1212", "port"); + portOption.setDefaultValue("1212"); + parser.addOption(portOption); + parser.process(application); if (!parser.isSet(tokenOption)) { @@ -38,6 +48,8 @@ int main(int argc, char *argv[]) } ProxyClient client; + client.setHostAddress(QHostAddress(parser.value(addressOption))); + client.setPort(parser.value(portOption).toInt()); client.start(parser.value(tokenOption)); return application.exec(); diff --git a/client/proxyclient.cpp b/client/proxyclient.cpp index 0eccf1f..7f3aac7 100644 --- a/client/proxyclient.cpp +++ b/client/proxyclient.cpp @@ -9,9 +9,20 @@ ProxyClient::ProxyClient(QObject *parent) : connect(m_connection, &RemoteProxyConnection::ready, this, &ProxyClient::onClientReady); connect(m_connection, &RemoteProxyConnection::authenticated, this, &ProxyClient::onAuthenticationFinished); connect(m_connection, &RemoteProxyConnection::errorOccured, this, &ProxyClient::onErrorOccured); + connect(m_connection, &RemoteProxyConnection::disconnected, this, &ProxyClient::onClientDisconnected); } +void ProxyClient::setHostAddress(const QHostAddress &hostAddress) +{ + m_hostAddress = hostAddress; +} + +void ProxyClient::setPort(int port) +{ + m_port = port; +} + void ProxyClient::onErrorOccured(RemoteProxyConnection::Error error) { qDebug() << "Error occured" << error << m_connection->errorString(); @@ -27,6 +38,12 @@ void ProxyClient::onAuthenticationFinished() qDebug() << "Authentication finished."; } +void ProxyClient::onClientDisconnected() +{ + qDebug() << "Disconnected from" << m_connection; + exit(1); +} + void ProxyClient::start(const QString &token) { m_token = token; diff --git a/client/proxyclient.h b/client/proxyclient.h index 74c54f9..ae50634 100644 --- a/client/proxyclient.h +++ b/client/proxyclient.h @@ -14,7 +14,7 @@ public: explicit ProxyClient(QObject *parent = nullptr); void setHostAddress(const QHostAddress &hostAddress); - void setPort(const int &port); + void setPort(int port); private: QString m_token; @@ -30,6 +30,7 @@ private slots: void onErrorOccured(RemoteProxyConnection::Error error); void onClientReady(); void onAuthenticationFinished(); + void onClientDisconnected(); public slots: void start(const QString &token); diff --git a/debian/control b/debian/control index 0fdaeeb..696e14f 100644 --- a/debian/control +++ b/debian/control @@ -3,6 +3,7 @@ Section: utils Priority: options Maintainer: Simon Stürz Build-depends: debhelper (>= 0.0.0), + dh-systemd, libqt5websockets5-dev, Standards-Version: 3.9.3 diff --git a/debian/nymea-remoteproxy.service b/debian/nymea-remoteproxy.service new file mode 100644 index 0000000..af023ee --- /dev/null +++ b/debian/nymea-remoteproxy.service @@ -0,0 +1,16 @@ +[Unit] +Description=nymea-remoteproxy - Proxy server for the nymea remote connection +Documentation=https://gitlab.nymea.io/cloud/nymea-remoteproxy +After=network.target +Wants=network-online.target + +[Service] +Type=simple +ExecStart=/usr/bin/nymea-remoteproxy -c /etc/nymea/nymea-remoteproxy.conf +StandardOutput=journal +StandardError=journal +Restart=on-failure + +[Install] +WantedBy=multi-user.target + diff --git a/debian/rules b/debian/rules index 0ed2311..424e499 100755 --- a/debian/rules +++ b/debian/rules @@ -21,4 +21,4 @@ override_dh_auto_clean: rm -rf $(PREPROCESS_FILES:.in=) %: - dh $@ + dh $@ --with systemd