]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/systemd.timer.xml
Merge pull request #17693 from yuwata/tmpfiles-compress-nocow-on-btrfs
[thirdparty/systemd.git] / man / systemd.timer.xml
1 <?xml version='1.0'?>
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4 <!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
5
6 <refentry id="systemd.timer">
7 <refentryinfo>
8 <title>systemd.timer</title>
9 <productname>systemd</productname>
10 </refentryinfo>
11
12 <refmeta>
13 <refentrytitle>systemd.timer</refentrytitle>
14 <manvolnum>5</manvolnum>
15 </refmeta>
16
17 <refnamediv>
18 <refname>systemd.timer</refname>
19 <refpurpose>Timer unit configuration</refpurpose>
20 </refnamediv>
21
22 <refsynopsisdiv>
23 <para><filename><replaceable>timer</replaceable>.timer</filename></para>
24 </refsynopsisdiv>
25
26 <refsect1>
27 <title>Description</title>
28
29 <para>A unit configuration file whose name ends in
30 <literal>.timer</literal> encodes information about a timer
31 controlled and supervised by systemd, for timer-based
32 activation.</para>
33
34 <para>This man page lists the configuration options specific to
35 this unit type. See
36 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
37 for the common options of all unit configuration files. The common
38 configuration items are configured in the generic [Unit] and
39 [Install] sections. The timer specific configuration options are
40 configured in the [Timer] section.</para>
41
42 <para>For each timer file, a matching unit file must exist,
43 describing the unit to activate when the timer elapses. By
44 default, a service by the same name as the timer (except for the
45 suffix) is activated. Example: a timer file
46 <filename>foo.timer</filename> activates a matching service
47 <filename>foo.service</filename>. The unit to activate may be
48 controlled by <varname>Unit=</varname> (see below).</para>
49
50 <para>Note that in case the unit to activate is already active at the time the timer elapses it is not restarted,
51 but simply left running. There is no concept of spawning new service instances in this case. Due to this, services
52 with <varname>RemainAfterExit=</varname> set (which stay around continuously even after the service's main process
53 exited) are usually not suitable for activation via repetitive timers, as they will only be activated once, and
54 then stay around forever.</para>
55 </refsect1>
56
57 <refsect1>
58 <title>Automatic Dependencies</title>
59
60 <refsect2>
61 <title>Implicit Dependencies</title>
62
63 <para>The following dependencies are implicitly added:</para>
64
65 <itemizedlist>
66 <listitem><para>Timer units automatically gain a <varname>Before=</varname>
67 dependency on the service they are supposed to activate.</para></listitem>
68 </itemizedlist>
69 </refsect2>
70
71 <refsect2>
72 <title>Default Dependencies</title>
73
74 <para>The following dependencies are added unless <varname>DefaultDependencies=no</varname> is set:</para>
75
76 <itemizedlist>
77 <listitem><para>Timer units will automatically have dependencies of type <varname>Requires=</varname> and
78 <varname>After=</varname> on <filename>sysinit.target</filename>, a dependency of type <varname>Before=</varname>
79 on <filename>timers.target</filename>, as well as <varname>Conflicts=</varname> and <varname>Before=</varname> on
80 <filename>shutdown.target</filename> to ensure that they are stopped cleanly prior to system shutdown. Only timer
81 units involved with early boot or late system shutdown should disable the
82 <varname>DefaultDependencies=</varname> option.</para></listitem>
83
84 <listitem><para>Timer units with at least one <varname>OnCalendar=</varname> directive acquire a pair
85 of additional <varname>After=</varname> dependencies on <filename>time-set.target</filename> and
86 <filename>time-sync.target</filename>, in order to avoid being started before the system clock has
87 been correctly set. See
88 <citerefentry><refentrytitle>systemd.special</refentrytitle><manvolnum>7</manvolnum></citerefentry>
89 for details on these two targets.</para></listitem>
90 </itemizedlist>
91 </refsect2>
92 </refsect1>
93
94 <refsect1>
95 <title>Options</title>
96
97 <para>Timer files must include a [Timer] section, which carries
98 information about the timer it defines. The options specific to
99 the [Timer] section of timer units are the following:</para>
100
101 <variablelist class='unit-directives'>
102 <varlistentry>
103 <term><varname>OnActiveSec=</varname></term>
104 <term><varname>OnBootSec=</varname></term>
105 <term><varname>OnStartupSec=</varname></term>
106 <term><varname>OnUnitActiveSec=</varname></term>
107 <term><varname>OnUnitInactiveSec=</varname></term>
108
109 <listitem><para>Defines monotonic timers relative to different
110 starting points:</para>
111
112 <table>
113 <title>Settings and their starting points</title>
114
115 <tgroup cols='2'>
116 <thead>
117 <row>
118 <entry>Setting</entry>
119 <entry>Meaning</entry>
120 </row>
121 </thead>
122 <tbody>
123 <row>
124 <entry><varname>OnActiveSec=</varname></entry>
125 <entry>Defines a timer relative to the moment the timer unit itself is activated.</entry>
126 </row>
127 <row>
128 <entry><varname>OnBootSec=</varname></entry>
129 <entry>Defines a timer relative to when the machine was booted up. In containers, for the system manager instance, this is mapped to <varname>OnStartupSec=</varname>, making both equivalent.</entry>
130 </row>
131 <row>
132 <entry><varname>OnStartupSec=</varname></entry>
133 <entry>Defines a timer relative to when the service manager was first started. For system timer units this is very similar to <varname>OnBootSec=</varname> as the system service manager is generally started very early at boot. It's primarily useful when configured in units running in the per-user service manager, as the user service manager is generally started on first login only, not already during boot.</entry>
134 </row>
135 <row>
136 <entry><varname>OnUnitActiveSec=</varname></entry>
137 <entry>Defines a timer relative to when the unit the timer unit is activating was last activated.</entry>
138 </row>
139 <row>
140 <entry><varname>OnUnitInactiveSec=</varname></entry>
141 <entry>Defines a timer relative to when the unit the timer unit is activating was last deactivated.</entry>
142 </row>
143 </tbody>
144 </tgroup>
145 </table>
146
147 <para>Multiple directives may be combined of the same and of different types, in which case the timer
148 unit will trigger whenever any of the specified timer expressions elapse. For example, by combining
149 <varname>OnBootSec=</varname> and <varname>OnUnitActiveSec=</varname>, it is possible to define a
150 timer that elapses in regular intervals and activates a specific service each time. Moreover, both
151 monotonic time expressions and <varname>OnCalendar=</varname> calendar expressions may be combined in
152 the same timer unit.</para>
153
154 <para>The arguments to the directives are time spans
155 configured in seconds. Example: "OnBootSec=50" means 50s after
156 boot-up. The argument may also include time units. Example:
157 "OnBootSec=5h 30min" means 5 hours and 30 minutes after
158 boot-up. For details about the syntax of time spans, see
159 <citerefentry><refentrytitle>systemd.time</refentrytitle><manvolnum>7</manvolnum></citerefentry>.</para>
160
161 <para>If a timer configured with <varname>OnBootSec=</varname>
162 or <varname>OnStartupSec=</varname> is already in the past
163 when the timer unit is activated, it will immediately elapse
164 and the configured unit is started. This is not the case for
165 timers defined in the other directives.</para>
166
167 <para>These are monotonic timers, independent of wall-clock time and timezones. If the computer is
168 temporarily suspended, the monotonic clock generally pauses, too. Note that if
169 <varname>WakeSystem=</varname> is used, a different monotonic clock is selected that continues to
170 advance while the system is suspended and thus can be used as the trigger to resume the
171 system.</para>
172
173 <para>If the empty string is assigned to any of these options, the list of timers is reset (both
174 monotonic timers and <varname>OnCalendar=</varname> timers, see below), and all prior assignments
175 will have no effect.</para>
176
177 <para>Note that timers do not necessarily expire at the
178 precise time configured with these settings, as they are
179 subject to the <varname>AccuracySec=</varname> setting
180 below.</para></listitem>
181
182 </varlistentry>
183
184 <varlistentry>
185 <term><varname>OnCalendar=</varname></term>
186
187 <listitem><para>Defines realtime (i.e. wallclock) timers with
188 calendar event expressions. See
189 <citerefentry><refentrytitle>systemd.time</refentrytitle><manvolnum>7</manvolnum></citerefentry>
190 for more information on the syntax of calendar event
191 expressions. Otherwise, the semantics are similar to
192 <varname>OnActiveSec=</varname> and related settings.</para>
193
194 <para>Note that timers do not necessarily expire at the
195 precise time configured with this setting, as it is subject to
196 the <varname>AccuracySec=</varname> setting
197 below.</para>
198
199 <para>May be specified more than once, in which case the timer unit will trigger whenever any of the
200 specified expressions elapse. Moreover calendar timers and monotonic timers (see above) may be
201 combined within the same timer unit.</para>
202
203 <para>If the empty string is assigned to any of these options, the list of timers is reset (both
204 <varname>OnCalendar=</varname> timers and monotonic timers, see above), and all prior assignments
205 will have no effect.</para></listitem>
206 </varlistentry>
207
208 <varlistentry>
209 <term><varname>AccuracySec=</varname></term>
210
211 <listitem><para>Specify the accuracy the timer shall elapse
212 with. Defaults to 1min. The timer is scheduled to elapse
213 within a time window starting with the time specified in
214 <varname>OnCalendar=</varname>,
215 <varname>OnActiveSec=</varname>,
216 <varname>OnBootSec=</varname>,
217 <varname>OnStartupSec=</varname>,
218 <varname>OnUnitActiveSec=</varname> or
219 <varname>OnUnitInactiveSec=</varname> and ending the time
220 configured with <varname>AccuracySec=</varname> later. Within
221 this time window, the expiry time will be placed at a
222 host-specific, randomized, but stable position that is
223 synchronized between all local timer units. This is done in
224 order to optimize power consumption to suppress unnecessary
225 CPU wake-ups. To get best accuracy, set this option to
226 1us. Note that the timer is still subject to the timer slack
227 configured via
228 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>'s
229 <varname>TimerSlackNSec=</varname> setting. See
230 <citerefentry><refentrytitle>prctl</refentrytitle><manvolnum>2</manvolnum></citerefentry>
231 for details. To optimize power consumption, make sure to set
232 this value as high as possible and as low as
233 necessary.</para>
234
235 <para>Note that this setting is primarily a power saving option that allows coalescing CPU
236 wake-ups. It should not be confused with <varname>RandomizedDelaySec=</varname> (see below) which
237 adds a random value to the time the timer shall elapse next and whose purpose is the opposite: to
238 stretch elapsing of timer events over a longer period to reduce workload spikes. For further details
239 and explanations and how both settings play together, see below.</para></listitem>
240 </varlistentry>
241
242 <varlistentry>
243 <term><varname>RandomizedDelaySec=</varname></term>
244
245 <listitem><para>Delay the timer by a randomly selected, evenly distributed amount of time between 0
246 and the specified time value. Defaults to 0, indicating that no randomized delay shall be applied.
247 Each timer unit will determine this delay randomly before each iteration, and the delay will simply
248 be added on top of the next determined elapsing time, unless modified with
249 <varname>FixedRandomDelay=</varname>, see below.</para>
250
251 <para>This setting is useful to stretch dispatching of similarly configured timer events over a
252 certain time interval, to prevent them from firing all at the same time, possibly resulting in
253 resource congestion.</para>
254
255 <para>Note the relation to <varname>AccuracySec=</varname> above: the latter allows the service
256 manager to coalesce timer events within a specified time range in order to minimize wakeups, while
257 this setting does the opposite: it stretches timer events over an interval, to make it unlikely that
258 they fire simultaneously. If <varname>RandomizedDelaySec=</varname> and
259 <varname>AccuracySec=</varname> are used in conjunction, first the randomized delay is added, and
260 then the result is possibly further shifted to coalesce it with other timer events happening on the
261 system. As mentioned above <varname>AccuracySec=</varname> defaults to 1 minute and
262 <varname>RandomizedDelaySec=</varname> to 0, thus encouraging coalescing of timer events. In order to
263 optimally stretch timer events over a certain range of time, set
264 <varname>AccuracySec=1us</varname> and <varname>RandomizedDelaySec=</varname> to some higher value.
265 </para></listitem>
266 </varlistentry>
267
268 <varlistentry>
269 <term><varname>FixedRandomDelay=</varname></term>
270
271 <listitem><para>Takes a boolean argument. When enabled, the randomized offset specified by
272 <varname>RandomizedDelaySec=</varname> is reused for all firings of the same timer. For a given timer
273 unit, the offset depends on the machine ID, user identifier and timer name, which means that it is
274 stable between restarts of the manager. This effectively creates a fixed offset for an individual
275 timer, reducing the jitter in firings of this timer, while still avoiding firing at the same time as
276 other similarly configured timers.</para>
277
278 <para>This setting has no effect if <varname>RandomizedDelaySec=</varname> is set to 0. Defaults to
279 <option>false</option>.</para></listitem>
280 </varlistentry>
281
282 <varlistentry>
283 <term><varname>OnClockChange=</varname></term>
284 <term><varname>OnTimezoneChange=</varname></term>
285
286 <listitem><para>These options take boolean arguments. When true, the service unit will be triggered
287 when the system clock (<constant>CLOCK_REALTIME</constant>) jumps relative to the monotonic clock
288 (<constant>CLOCK_MONOTONIC</constant>), or when the local system timezone is modified. These options
289 can be used alone or in combination with other timer expressions (see above) within the same timer
290 unit. These options default to <option>false</option>.</para></listitem>
291 </varlistentry>
292
293 <varlistentry>
294 <term><varname>Unit=</varname></term>
295
296 <listitem><para>The unit to activate when this timer elapses.
297 The argument is a unit name, whose suffix is not
298 <literal>.timer</literal>. If not specified, this value
299 defaults to a service that has the same name as the timer
300 unit, except for the suffix. (See above.) It is recommended
301 that the unit name that is activated and the unit name of the
302 timer unit are named identically, except for the
303 suffix.</para></listitem>
304 </varlistentry>
305
306 <varlistentry>
307 <term><varname>Persistent=</varname></term>
308
309 <listitem><para>Takes a boolean argument. If true, the time when the service unit was last triggered
310 is stored on disk. When the timer is activated, the service unit is triggered immediately if it
311 would have been triggered at least once during the time when the timer was inactive. Such triggering
312 is nonetheless subject to the delay imposed by <varname>RandomizedDelaySec=</varname>.
313 This is useful to catch up on missed runs of the service when the system was powered down. Note that
314 this setting only has an effect on timers configured with <varname>OnCalendar=</varname>. Defaults to
315 <option>false</option>.</para>
316
317 <para>Use <command>systemctl clean --what=state …</command> on the timer unit to remove the timestamp
318 file maintained by this option from disk. In particular, use this command before uninstalling a timer
319 unit. See
320 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry> for
321 details.</para></listitem>
322 </varlistentry>
323
324 <varlistentry>
325 <term><varname>WakeSystem=</varname></term>
326
327 <listitem><para>Takes a boolean argument. If true, an elapsing timer will cause the system to resume
328 from suspend, should it be suspended and if the system supports this. Note that this option will only
329 make sure the system resumes on the appropriate times, it will not take care of suspending it again
330 after any work that is to be done is finished. Defaults to
331 <option>false</option>.</para>
332
333 <para>Note that this functionality requires privileges and is thus generally only available in the
334 system service manager.</para>
335
336 <para>Note that behaviour of monotonic clock timers (as configured with
337 <varname>OnActiveSec=</varname>, <varname>OnBootSec=</varname>, <varname>OnStartupSec=</varname>,
338 <varname>OnUnitActiveSec=</varname>, <varname>OnUnitInactiveSec=</varname>, see above) is altered
339 depending on this option. If false, a monotonic clock is used that is paused during system suspend
340 (<constant>CLOCK_MONOTONIC</constant>), if true a different monotonic clock is used that continues
341 advancing during system suspend (<constant>CLOCK_BOOTTIME</constant>), see
342 <citerefentry><refentrytitle>clock_getres</refentrytitle><manvolnum>2</manvolnum></citerefentry> for
343 details.</para></listitem>
344 </varlistentry>
345
346 <varlistentry>
347 <term><varname>RemainAfterElapse=</varname></term>
348
349 <listitem><para>Takes a boolean argument. If true, a timer will stay loaded, and its state remains
350 queryable even after it elapsed and the associated unit (as configured with <varname>Unit=</varname>,
351 see above) deactivated again. If false, an elapsed timer unit that cannot elapse anymore is unloaded
352 once its associated unit deactivated again. Turning this off is particularly useful for transient
353 timer units. Note that this setting has an effect when repeatedly starting a timer unit: if
354 <varname>RemainAfterElapse=</varname> is on, starting the timer a second time has no effect. However,
355 if <varname>RemainAfterElapse=</varname> is off and the timer unit was already unloaded, it can be
356 started again, and thus the service can be triggered multiple times. Defaults to
357 <option>true</option>.</para></listitem>
358 </varlistentry>
359 </variablelist>
360 </refsect1>
361
362 <refsect1>
363 <title>See Also</title>
364 <para>
365 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
366 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
367 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
368 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
369 <citerefentry><refentrytitle>systemd.time</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
370 <citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
371 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
372 <citerefentry><refentrytitle>prctl</refentrytitle><manvolnum>2</manvolnum></citerefentry>
373 </para>
374 </refsect1>
375
376 </refentry>