summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2014-06-27 22:00:56 +0200
committerFlorent Le Coz <louiz@louiz.org>2014-06-30 01:03:07 +0200
commit70ebbae15e7432d56bf23751e548836b388781f6 (patch)
tree459a7e4f9359347c0773ae9b26e36fd2817f7fcb
parenta165e5924012c82d2598495d962597ae896e9cf7 (diff)
downloadbiboumi-70ebbae15e7432d56bf23751e548836b388781f6.tar.gz
biboumi-70ebbae15e7432d56bf23751e548836b388781f6.tar.bz2
biboumi-70ebbae15e7432d56bf23751e548836b388781f6.tar.xz
biboumi-70ebbae15e7432d56bf23751e548836b388781f6.zip
Regularly send a notification for the systemd watchdog
-rw-r--r--src/xmpp/xmpp_component.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/xmpp/xmpp_component.cpp b/src/xmpp/xmpp_component.cpp
index b855d67..1e8f9e0 100644
--- a/src/xmpp/xmpp_component.cpp
+++ b/src/xmpp/xmpp_component.cpp
@@ -1,3 +1,4 @@
+#include <utils/timed_events.hpp>
#include <utils/scopeguard.hpp>
#include <utils/tolower.hpp>
#include <logger/logger.hpp>
@@ -273,6 +274,16 @@ void XmppComponent::handle_handshake(const Stanza& stanza)
log_info("Authenticated with the XMPP server");
#ifdef SYSTEMDDAEMON_FOUND
sd_notify(0, "READY=1");
+ // Install an event that sends a keepalive to systemd. If biboumi crashes
+ // or hangs for too long, systemd will restart it.
+ uint64_t usec;
+ if (sd_watchdog_enabled(0, &usec) > 0)
+ {
+ std::chrono::microseconds delay(usec);
+ TimedEventsManager::instance().add_event(TimedEvent(
+ std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::microseconds(usec / 2)),
+ []() { sd_notify(0, "WATCHDOG=1"); }));
+ }
#endif
}