chiark / gitweb /
118b8b8bcc86d94f04b4d40eb9d91be78aa60053
[elogind.git] / man / sd_watchdog_enabled.xml
1 <?xml version='1.0'?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3   "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4
5 <!--
6   This file is part of elogind.
7   SPDX-License-Identifier: LGPL-2.1+
8
9
10   Copyright 2013 Lennart Poettering
11 -->
12
13 <refentry id="sd_watchdog_enabled"
14   xmlns:xi="http://www.w3.org/2001/XInclude">
15
16   <refentryinfo>
17     <title>sd_watchdog_enabled</title>
18     <productname>elogind</productname>
19
20     <authorgroup>
21       <author>
22         <contrib>Developer</contrib>
23         <firstname>Lennart</firstname>
24         <surname>Poettering</surname>
25         <email>lennart@poettering.net</email>
26       </author>
27     </authorgroup>
28   </refentryinfo>
29
30   <refmeta>
31     <refentrytitle>sd_watchdog_enabled</refentrytitle>
32     <manvolnum>3</manvolnum>
33   </refmeta>
34
35   <refnamediv>
36     <refname>sd_watchdog_enabled</refname>
37     <refpurpose>Check whether the service manager expects watchdog keep-alive notifications from a service</refpurpose>
38   </refnamediv>
39
40   <refsynopsisdiv>
41     <funcsynopsis>
42       <funcsynopsisinfo>#include &lt;elogind/sd-daemon.h&gt;</funcsynopsisinfo>
43
44       <funcprototype>
45         <funcdef>int <function>sd_watchdog_enabled</function></funcdef>
46         <paramdef>int <parameter>unset_environment</parameter></paramdef>
47         <paramdef>uint64_t *<parameter>usec</parameter></paramdef>
48       </funcprototype>
49     </funcsynopsis>
50   </refsynopsisdiv>
51
52   <refsect1>
53     <title>Description</title>
54     <para><function>sd_watchdog_enabled()</function> may be called by
55     a service to detect whether the service manager expects regular
56     keep-alive watchdog notification events from it, and the timeout
57     after which the manager will act on the service if it did not get
58     such a notification.</para>
59
60     <para>If the <varname>$WATCHDOG_USEC</varname> environment
61     variable is set, and the <varname>$WATCHDOG_PID</varname> variable
62     is unset or set to the PID of the current process, the service
63     manager expects notifications from this process. The manager will
64     usually terminate a service when it does not get a notification
65     message within the specified time after startup and after each
66     previous message. It is recommended that a daemon sends a
67     keep-alive notification message to the service manager every half
68     of the time returned here. Notification messages may be sent with
69     <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>
70     with a message string of <literal>WATCHDOG=1</literal>.</para>
71
72     <para>If the <parameter>unset_environment</parameter> parameter is
73     non-zero, <function>sd_watchdog_enabled()</function> will unset
74     the <varname>$WATCHDOG_USEC</varname> and
75     <varname>$WATCHDOG_PID</varname> environment variables before
76     returning (regardless of whether the function call itself
77     succeeded or not). Those variables are no longer inherited by
78     child processes. Further calls to
79     <function>sd_watchdog_enabled()</function> will also return with
80     zero.</para>
81
82     <para>If the <parameter>usec</parameter> parameter is non-NULL,
83     <function>sd_watchdog_enabled()</function> will write the timeout
84     in µs for the watchdog logic to it.</para>
85
86     <para>To enable service supervision with the watchdog logic, use
87     <varname>WatchdogSec=</varname> in service files. See
88     <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
89     for details.</para>
90
91     <para>Use
92     <citerefentry><refentrytitle>sd_event_set_watchdog</refentrytitle><manvolnum>3</manvolnum></citerefentry>
93     to enable automatic watchdog support in
94     <citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry>-based event loops.</para>
95   </refsect1>
96
97   <refsect1>
98     <title>Return Value</title>
99
100     <para>On failure, this call returns a negative errno-style error
101     code. If the service manager expects watchdog keep-alive
102     notification messages to be sent, &gt; 0 is returned, otherwise 0
103     is returned. Only if the return value is &gt; 0, the
104     <parameter>usec</parameter> parameter is valid after the
105     call.</para>
106   </refsect1>
107
108   <refsect1>
109     <title>Notes</title>
110
111     <xi:include href="libelogind-pkgconfig.xml" xpointer="pkgconfig-text"/>
112
113     <para>Internally, this function parses the
114     <varname>$WATCHDOG_PID</varname> and
115     <varname>$WATCHDOG_USEC</varname> environment variable. The call
116     will ignore these variables if <varname>$WATCHDOG_PID</varname>
117     does not contain the PID of the current process, under the
118     assumption that in that case, the variables were set for a
119     different process further up the process tree.</para>
120   </refsect1>
121
122   <refsect1>
123     <title>Environment</title>
124
125     <variablelist class='environment-variables'>
126       <varlistentry>
127         <term><varname>$WATCHDOG_PID</varname></term>
128
129         <listitem><para>Set by the system manager for supervised
130         process for which watchdog support is enabled, and contains
131         the PID of that process. See above for
132         details.</para></listitem>
133       </varlistentry>
134
135       <varlistentry>
136         <term><varname>$WATCHDOG_USEC</varname></term>
137
138         <listitem><para>Set by the system manager for supervised
139         process for which watchdog support is enabled, and contains
140         the watchdog timeout in µs. See above for
141         details.</para></listitem>
142       </varlistentry>
143     </variablelist>
144   </refsect1>
145
146   <refsect1>
147     <title>See Also</title>
148     <para>
149       <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
150       <citerefentry><refentrytitle>sd-daemon</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
151       <citerefentry><refentrytitle>daemon</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
152       <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
153       <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
154       <citerefentry><refentrytitle>sd_event_set_watchdog</refentrytitle><manvolnum>3</manvolnum></citerefentry>
155     </para>
156   </refsect1>
157
158 </refentry>