Allows to notify systemd whether kwin is still running and possibly restart the service if it stops responding. Use Type=notify-reload to watch the kwin service. This will make it so we receive SIGHUP rather than SIGTERM on the wrapper which we can handle gracefully and stop the kwin process and restart as expected. https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html Signed-off-by: Victoria Fischer <victoria.fischer@mbition.io>wilder/Plasma/6.2
parent
aac5d562fb
commit
71ade59f4b
5 changed files with 103 additions and 12 deletions
@ -0,0 +1,62 @@ |
||||
/*
|
||||
KWin - the KDE window manager |
||||
This file is part of the KDE project. |
||||
|
||||
SPDX-FileCopyrightText: 2024 Aleix Pol i Gonzalez <aleix.pol_gonzalez@mbition.io> |
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later |
||||
*/ |
||||
|
||||
#include "utils/common.h" |
||||
#include <QCoreApplication> |
||||
#include <QTimer> |
||||
#include <systemd/sd-daemon.h> |
||||
|
||||
class Watchdog : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
Watchdog(QObject *parent) |
||||
: QObject(parent) |
||||
{ |
||||
bool ok; |
||||
const std::chrono::microseconds watchdogIntervalInUs((qgetenv("WATCHDOG_USEC").toUInt(&ok) * 3) / 4); |
||||
if (!ok) { |
||||
qCInfo(KWIN_CORE) << "Watchdog: disabled, not running on a systemd environment or watchdog is not set up. No WATCHDOG_USEC."; |
||||
deleteLater(); |
||||
return; |
||||
} |
||||
m_onBehalf = qgetenv("WATCHDOG_PID").toUInt(&ok); |
||||
if (!ok) { |
||||
qCInfo(KWIN_CORE) << "Watchdog: disabled, not running on a systemd environment or watchdog is not set up. No WATCHDOG_PID."; |
||||
deleteLater(); |
||||
return; |
||||
} |
||||
qunsetenv("WATCHDOG_USEC"); |
||||
qunsetenv("WATCHDOG_PID"); |
||||
auto t = new QTimer(this); |
||||
t->setInterval(std::chrono::duration_cast<std::chrono::milliseconds>(watchdogIntervalInUs)); |
||||
t->setSingleShot(false); |
||||
qCInfo(KWIN_CORE) << "Watchdog: enabled. Interval:" << watchdogIntervalInUs << t->intervalAsDuration(); |
||||
|
||||
sd_pid_notify(m_onBehalf, 0, "READY=1"); // If service Type=notify the service is only considered ready once we send this
|
||||
qCInfo(KWIN_CORE) << "Watchdog: Notified as ready"; |
||||
|
||||
connect(t, &QTimer::timeout, this, [this] { |
||||
sd_pid_notify(m_onBehalf, 0, "WATCHDOG=1"); |
||||
}); |
||||
t->start(); |
||||
} |
||||
|
||||
private: |
||||
pid_t m_onBehalf = 0; |
||||
}; |
||||
|
||||
static void setupWatchdog() |
||||
{ |
||||
new Watchdog(QCoreApplication::instance()); |
||||
} |
||||
|
||||
Q_COREAPP_STARTUP_FUNCTION(setupWatchdog) |
||||
|
||||
#include "watchdog.moc" |
||||
Loading…
Reference in new issue