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