]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: split system/user job timeouts and make them configurable
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 26 Jan 2021 19:23:12 +0000 (20:23 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 1 Feb 2023 11:52:29 +0000 (11:52 +0000)
Config options are -Ddefault-timeout-sec= and -Ddefault-user-timeout-sec=.
Existing -Dupdate-helper-user-timeout= is renamed to -Dupdate-helper-user-timeout-sec=
for consistency. All three options take an integer value in seconds. The
renaming and type-change of the option is a small compat break, but it's just
at compile time and result in a clear error message. I also doubt that anyone was
actually using the option.

This commit separates the user manager timeouts, but keeps them unchanged at 90 s.
The timeout for the user manager is set to 4/3*user-timeout, which means that it
is still 120 s.

Fedora wants to experiment with lower timeouts, but doing this via a patch would
be annoying and more work than necessary. Let's make this easy to configure.

13 files changed:
man/custom-entities.ent.in
man/systemd-system.conf.xml
man/systemd.service.xml
meson.build
meson_options.txt
src/basic/constants.h
src/core/main.c
src/core/manager.c
src/core/manager.h
src/core/system.conf.in
src/core/user.conf.in
src/rpm/systemd-update-helper.in
units/user@.service.in

index 6d662a380a82996819cb7e1cd3ccfc4f8ae842d3..0376e0feb99731095e3b9366903b65af88f43280 100644 (file)
@@ -15,5 +15,7 @@
 <!ENTITY HIGH_RLIMIT_NOFILE "{{HIGH_RLIMIT_NOFILE}}">
 <!ENTITY DEFAULT_DNSSEC_MODE "{{DEFAULT_DNSSEC_MODE_STR}}">
 <!ENTITY DEFAULT_DNS_OVER_TLS_MODE "{{DEFAULT_DNS_OVER_TLS_MODE_STR}}">
+<!ENTITY DEFAULT_TIMEOUT "{{DEFAULT_TIMEOUT_SEC}} s">
+<!ENTITY DEFAULT_USER_TIMEOUT "{{DEFAULT_USER_TIMEOUT_SEC}} s">
 <!ENTITY fedora_latest_version "36">
 <!ENTITY fedora_cloud_release "1.5">
index 481fa31e01470c6be0d0c2cc05448532eff29098..82a52e21509f1457424c1954f341b8f9b3525d82 100644 (file)
         <term><varname>DefaultTimeoutAbortSec=</varname></term>
         <term><varname>DefaultRestartSec=</varname></term>
 
-        <listitem><para>Configures the default timeouts for starting,
-        stopping and aborting of units, as well as the default time to sleep
-        between automatic restarts of units, as configured per-unit in
-        <varname>TimeoutStartSec=</varname>,
-        <varname>TimeoutStopSec=</varname>,
-        <varname>TimeoutAbortSec=</varname> and
-        <varname>RestartSec=</varname> (for services, see
+        <listitem><para>Configures the default timeouts for starting, stopping and aborting of units, as well
+        as the default time to sleep between automatic restarts of units, as configured per-unit in
+        <varname>TimeoutStartSec=</varname>, <varname>TimeoutStopSec=</varname>,
+        <varname>TimeoutAbortSec=</varname> and <varname>RestartSec=</varname> (for services, see
         <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
-        for details on the per-unit settings). Disabled by default, when
-        service with <varname>Type=oneshot</varname> is used.
-        For non-service units,
-        <varname>DefaultTimeoutStartSec=</varname> sets the default
-        <varname>TimeoutSec=</varname>
-        value. <varname>DefaultTimeoutStartSec=</varname> and
-        <varname>DefaultTimeoutStopSec=</varname> default to
-        90s. <varname>DefaultTimeoutAbortSec=</varname> is not set by default
-        so that all units fall back to <varname>TimeoutStopSec=</varname>.
-        <varname>DefaultRestartSec=</varname> defaults to
-        100ms.</para></listitem>
+        for details on the per-unit settings). For non-service units,
+        <varname>DefaultTimeoutStartSec=</varname> sets the default <varname>TimeoutSec=</varname> value.
+        </para>
+
+        <para><varname>DefaultTimeoutStartSec=</varname> and <varname>DefaultTimeoutStopSec=</varname>
+        default to &DEFAULT_TIMEOUT; in the system manager and &DEFAULT_USER_TIMEOUT; in the user manager.
+        <varname>DefaultTimeoutAbortSec=</varname> is not set by default so that all units fall back to
+        <varname>TimeoutStopSec=</varname>. <varname>DefaultRestartSec=</varname> defaults to 100 ms.
+        </para></listitem>
       </varlistentry>
 
       <varlistentry>
         and <filename>/etc/crypttab</filename> (see
         <citerefentry><refentrytitle>systemd.mount</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
         <citerefentry><refentrytitle>crypttab</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
-        Defaults to 90s.</para></listitem>
+        Defaults to &DEFAULT_TIMEOUT; in the system manager and &DEFAULT_USER_TIMEOUT; in the user manager.
+        </para></listitem>
       </varlistentry>
 
       <varlistentry>
index d44c48c7b1c79d9a5d32cd61ea5146bdfa2837ec..a1a32e8cd905469ccfd1ecf0c385231a94b06017 100644 (file)
 
       <varlistentry>
         <term><varname>TimeoutStartSec=</varname></term>
-        <listitem><para>Configures the time to wait for start-up. If a daemon service does not signal start-up
-        completion within the configured time, the service will be considered failed and will be shut down again. The
-        precise action depends on the <varname>TimeoutStartFailureMode=</varname> option. Takes a unit-less value in
-        seconds, or a time span value such as "5min 20s". Pass <literal>infinity</literal> to disable the timeout logic.
-        Defaults to <varname>DefaultTimeoutStartSec=</varname> from the manager configuration file, except when
+        <listitem><para>Configures the time to wait for start-up. If a daemon service does not signal
+        start-up completion within the configured time, the service will be considered failed and will be
+        shut down again. The precise action depends on the <varname>TimeoutStartFailureMode=</varname>
+        option. Takes a unit-less value in seconds, or a time span value such as "5min 20s". Pass
+        <literal>infinity</literal> to disable the timeout logic. Defaults to
+        <varname>DefaultTimeoutStartSec=</varname> set in the manager, except when
         <varname>Type=oneshot</varname> is used, in which case the timeout is disabled by default (see
         <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
         </para>
index a856bb2f8439eab003efa6d5cbf10bd713e32037..97246a3c6fad044386279e302c39e4ed6e139c77 100644 (file)
@@ -294,7 +294,6 @@ conf.set_quoted('USER_TMPFILES_DIR',                          usertmpfilesdir)
 conf.set_quoted('UDEVLIBEXECDIR',                             udevlibexecdir)
 conf.set_quoted('UDEV_HWDB_DIR',                              udevhwdbdir)
 conf.set_quoted('UDEV_RULES_DIR',                             udevrulesdir)
-conf.set_quoted('UPDATE_HELPER_USER_TIMEOUT',                 get_option('update-helper-user-timeout'))
 conf.set_quoted('USER_CONFIG_UNIT_DIR',                       pkgsysconfdir / 'user')
 conf.set_quoted('USER_DATA_UNIT_DIR',                         userunitdir)
 conf.set_quoted('USER_ENV_GENERATOR_DIR',                     userenvgeneratordir)
@@ -310,6 +309,10 @@ conf.set10('MEMORY_ACCOUNTING_DEFAULT',                       memory_accounting_
 conf.set('STATUS_UNIT_FORMAT_DEFAULT',                        'STATUS_UNIT_FORMAT_' + status_unit_format_default.to_upper())
 conf.set_quoted('STATUS_UNIT_FORMAT_DEFAULT_STR',             status_unit_format_default)
 
+conf.set('DEFAULT_TIMEOUT_SEC',                               get_option('default-timeout-sec'))
+conf.set('DEFAULT_USER_TIMEOUT_SEC',                          get_option('default-user-timeout-sec'))
+conf.set('UPDATE_HELPER_USER_TIMEOUT_SEC',                    get_option('update-helper-user-timeout-sec'))
+
 conf.set10('FIRST_BOOT_FULL_PRESET',                          get_option('first-boot-full-preset'))
 
 #####################################################################
index 8ce245dbb97148767b3ae5bb8aba685efe6075a6..17c88e23a1d3bee5d4743ee88fb8d02de8505810 100644 (file)
@@ -187,6 +187,10 @@ option('dbussystemservicedir', type : 'string',
        description : 'D-Bus system service directory')
 option('dbus-interfaces-dir', type : 'string',
        description : 'export D-Bus introspection XML as standalone files')
+option('default-timeout-sec', type : 'integer', value : 90,
+       description : 'default timeout for system unit start/stop')
+option('default-user-timeout-sec', type : 'integer', value : 90,
+       description : 'default timeout for user unit start/stop')
 option('pkgconfigdatadir', type : 'string', value : '',
        description : 'directory for arch-independent pkg-config files')
 option('pkgconfiglibdir', type : 'string', value : '',
@@ -195,8 +199,8 @@ option('xinitrcdir', type : 'string', value : '',
        description : 'directory for xinitrc files')
 option('rpmmacrosdir', type : 'string', value : 'lib/rpm/macros.d',
        description : 'directory for rpm macros ["no" disables]')
-option('update-helper-user-timeout', type : 'string', value : '15s',
-       description : 'how long to wait for user manager operations')
+option('update-helper-user-timeout-sec', type : 'integer', value : 15,
+       description : 'timeout for user manager package operations')
 option('pamlibdir', type : 'string',
        description : 'directory for PAM modules')
 option('pamconfdir', type : 'string',
index 4a24ba9c8cba162afe60937513f81d4df4a1916d..5d68cc63320f95cb757a85d4538cf5b3c158118c 100644 (file)
 #  endif
 #endif
 
-#define DEFAULT_TIMEOUT_USEC (90*USEC_PER_SEC)
 #define DEFAULT_RESTART_USEC (100*USEC_PER_MSEC)
+
+/* Many different things, but also system unit start/stop */
+#define DEFAULT_TIMEOUT_USEC (DEFAULT_TIMEOUT_SEC*USEC_PER_SEC)
+/* User unit start/stop */
+#define DEFAULT_USER_TIMEOUT_USEC (DEFAULT_USER_TIMEOUT_SEC*USEC_PER_SEC)
+/* Timeout for user confirmation on the console */
 #define DEFAULT_CONFIRM_USEC (30*USEC_PER_SEC)
 
 /* We use an extra-long timeout for the reload. This is because a reload or reexec means generators are rerun
index a7cdc8d631054528b81d4fe475f749181de55c83..867f3c7adcf02d33e0dc8dd0923f022104f22766 100644 (file)
@@ -2436,11 +2436,11 @@ static void reset_arguments(void) {
         arg_default_std_output = EXEC_OUTPUT_JOURNAL;
         arg_default_std_error = EXEC_OUTPUT_INHERIT;
         arg_default_restart_usec = DEFAULT_RESTART_USEC;
-        arg_default_timeout_start_usec = DEFAULT_TIMEOUT_USEC;
-        arg_default_timeout_stop_usec = DEFAULT_TIMEOUT_USEC;
-        arg_default_timeout_abort_usec = DEFAULT_TIMEOUT_USEC;
+        arg_default_timeout_start_usec = manager_default_timeout(arg_system);
+        arg_default_timeout_stop_usec = manager_default_timeout(arg_system);
+        arg_default_timeout_abort_usec = manager_default_timeout(arg_system);
         arg_default_timeout_abort_set = false;
-        arg_default_device_timeout_usec = DEFAULT_TIMEOUT_USEC;
+        arg_default_device_timeout_usec = manager_default_timeout(arg_system);
         arg_default_start_limit_interval = DEFAULT_START_LIMIT_INTERVAL;
         arg_default_start_limit_burst = DEFAULT_START_LIMIT_BURST;
         arg_runtime_watchdog = 0;
index d39e917134f104f5abcf27a7b7932feb6575ff39..67bab54b9b0a440e895bd6b8fd13e08175ef734a 100644 (file)
@@ -835,10 +835,10 @@ int manager_new(LookupScope scope, ManagerTestRunFlags test_run_flags, Manager *
                 .default_memory_accounting = MEMORY_ACCOUNTING_DEFAULT,
                 .default_tasks_accounting = true,
                 .default_tasks_max = TASKS_MAX_UNSET,
-                .default_timeout_start_usec = DEFAULT_TIMEOUT_USEC,
-                .default_timeout_stop_usec = DEFAULT_TIMEOUT_USEC,
+                .default_timeout_start_usec = manager_default_timeout(scope == LOOKUP_SCOPE_SYSTEM),
+                .default_timeout_stop_usec = manager_default_timeout(scope == LOOKUP_SCOPE_SYSTEM),
                 .default_restart_usec = DEFAULT_RESTART_USEC,
-                .default_device_timeout_usec = DEFAULT_TIMEOUT_USEC,
+                .default_device_timeout_usec = manager_default_timeout(scope == LOOKUP_SCOPE_SYSTEM),
 
                 .original_log_level = -1,
                 .original_log_target = _LOG_TARGET_INVALID,
index c13de8fe78ff78507bcb508b89a054a557565c9c..e7b594fdd30081506e81ad438a671dd56cb4cf1a 100644 (file)
@@ -485,6 +485,10 @@ static inline usec_t manager_default_timeout_abort_usec(Manager *m) {
 
 #define MANAGER_IS_TEST_RUN(m) ((m)->test_run_flags != 0)
 
+static inline usec_t manager_default_timeout(bool is_system) {
+        return is_system ? DEFAULT_TIMEOUT_USEC : DEFAULT_USER_TIMEOUT_USEC;
+}
+
 int manager_new(LookupScope scope, ManagerTestRunFlags test_run_flags, Manager **m);
 Manager* manager_free(Manager *m);
 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
index 531a7694d98b368e887a2fadc2d9d91b3dfa10c3..0c27586c462f5c1ded06b4f7e0571f3840e8ebcc 100644 (file)
 #DefaultTimerAccuracySec=1min
 #DefaultStandardOutput=journal
 #DefaultStandardError=inherit
-#DefaultTimeoutStartSec=90s
-#DefaultTimeoutStopSec=90s
+#DefaultTimeoutStartSec={{DEFAULT_TIMEOUT_SEC}}s
+#DefaultTimeoutStopSec={{DEFAULT_TIMEOUT_SEC}}s
 #DefaultTimeoutAbortSec=
-#DefaultDeviceTimeoutSec=90s
+#DefaultDeviceTimeoutSec={{DEFAULT_TIMEOUT_SEC}}s
 #DefaultRestartSec=100ms
 #DefaultStartLimitIntervalSec=10s
 #DefaultStartLimitBurst=5
index b4938942d146ea59b384bf8c407a0fa7041fd152..d67650b85806b003e47679ddb90efe7b264cfd42 100644 (file)
 #DefaultTimerAccuracySec=1min
 #DefaultStandardOutput=inherit
 #DefaultStandardError=inherit
-#DefaultTimeoutStartSec=90s
-#DefaultTimeoutStopSec=90s
+#DefaultTimeoutStartSec={{DEFAULT_USER_TIMEOUT_SEC}}s
+#DefaultTimeoutStopSec={{DEFAULT_USER_TIMEOUT_SEC}}s
 #DefaultTimeoutAbortSec=
+#DefaultDeviceTimeoutSec={{DEFAULT_USER_TIMEOUT_SEC}}s
 #DefaultRestartSec=100ms
 #DefaultStartLimitIntervalSec=10s
 #DefaultStartLimitBurst=5
index b35d952fab0d3d0c5a7107c07f28e47cbcd8c492..c623a5ea17227593b787065e269c821568469fa5 100755 (executable)
@@ -32,7 +32,7 @@ case "$command" in
 
         users=$(systemctl list-units 'user@*' --legend=no | sed -n -r 's/.*user@([0-9]+).service.*/\1/p')
         for user in $users; do
-            SYSTEMD_BUS_TIMEOUT={{UPDATE_HELPER_USER_TIMEOUT}} \
+            SYSTEMD_BUS_TIMEOUT={{UPDATE_HELPER_USER_TIMEOUT_SEC}}s \
                     systemctl --user -M "$user@" disable --now --no-warn "$@" &
         done
         wait
@@ -53,7 +53,7 @@ case "$command" in
         users=$(systemctl list-units 'user@*' --legend=no | sed -n -r 's/.*user@([0-9]+).service.*/\1/p')
         for user in $users; do
             for unit in "$@"; do
-                SYSTEMD_BUS_TIMEOUT={{UPDATE_HELPER_USER_TIMEOUT}} \
+                SYSTEMD_BUS_TIMEOUT={{UPDATE_HELPER_USER_TIMEOUT_SEC}}s \
                         systemctl --user -M "$user@" set-property "$unit" Markers=+needs-restart &
             done
         done
@@ -89,7 +89,7 @@ case "$command" in
 
         if [[ "$command" =~ reexec ]]; then
             for user in $users; do
-                SYSTEMD_BUS_TIMEOUT={{UPDATE_HELPER_USER_TIMEOUT}} \
+                SYSTEMD_BUS_TIMEOUT={{UPDATE_HELPER_USER_TIMEOUT_SEC}}s \
                         systemctl --user -M "$user@" daemon-reexec &
             done
             wait
@@ -97,7 +97,7 @@ case "$command" in
 
         if [[ "$command" =~ reload ]]; then
             for user in $users; do
-                SYSTEMD_BUS_TIMEOUT={{UPDATE_HELPER_USER_TIMEOUT}} \
+                SYSTEMD_BUS_TIMEOUT={{UPDATE_HELPER_USER_TIMEOUT_SEC}}s \
                         systemctl --user -M "$user@" daemon-reload &
             done
             wait
@@ -105,7 +105,7 @@ case "$command" in
 
         if [[ "$command" =~ restart ]]; then
             for user in $users; do
-                SYSTEMD_BUS_TIMEOUT={{UPDATE_HELPER_USER_TIMEOUT}} \
+                SYSTEMD_BUS_TIMEOUT={{UPDATE_HELPER_USER_TIMEOUT_SEC}}s \
                         systemctl --user -M "$user@" reload-or-restart --marked &
             done
             wait
index 15587649094b672f75113729d5d881a2d334c509..5e95efe1d109e3d4fbad415a540ae5e26e7a620a 100644 (file)
@@ -23,6 +23,6 @@ Slice=user-%i.slice
 KillMode=mixed
 Delegate=pids memory cpu
 TasksMax=infinity
-TimeoutStopSec=120s
+TimeoutStopSec={{ DEFAULT_USER_TIMEOUT_SEC*4//3 }}s
 KeyringMode=inherit
 OOMScoreAdjust=100