From 70ebbae15e7432d56bf23751e548836b388781f6 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Fri, 27 Jun 2014 22:00:56 +0200 Subject: Regularly send a notification for the systemd watchdog --- src/xmpp/xmpp_component.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 #include #include #include @@ -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::microseconds(usec / 2)), + []() { sd_notify(0, "WATCHDOG=1"); })); + } #endif } -- cgit v1.2.3