✓ RestartSec=
✓ RootDirectoryStartOnly=
✓ RuntimeMaxSec=
+✓ RuntimeRandomizedExtraSec=
Sockets=
✓ SuccessExitStatus=
✓ TimeoutAbortSec=
```
✓ RuntimeMaxSec=
+✓ RuntimeRandomizedExtraSec=
✓ TimeoutStopSec=
```
readonly s TimeoutStopFailureMode = '...';
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
readonly t RuntimeMaxUSec = ...;
+ @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
+ readonly t RuntimeRandomizedExtraUSec = ...;
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
readonly t WatchdogUSec = ...;
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
<!--property RuntimeMaxUSec is not documented!-->
+ <!--property RuntimeRandomizedExtraUSec is not documented!-->
+
<!--property WatchdogUSec is not documented!-->
<!--property RootDirectoryStartOnly is not documented!-->
<variablelist class="dbus-property" generated="True" extra-ref="RuntimeMaxUSec"/>
+ <variablelist class="dbus-property" generated="True" extra-ref="RuntimeRandomizedExtraUSec"/>
+
<variablelist class="dbus-property" generated="True" extra-ref="WatchdogUSec"/>
<variablelist class="dbus-property" generated="True" extra-ref="WatchdogTimestamp"/>
readonly s Result = '...';
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
readonly t RuntimeMaxUSec = ...;
+ @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
+ readonly t RuntimeRandomizedExtraUSec = ...;
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
readonly s Slice = '...';
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
<!--property RuntimeMaxUSec is not documented!-->
+ <!--property RuntimeRandomizedExtraUSec is not documented!-->
+
<!--property Slice is not documented!-->
<!--property MemoryCurrent is not documented!-->
<variablelist class="dbus-property" generated="True" extra-ref="RuntimeMaxUSec"/>
+ <variablelist class="dbus-property" generated="True" extra-ref="RuntimeRandomizedExtraUSec"/>
+
<variablelist class="dbus-property" generated="True" extra-ref="Slice"/>
<variablelist class="dbus-property" generated="True" extra-ref="ControlGroup"/>
active for longer than the specified time it is terminated and put into a failure state. Pass
<literal>infinity</literal> (the default) to configure no runtime limit.</para></listitem>
</varlistentry>
+
+ <varlistentry>
+ <term><varname>RuntimeRandomizedExtraSec=</varname></term>
+
+ <listitem><para>This option modifies <varname>RuntimeMaxSec=</varname> by increasing the maximum runtime by an
+ evenly distributed duration between 0 and the specified value (in seconds). If <varname>RuntimeMaxSec=</varname> is
+ unspecified, then this feature will be disabled.
+ </para></listitem>
+ </varlistentry>
</variablelist>
<xi:include href="systemd.service.xml" xpointer="shared-unit-options" />
</para></listitem>
</varlistentry>
+ <varlistentry>
+ <term><varname>RuntimeRandomizedExtraSec=</varname></term>
+
+ <listitem><para>This option modifies <varname>RuntimeMaxSec=</varname> by increasing the maximum runtime by an
+ evenly distributed duration between 0 and the specified value (in seconds). If <varname>RuntimeMaxSec=</varname> is
+ unspecified, then this feature will be disabled.
+ </para></listitem>
+ </varlistentry>
+
<varlistentry>
<term><varname>WatchdogSec=</varname></term>
<listitem><para>Configures the watchdog timeout for a service.
SD_BUS_PROPERTY("TimeoutStopUSec", "t", bus_property_get_usec, offsetof(Scope, timeout_stop_usec), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Scope, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_PROPERTY("RuntimeMaxUSec", "t", bus_property_get_usec, offsetof(Scope, runtime_max_usec), SD_BUS_VTABLE_PROPERTY_CONST),
+ SD_BUS_PROPERTY("RuntimeRandomizedExtraUSec", "t", bus_property_get_usec, offsetof(Scope, runtime_rand_extra_usec), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_SIGNAL("RequestStop", NULL, 0),
SD_BUS_METHOD("Abandon", NULL, NULL, bus_scope_method_abandon, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_VTABLE_END
if (streq(name, "RuntimeMaxUSec"))
return bus_set_transient_usec(u, name, &s->runtime_max_usec, message, flags, error);
+ if (streq(name, "RuntimeRandomizedExtraUSec"))
+ return bus_set_transient_usec(u, name, &s->runtime_rand_extra_usec, message, flags, error);
+
if (streq(name, "PIDs")) {
_cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
unsigned n = 0;
SD_BUS_PROPERTY("TimeoutStartFailureMode", "s", property_get_timeout_failure_mode, offsetof(Service, timeout_start_failure_mode), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("TimeoutStopFailureMode", "s", property_get_timeout_failure_mode, offsetof(Service, timeout_stop_failure_mode), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("RuntimeMaxUSec", "t", bus_property_get_usec, offsetof(Service, runtime_max_usec), SD_BUS_VTABLE_PROPERTY_CONST),
+ SD_BUS_PROPERTY("RuntimeRandomizedExtraUSec", "t", bus_property_get_usec, offsetof(Service, runtime_rand_extra_usec), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("WatchdogUSec", "t", property_get_watchdog_usec, 0, 0),
BUS_PROPERTY_DUAL_TIMESTAMP("WatchdogTimestamp", offsetof(Service, watchdog_timestamp), 0),
SD_BUS_PROPERTY("PermissionsStartOnly", "b", bus_property_get_bool, offsetof(Service, permissions_start_only), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), /* 😷 deprecated */
if (streq(name, "RuntimeMaxUSec"))
return bus_set_transient_usec(u, name, &s->runtime_max_usec, message, flags, error);
+ if (streq(name, "RuntimeRandomizedExtraUSec"))
+ return bus_set_transient_usec(u, name, &s->runtime_rand_extra_usec, message, flags, error);
+
if (streq(name, "WatchdogUSec"))
return bus_set_transient_usec(u, name, &s->watchdog_usec, message, flags, error);
Service.TimeoutStartFailureMode, config_parse_service_timeout_failure_mode, 0, offsetof(Service, timeout_start_failure_mode)
Service.TimeoutStopFailureMode, config_parse_service_timeout_failure_mode, 0, offsetof(Service, timeout_stop_failure_mode)
Service.RuntimeMaxSec, config_parse_sec, 0, offsetof(Service, runtime_max_usec)
+Service.RuntimeRandomizedExtraSec, config_parse_sec, 0, offsetof(Service, runtime_rand_extra_usec)
Service.WatchdogSec, config_parse_sec, 0, offsetof(Service, watchdog_usec)
{# The following five only exist for compatibility, they moved into Unit, see above #}
Service.StartLimitInterval, config_parse_sec, 0, offsetof(Unit, start_ratelimit.interval)
{{ CGROUP_CONTEXT_CONFIG_ITEMS('Scope') }}
{{ KILL_CONTEXT_CONFIG_ITEMS('Scope') }}
Scope.RuntimeMaxSec, config_parse_sec, 0, offsetof(Scope, runtime_max_usec)
+Scope.RuntimeRandomizedExtraSec, config_parse_sec, 0, offsetof(Scope, runtime_rand_extra_usec)
Scope.TimeoutStopSec, config_parse_sec, 0, offsetof(Scope, timeout_stop_usec)
{# The [Install] section is ignored here #}
Install.Alias, NULL, 0, 0
#include "load-dropin.h"
#include "log.h"
#include "process-util.h"
+#include "random-util.h"
#include "scope.h"
#include "serialize.h"
#include "special.h"
s->timer_event_source = sd_event_source_disable_unref(s->timer_event_source);
}
+static int scope_running_timeout(Scope *s) {
+ usec_t delta = 0;
+
+ assert(s);
+
+ if (s->runtime_rand_extra_usec != 0) {
+ delta = random_u64_range(s->runtime_rand_extra_usec);
+ log_unit_debug(UNIT(s), "Adding delta of %s sec to timeout", FORMAT_TIMESPAN(delta, USEC_PER_SEC));
+ }
+
+ return usec_add(usec_add(UNIT(s)->active_enter_timestamp.monotonic,
+ s->runtime_max_usec),
+ delta);
+}
+
static int scope_arm_timer(Scope *s, usec_t usec) {
int r;
switch (s->deserialized_state) {
case SCOPE_RUNNING:
- return usec_add(UNIT(s)->active_enter_timestamp.monotonic, s->runtime_max_usec);
+ return scope_running_timeout(s);
case SCOPE_STOP_SIGKILL:
case SCOPE_STOP_SIGTERM:
fprintf(f,
"%sScope State: %s\n"
"%sResult: %s\n"
- "%sRuntimeMaxSec: %s\n",
+ "%sRuntimeMaxSec: %s\n"
+ "%sRuntimeRandomizedExtraSec: %s\n",
prefix, scope_state_to_string(s->state),
prefix, scope_result_to_string(s->result),
- prefix, FORMAT_TIMESPAN(s->runtime_max_usec, USEC_PER_SEC));
+ prefix, FORMAT_TIMESPAN(s->runtime_max_usec, USEC_PER_SEC),
+ prefix, FORMAT_TIMESPAN(s->runtime_rand_extra_usec, USEC_PER_SEC));
cgroup_context_dump(UNIT(s), f, prefix);
kill_context_dump(&s->kill_context, f, prefix);
scope_set_state(s, SCOPE_RUNNING);
/* Set the maximum runtime timeout. */
- scope_arm_timer(s, usec_add(UNIT(s)->active_enter_timestamp.monotonic, s->runtime_max_usec));
+ scope_arm_timer(s, scope_running_timeout(s));
/* On unified we use proper notifications hence we can unwatch the PIDs
* we just attached to the scope. This can also be done on legacy as
ScopeResult result;
usec_t runtime_max_usec;
+ usec_t runtime_rand_extra_usec;
usec_t timeout_stop_usec;
char *controller;
#include "parse-util.h"
#include "path-util.h"
#include "process-util.h"
+#include "random-util.h"
#include "serialize.h"
#include "service.h"
#include "signal-util.h"
}
}
+static int service_running_timeout(Service *s) {
+ usec_t delta = 0;
+
+ assert(s);
+
+ if (s->runtime_rand_extra_usec != 0) {
+ delta = random_u64_range(s->runtime_rand_extra_usec);
+ log_unit_debug(UNIT(s), "Adding delta of %s sec to timeout", FORMAT_TIMESPAN(delta, USEC_PER_SEC));
+ }
+
+ return usec_add(usec_add(UNIT(s)->active_enter_timestamp.monotonic,
+ s->runtime_max_usec),
+ delta);
+}
+
static int service_arm_timer(Service *s, usec_t usec) {
int r;
if (s->runtime_max_usec != USEC_INFINITY && s->type == SERVICE_ONESHOT)
log_unit_warning(UNIT(s), "RuntimeMaxSec= has no effect in combination with Type=oneshot. Ignoring.");
+ if (s->runtime_max_usec == USEC_INFINITY && s->runtime_rand_extra_usec != 0)
+ log_unit_warning(UNIT(s), "Service has RuntimeRandomizedExtraSec= setting, but no RuntimeMaxSec=. Ignoring.");
+
return 0;
}
fprintf(f,
"%sRuntimeMaxSec: %s\n"
+ "%sRuntimeRandomizedExtraSec: %s\n"
"%sWatchdogSec: %s\n",
prefix, FORMAT_TIMESPAN(s->runtime_max_usec, USEC_PER_SEC),
+ prefix, FORMAT_TIMESPAN(s->runtime_rand_extra_usec, USEC_PER_SEC),
prefix, FORMAT_TIMESPAN(s->watchdog_usec, USEC_PER_SEC));
kill_context_dump(&s->kill_context, f, prefix);
return usec_add(UNIT(s)->state_change_timestamp.monotonic, s->timeout_start_usec);
case SERVICE_RUNNING:
- return usec_add(UNIT(s)->active_enter_timestamp.monotonic, s->runtime_max_usec);
+ return service_running_timeout(s);
case SERVICE_STOP:
case SERVICE_STOP_SIGTERM:
service_enter_stop_by_notify(s);
else {
service_set_state(s, SERVICE_RUNNING);
- service_arm_timer(s, usec_add(UNIT(s)->active_enter_timestamp.monotonic, s->runtime_max_usec));
+ service_arm_timer(s, service_running_timeout(s));
}
} else if (s->remain_after_exit)
usec_t timeout_abort_usec;
bool timeout_abort_set;
usec_t runtime_max_usec;
+ usec_t runtime_rand_extra_usec;
ServiceTimeoutFailureMode timeout_start_failure_mode;
ServiceTimeoutFailureMode timeout_stop_failure_mode;
if (streq(field, "RuntimeMaxSec"))
return bus_append_parse_sec_rename(m, field, eq);
+ if (streq(field, "RuntimeRandomizedExtraSec"))
+ return bus_append_parse_sec_rename(m, field, eq);
+
if (streq(field, "TimeoutStopSec"))
return bus_append_parse_sec_rename(m, field, eq);
"TimeoutStopSec",
"TimeoutAbortSec",
"RuntimeMaxSec",
+ "RuntimeRandomizedExtraSec",
"WatchdogSec"))
return bus_append_parse_sec_rename(m, field, eq);
RestartKillSignal=
RestrictNetworkInterfaces=
RuntimeMaxSec=
+RuntimeRandomizedExtraSec=
SendSIGHUP=
SendSIGKILL=
Slice=
RuntimeDirectoryMode=
RuntimeDirectoryPreserve=
RuntimeMaxSec=
+RuntimeRandomizedExtraSec=
SELinuxContext=
SecureBits=
SendSIGHUP=