From patchwork Mon May 2 15:50:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Perrudin X-Patchwork-Id: 34158 Received: from localhost ([127.0.0.1] helo=www.linuxtv.org) by www.linuxtv.org with esmtp (Exim 4.84_2) (envelope-from ) id 1axG7c-0004lY-OO; Mon, 02 May 2016 15:50:56 +0000 Received: from bouncing.tu-berlin.de ([130.149.7.34]) by www.linuxtv.org with esmtp (Exim 4.84_2) (envelope-from ) id 1axG7Z-0004lF-0D for vdr@linuxtv.org; Mon, 02 May 2016 15:50:54 +0000 X-tubIT-Incoming-IP: 46.105.79.46 Received: from 10.mo179.mail-out.ovh.net ([46.105.79.46]) by mail.tu-berlin.de (exim-4.76/mailfrontend-8) with esmtps [UNKNOWN:AES256-GCM-SHA384:256] for id 1axG7X-0002oW-lK; Mon, 02 May 2016 17:50:52 +0200 Received: from player711.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo179.mail-out.ovh.net (Postfix) with ESMTP id A1C27FFB6FA for ; Mon, 2 May 2016 17:50:50 +0200 (CEST) Received: from myhost.at.mynet (gob75-4-82-226-175-12.fbx.proxad.net [82.226.175.12]) (Authenticated sender: mail_dev@ekass.net) by player711.ha.ovh.net (Postfix) with ESMTPSA id 7517B380068 for ; Mon, 2 May 2016 17:50:50 +0200 (CEST) Date: Mon, 2 May 2016 17:50:41 +0200 From: Marc Perrudin To: VDR Mailing List Message-ID: <20160502175041.69d82f2e@myhost.at.mynet> X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.29; i686-pc-linux-gnu) MIME-Version: 1.0 X-Ovh-Tracer-Id: 8600186441210686044 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeekkedrledugdelgecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjnecuuegrihhlohhuthemuceftddtnecu X-PMX-Version: 6.0.0.2142326, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2016.5.2.154216 X-PMX-Spam: Gauge=IIIIIIII, Probability=8%, Report=' HTML_00_01 0.05, HTML_00_10 0.05, MIME_TEXT_ONLY_MP_MIXED 0.05, MSGID_ADDED_BY_MTA 0.05, BODYTEXTP_SIZE_3000_LESS 0, BODY_SIZE_2000_2999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, NO_CTA_URI_FOUND 0, NO_URI_FOUND 0, NO_URI_HTTPS 0, SUBJ_PHRASE_WATCHES 0, __CT 0, __CTYPE_HAS_BOUNDARY 0, __CTYPE_MULTIPART 0, __CTYPE_MULTIPART_MIXED 0, __HAS_ATTACHMENT 0, __HAS_ATTACHMENT1 0, __HAS_FROM 0, __HAS_MSGID 0, __HAS_X_MAILER 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __SANE_MSGID 0, __SUBJ_ALPHA_END 0, __TO_MALFORMED_2 0' X-LSpam-Score: -1.3 (-) X-LSpam-Report: No, score=-1.3 required=5.0 tests=RCVD_IN_DNSWL_MED=-2.3, SPF_SOFTFAIL=0.972 autolearn=ham autolearn_force=no Subject: [vdr] [PATCH] Systemd watchdog support X-BeenThere: vdr@linuxtv.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: VDR Mailing List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: VDR Mailing List Errors-To: vdr-bounces@linuxtv.org Sender: "vdr" Hi, Here is a patch I use to enable systemd watchdog support in VDR. It doesn't replace the internal watchdog, it just allow setting WatchdogSec directive in service file so if VDR watchdog is unable to exit, systemd take care of restarting it. I use this patch against VDR 2.2.0 without problem for few mouths (I set systemd watchdog to the same value than VDR watchdog to avoid interference between them). If you are interested to include it, I can see if it apply to dev branch, but there is only ~20 lines so it should apply without modification. Note that the first and last chunk are only systemd notifications about the current state of VDR and they can be removed if needed. Regards, Marc. diff -Naur a/vdr.c b/vdr.c --- a/vdr.c 2015-02-10 15:13:12.000000000 +0100 +++ b/vdr.c 2016-05-02 13:37:43.180638765 +0200 @@ -170,6 +170,9 @@ // Something terrible must have happened that prevented the 'alarm()' from // being called in time, so let's get out of here: esyslog("PANIC: watchdog timer expired - exiting!"); +#ifdef SDNOTIFY + sd_notify(0, "STOPPING=1\nSTATUS=PANIC"); +#endif exit(1); } @@ -234,6 +237,10 @@ #if defined(VDR_USER) VdrUser = VDR_USER; #endif +#ifdef SDNOTIFY + time_t SdWatchdog; + int SdWatchdogTimeout = 0; +#endif cArgs *Args = NULL; if (argc == 1) { @@ -904,6 +911,16 @@ } #ifdef SDNOTIFY + if (sd_watchdog_enabled(0, NULL) > 0) { + uint64_t timeout; + SdWatchdog = time(NULL); + sd_watchdog_enabled(0, &timeout); + SdWatchdogTimeout = (int)timeout/1000000; + dsyslog("SD_WATCHDOG enabled with timeout set to %d seconds", SdWatchdogTimeout); + } + + // Startup notification: + sd_notify(0, "READY=1\nSTATUS=Ready"); #endif @@ -958,6 +975,14 @@ dsyslog("max. latency time %d seconds", MaxLatencyTime); } } +#ifdef SDNOTIFY + // Ping systemd watchdog when half the timeout is elapsed: + if (SdWatchdogTimeout && (Now - SdWatchdog)*2 > SdWatchdogTimeout) { + sd_notify(0, "WATCHDOG=1"); + SdWatchdog = Now; + dsyslog("SD_WATCHDOG ping"); + } +#endif // Handle channel and timer modifications: if (!Channels.BeingEdited() && !Timers.BeingEdited()) { int modified = Channels.Modified(); @@ -1494,5 +1519,11 @@ closelog(); if (HasStdin) tcsetattr(STDIN_FILENO, TCSANOW, &savedTm); +#ifdef SDNOTIFY + if (ShutdownHandler.GetExitCode() == 2) + sd_notify(0, "STOPPING=1\nSTATUS=Startup failed, exiting"); + else + sd_notify(0, "STOPPING=1\nSTATUS=Exiting"); +#endif return ShutdownHandler.GetExitCode(); }