diff --git a/asteroidsyncservice/CMakeLists.txt b/asteroidsyncservice/CMakeLists.txt index b4c7349..a2a8e5f 100644 --- a/asteroidsyncservice/CMakeLists.txt +++ b/asteroidsyncservice/CMakeLists.txt @@ -1,7 +1,9 @@ cmake_minimum_required(VERSION 3.15) find_package(Qt6 COMPONENTS DBus Qml) if (NOT Qt6_FOUND) - find_package(Qt5 5.15 COMPONENTS DBus Qml REQUIRED) + find_package(Qt5 5.12 COMPONENTS DBus Qml REQUIRED) + add_library(Qt::DBus ALIAS Qt5::DBus) + add_library(Qt::Qml ALIAS Qt5::Qml) endif() add_library(asteroidsyncserviceplugin SHARED syncservice_plugin.cpp watch.cpp watches.cpp ${PLATFORM_SOURCE_DIR}/servicecontrol.cpp) set_target_properties(asteroidsyncserviceplugin PROPERTIES AUTOMOC ON) @@ -9,8 +11,10 @@ target_include_directories(asteroidsyncserviceplugin PRIVATE ${PROJECT_BINARY_DI target_compile_features(asteroidsyncserviceplugin PUBLIC cxx_std_17) target_link_libraries(asteroidsyncserviceplugin PRIVATE Qt::DBus Qt::Qml) + # Installation paths -get_target_property(REAL_QMAKE_EXECUTABLE Qt::qmake IMPORTED_LOCATION) +#get_target_property(REAL_QMAKE_EXECUTABLE Qt::qmake IMPORTED_LOCATION) +find_program(REAL_QMAKE_EXECUTABLE NAMES qmake6 qmake) if (NOT QT_INSTALL_QML) execute_process(COMMAND "${REAL_QMAKE_EXECUTABLE}" -query QT_INSTALL_QML diff --git a/asteroidsyncservice/platforms/ubuntutouch/servicecontrol.cpp b/asteroidsyncservice/platforms/ubuntutouch/servicecontrol.cpp index 30c3d94..ce33dc0 100644 --- a/asteroidsyncservice/platforms/ubuntutouch/servicecontrol.cpp +++ b/asteroidsyncservice/platforms/ubuntutouch/servicecontrol.cpp @@ -30,7 +30,7 @@ bool ServiceControl::serviceFileInstalled() const qDebug() << "Service name not set."; return false; } - QFile f(QDir::homePath() + "/.config/upstart/" + m_serviceName + ".conf"); + QFile f(QDir::homePath() + "/.config/systemd/user/"+ m_serviceName + ".service"); return f.exists(); } @@ -41,7 +41,7 @@ bool ServiceControl::installServiceFile() return false; } - QFile f(QDir::homePath() + "/.config/upstart/" + m_serviceName + ".conf"); + QFile f(QDir::homePath() + "/.config/systemd/user/"+ m_serviceName + ".service"); if (f.exists()) { qDebug() << "Service file already existing..."; return false; @@ -56,11 +56,20 @@ bool ServiceControl::installServiceFile() // Try to replace version with "current" to be more robust against updates appDir.replace(QRegExp("[0-9].[0-9].[0-9]"), "current"); - f.write("start on started unity8\n"); - f.write("pre-start script\n"); - f.write(" initctl set-env LD_LIBRARY_PATH=" + appDir.toUtf8() + "/usr/bin/../:$LD_LIBRARY_PATH\n"); - f.write("end script\n"); - f.write("exec " + appDir.toUtf8() + "/usr/bin/" + m_serviceName.toUtf8() + "\n"); + f.write("[Unit]\n"); + f.write("Description=asteroidsync\n"); + f.write("After=graphical.target\n"); + f.write("[Service]\n"); + f.write("ExecStart=" + appDir.toUtf8() + "/usr/bin/" + m_serviceName.toUtf8() + "\n"); + + f.write("Restart=always\n"); + f.write("RestartSec=5\n"); + f.write("Environment=LD_LIBRARY_PATH=" + appDir.toUtf8() + "/usr/bin/../:$LD_LIBRARY_PATH\n"); + f.write("Environment=HOME=%h XDG_CONFIG_HOME=/home/%u/.config DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/%U/bus XDG_RUNTIME_DIR=/run/user/%U\n"); + f.write("[Install]\n"); + f.write("WantedBy=default.target\n"); + + f.close(); return true; } @@ -71,18 +80,18 @@ bool ServiceControl::removeServiceFile() qDebug() << "Service name not set."; return false; } - QFile f(QDir::homePath() + "/.config/upstart/" + m_serviceName + ".conf"); + QFile f(QDir::homePath() + "/.config/systemd/user/"+ m_serviceName + ".service"); return f.remove(); } bool ServiceControl::serviceRunning() const { QProcess p; - p.start("initctl", {"status", m_serviceName}); + p.start("systemctl", {"is-active", "--user", m_serviceName}); p.waitForFinished(); QByteArray output = p.readAll(); qDebug() << output; - return output.contains("running"); + return output.contains("active"); } bool ServiceControl::setServiceRunning(bool running) @@ -97,21 +106,21 @@ bool ServiceControl::setServiceRunning(bool running) bool ServiceControl::startService() { - qDebug() << "start service"; - int ret = QProcess::execute("start", {m_serviceName}); + int ret = QProcess::execute("systemctl", {"start", "--user", m_serviceName}); + qDebug() << "start service" << ret; return ret == 0; } bool ServiceControl::stopService() { - qDebug() << "stop service"; - int ret = QProcess::execute("stop", {m_serviceName}); + int ret = QProcess::execute("systemctl", {"stop", "--user", m_serviceName}); + qDebug() << "stop service" << ret; return ret == 0; } bool ServiceControl::restartService() { - qDebug() << "restart service"; - int ret = QProcess::execute("restart", {m_serviceName}); + int ret = QProcess::execute("systemctl", {"restart", "--user", m_serviceName}); + qDebug() << "restart service" << ret; return ret == 0; } diff --git a/asteroidsyncserviced/CMakeLists.txt b/asteroidsyncserviced/CMakeLists.txt index 3bb1e81..b405d67 100644 --- a/asteroidsyncserviced/CMakeLists.txt +++ b/asteroidsyncserviced/CMakeLists.txt @@ -2,6 +2,10 @@ cmake_minimum_required(VERSION 3.15) find_package(Qt6 COMPONENTS Core Bluetooth DBus Qml) if (NOT Qt6_FOUND) find_package(Qt5 COMPONENTS Core Bluetooth DBus Qml REQUIRED) + add_library(Qt::Core ALIAS Qt5::Core) + add_library(Qt::Bluetooth ALIAS Qt5::Bluetooth) + add_library(Qt::DBus ALIAS Qt5::DBus) + add_library(Qt::Qml ALIAS Qt5::Qml) endif() add_subdirectory(libasteroid)