[systemd-devel] sd_watchdog_enabled: how to use when forking process?

Jérémy Rosen jeremy.rosen at smile.fr
Mon Jan 22 08:49:08 UTC 2018


Alternatively, NotifyAccess= in [Service allows other processes to ping 
the watchdog, but Simon is right...

forking is not needed for systemd.

On 19/01/2018 18:41, Simon McVittie wrote:
> On Fri, 19 Jan 2018 at 17:22:51 +0000, philip is hungry wrote:
>> however if i run the forkme function (to put process in the background) it
>> behaves as follows:
>>
>> Jan 18 15:06:25 thinkpad waitonly[11228]: Return from forkme = 11228
>> Jan 18 15:06:25 thinkpad waitonly[11228]: Return from lockme = 0
>> Jan 18 15:06:25 thinkpad waitonly[11228]: PID to compare with watchdog_pid:
>> 11228
> systemd tells your service which process it expects to be sending
> keepalives ($WATCHDOG_PID), and only accepts keepalives from that
> process. The forked child process has some other process ID, so
> sd_watchdog_enabled() returns false for it.
>
> If you want to use the watchdog, don't fork and go to the background: it's
> unnecessary for systemd services. To notify systemd that your process
> is ready to receive requests (which was done via the double-fork trick
> in init-script-based init systems), a daemon that natively supports
> systemd features can use sd_notify() and Type=notify.
>
> If you want your service to continue to support non-systemd init systems,
> you might want to add a --no-fork command-line option and make the systemd
> unit's ExecStart use that option. For example, that's how it works for
> dbus-daemon, which needs to continue to default to forking for
> compatibility with what it does on non-Linux OSs or non-systemd init.
> Or, if your service will only ever run under systemd, you can make it
> not fork/background itself at all.
>
>      smcv
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/systemd-devel

-- 
SMILE <http://www.smile.eu/>

20 rue des Jardins
92600 Asnières-sur-Seine

	
*Jérémy ROSEN*
Architecte technique
Responsable de l'expertise Smile-ECS

email jeremy.rosen at smile.fr <mailto:jeremy.rosen at smile.fr>
phone +33141402967
url http://www.smile.eu

Twitter <https://twitter.com/GroupeSmile> Facebook 
<https://www.facebook.com/smileopensource> LinkedIn 
<https://www.linkedin.com/company/smile> Github 
<https://github.com/Smile-SA>


Découvrez l’univers Smile, rendez-vous sur smile.eu 
<http://smile.eu/?utm_source=signature&utm_medium=email&utm_campaign=signature>

eco Pour la planète, n'imprimez ce mail que si c'est nécessaire
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20180122/85109039/attachment-0001.html>


More information about the systemd-devel mailing list