anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

Blame SOURCES/0030-Configurable-Timeouts-Restarts-default-values.patch

572a44
From cd1c485f2fc5b23c7cdccb0dd852c7228fc79868 Mon Sep 17 00:00:00 2001
a4b143
From: Oleksii Shevchuk <alxchk@gmail.com>
a4b143
Date: Mon, 4 Nov 2013 18:47:43 +0200
a4b143
Subject: [PATCH] Configurable Timeouts/Restarts default values
a4b143
a4b143
https://bugs.freedesktop.org/show_bug.cgi?id=71132
a4b143
a4b143
Patch adds DefaultTimeoutStartSec, DefaultTimeoutStopSec, DefaultRestartSec
a4b143
configuration options to manager configuration file.
a4b143
---
a4b143
 man/systemd-system.conf.xml | 24 +++++++++++++++++++++++-
a4b143
 man/systemd.mount.xml       |  4 ++--
a4b143
 man/systemd.service.xml     |  6 ++++--
a4b143
 man/systemd.socket.xml      |  4 ++--
a4b143
 man/systemd.swap.xml        |  4 ++--
a4b143
 src/core/device.c           |  2 +-
a4b143
 src/core/main.c             |  9 +++++++++
a4b143
 src/core/manager.h          |  3 +++
a4b143
 src/core/mount.c            |  2 +-
a4b143
 src/core/scope.c            |  2 +-
a4b143
 src/core/service.c          |  6 +++---
a4b143
 src/core/socket.c           |  2 +-
a4b143
 src/core/swap.c             |  2 +-
a4b143
 src/core/system.conf        |  3 +++
a4b143
 src/core/user.conf          |  3 +++
a4b143
 15 files changed, 59 insertions(+), 17 deletions(-)
a4b143
a4b143
diff --git a/man/systemd-system.conf.xml b/man/systemd-system.conf.xml
a4b143
index e8cf8a9..c1f2648 100644
a4b143
--- a/man/systemd-system.conf.xml
a4b143
+++ b/man/systemd-system.conf.xml
a4b143
@@ -61,7 +61,6 @@
a4b143
                 otherwise <filename>user.conf</filename>. These
a4b143
                 configuration files contain a few settings controlling
a4b143
                 basic manager operations.</para>
a4b143
-
a4b143
         </refsect1>
a4b143
 
a4b143
         <refsect1>
a4b143
@@ -95,6 +94,29 @@
a4b143
                         </varlistentry>
a4b143
 
a4b143
                         <varlistentry>
a4b143
+                                <term><varname>DefaultTimeoutStartSec=</varname></term>
a4b143
+                                <term><varname>DefaultTimeoutStopSec=</varname></term>
a4b143
+                                <term><varname>DefaultRestartSec=</varname></term>
a4b143
+
a4b143
+                                <listitem><para>Configures the default
a4b143
+                                time-outs for starting and stopping of
a4b143
+                                units, as well as the default time to
a4b143
+                                sleep between automatic restarts of a
a4b143
+                                units, as configured per-unit in
a4b143
+                                <varname>TimeoutStartSec=</varname>,
a4b143
+                                <varname>TimeoutStopSec=</varname> and
a4b143
+                                <varname>RestartSec=</varname> (for
a4b143
+                                service units see
a4b143
+                                <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
a4b143
+                                for details on the per-unit
a4b143
+                                settings). For non-service units
a4b143
+                                <varname>DefaultTimeoutStartSec=</varname>
a4b143
+                                sets the default
a4b143
+                                <varname>TimeoutSec=</varname> value.
a4b143
+                                </para></listitem>
a4b143
+                        </varlistentry>
a4b143
+
a4b143
+                        <varlistentry>
a4b143
                                 <term><varname>CPUAffinity=</varname></term>
a4b143
 
a4b143
                                 <listitem><para>Configures the initial
a4b143
diff --git a/man/systemd.mount.xml b/man/systemd.mount.xml
a4b143
index 48af1ca..71a5736 100644
a4b143
--- a/man/systemd.mount.xml
a4b143
+++ b/man/systemd.mount.xml
a4b143
@@ -260,8 +260,8 @@
a4b143
                                 Takes a unit-less value in seconds, or
a4b143
                                 a time span value such as "5min
a4b143
                                 20s". Pass 0 to disable the timeout
a4b143
-                                logic. Defaults to
a4b143
-                                90s.</para></listitem>
a4b143
+                                logic. Default value is setted up in manager configuration
a4b143
+                                file via <term><varname>DefaultTimeoutStart=</varname></term>.</para></listitem>
a4b143
                         </varlistentry>
a4b143
                 </variablelist>
a4b143
 
a4b143
diff --git a/man/systemd.service.xml b/man/systemd.service.xml
572a44
index 5e1ddf7..df04048 100644
a4b143
--- a/man/systemd.service.xml
a4b143
+++ b/man/systemd.service.xml
572a44
@@ -524,7 +524,8 @@
a4b143
                                 Takes a unit-less value in seconds, or a
a4b143
                                 time span value such as "5min
a4b143
                                 20s". Pass 0 to disable the timeout
a4b143
-                                logic. Defaults to 90s, except when
a4b143
+                                logic. Defaults to <varname>TimeoutStartSec=</varname> in
a4b143
+                                manager configuration file, except when
a4b143
                                 <varname>Type=oneshot</varname> is
a4b143
                                 used in which case the timeout
a4b143
                                 is disabled by default.
572a44
@@ -545,7 +546,8 @@
a4b143
                                 Takes a unit-less value in seconds, or a
a4b143
                                 time span value such as "5min
a4b143
                                 20s". Pass 0 to disable the timeout
a4b143
-                                logic. Defaults to 90s.
a4b143
+                                logic. Defaults to <varname>TimeoutStartSec=</varname> in
a4b143
+                                manager configuration file.
a4b143
                                 </para></listitem>
a4b143
                         </varlistentry>
a4b143
 
a4b143
diff --git a/man/systemd.socket.xml b/man/systemd.socket.xml
a4b143
index 8c88d9f..1c78562 100644
a4b143
--- a/man/systemd.socket.xml
a4b143
+++ b/man/systemd.socket.xml
a4b143
@@ -679,8 +679,8 @@
a4b143
                                 Takes a unit-less value in seconds, or
a4b143
                                 a time span value such as "5min
a4b143
                                 20s". Pass 0 to disable the timeout
a4b143
-                                logic. Defaults to
a4b143
-                                90s.</para></listitem>
a4b143
+                                logic. Defaults to <varname>TimeoutStartSec=</varname> in
a4b143
+                                manager configuration file.</para></listitem>
a4b143
                         </varlistentry>
a4b143
 
a4b143
                         <varlistentry>
a4b143
diff --git a/man/systemd.swap.xml b/man/systemd.swap.xml
a4b143
index 813ae6c..13f6c84 100644
a4b143
--- a/man/systemd.swap.xml
a4b143
+++ b/man/systemd.swap.xml
a4b143
@@ -186,8 +186,8 @@
a4b143
                                 Takes a unit-less value in seconds, or
a4b143
                                 a time span value such as "5min
a4b143
                                 20s". Pass 0 to disable the timeout
a4b143
-                                logic. Defaults to
a4b143
-                                90s.</para></listitem>
a4b143
+                                logic. Defaults to <varname>TimeoutStartSec=</varname> in
a4b143
+                                manager configuration file.</para></listitem>
a4b143
                         </varlistentry>
a4b143
                 </variablelist>
a4b143
 
a4b143
diff --git a/src/core/device.c b/src/core/device.c
a4b143
index 9fca82a..5397bd6 100644
a4b143
--- a/src/core/device.c
a4b143
+++ b/src/core/device.c
a4b143
@@ -70,7 +70,7 @@ static void device_init(Unit *u) {
a4b143
          * indefinitely for plugged in devices, something which cannot
a4b143
          * happen for the other units since their operations time out
a4b143
          * anyway. */
a4b143
-        UNIT(d)->job_timeout = DEFAULT_TIMEOUT_USEC;
a4b143
+        UNIT(d)->job_timeout = u->manager->default_timeout_start_usec;
a4b143
 
a4b143
         UNIT(d)->ignore_on_isolate = true;
a4b143
         UNIT(d)->ignore_on_snapshot = true;
a4b143
diff --git a/src/core/main.c b/src/core/main.c
572a44
index fe291f8..937994c 100644
a4b143
--- a/src/core/main.c
a4b143
+++ b/src/core/main.c
a4b143
@@ -90,6 +90,9 @@ static bool arg_switched_root = false;
a4b143
 static char ***arg_join_controllers = NULL;
a4b143
 static ExecOutput arg_default_std_output = EXEC_OUTPUT_JOURNAL;
a4b143
 static ExecOutput arg_default_std_error = EXEC_OUTPUT_INHERIT;
a4b143
+static usec_t arg_default_restart_usec = DEFAULT_RESTART_USEC;
a4b143
+static usec_t arg_default_timeout_start_usec = DEFAULT_TIMEOUT_USEC;
a4b143
+static usec_t arg_default_timeout_stop_usec = DEFAULT_TIMEOUT_USEC;
a4b143
 static usec_t arg_runtime_watchdog = 0;
a4b143
 static usec_t arg_shutdown_watchdog = 10 * USEC_PER_MINUTE;
a4b143
 static char **arg_default_environment = NULL;
a4b143
@@ -636,6 +639,9 @@ static int parse_config_file(void) {
a4b143
                 { "Manager", "CPUAffinity",           config_parse_cpu_affinity2, 0, NULL                    },
a4b143
                 { "Manager", "DefaultStandardOutput", config_parse_output,       0, &arg_default_std_output  },
a4b143
                 { "Manager", "DefaultStandardError",  config_parse_output,       0, &arg_default_std_error   },
a4b143
+                { "Manager", "DefaultTimeoutStartSec", config_parse_sec,         0, &arg_default_timeout_start_usec },
a4b143
+                { "Manager", "DefaultTimeoutStopSec", config_parse_sec,          0, &arg_default_timeout_stop_usec  },
a4b143
+                { "Manager", "DefaultRestartSec",     config_parse_sec,          0, &arg_default_restart_usec  },
a4b143
                 { "Manager", "JoinControllers",       config_parse_join_controllers, 0, &arg_join_controllers },
a4b143
                 { "Manager", "RuntimeWatchdogSec",    config_parse_sec,          0, &arg_runtime_watchdog    },
a4b143
                 { "Manager", "ShutdownWatchdogSec",   config_parse_sec,          0, &arg_shutdown_watchdog   },
a4b143
@@ -1542,6 +1548,9 @@ int main(int argc, char *argv[]) {
a4b143
         m->confirm_spawn = arg_confirm_spawn;
a4b143
         m->default_std_output = arg_default_std_output;
a4b143
         m->default_std_error = arg_default_std_error;
a4b143
+        m->default_restart_usec = arg_default_restart_usec;
a4b143
+        m->default_timeout_start_usec = arg_default_timeout_start_usec;
a4b143
+        m->default_timeout_stop_usec = arg_default_timeout_stop_usec;
a4b143
         m->runtime_watchdog = arg_runtime_watchdog;
a4b143
         m->shutdown_watchdog = arg_shutdown_watchdog;
a4b143
         m->userspace_timestamp = userspace_timestamp;
a4b143
diff --git a/src/core/manager.h b/src/core/manager.h
a4b143
index a3049b5..e74c609 100644
a4b143
--- a/src/core/manager.h
a4b143
+++ b/src/core/manager.h
a4b143
@@ -230,6 +230,9 @@ struct Manager {
a4b143
 
a4b143
         ExecOutput default_std_output, default_std_error;
a4b143
 
a4b143
+        usec_t default_restart_usec, default_timeout_start_usec,
a4b143
+                default_timeout_stop_usec;
a4b143
+
a4b143
         struct rlimit *rlimit[RLIMIT_NLIMITS];
a4b143
 
a4b143
         /* non-zero if we are reloading or reexecuting, */
a4b143
diff --git a/src/core/mount.c b/src/core/mount.c
a4b143
index 70cd372..c0445a6 100644
a4b143
--- a/src/core/mount.c
a4b143
+++ b/src/core/mount.c
a4b143
@@ -131,7 +131,7 @@ static void mount_init(Unit *u) {
a4b143
         assert(u);
a4b143
         assert(u->load_state == UNIT_STUB);
a4b143
 
a4b143
-        m->timeout_usec = DEFAULT_TIMEOUT_USEC;
a4b143
+        m->timeout_usec = u->manager->default_timeout_start_usec;
a4b143
         m->directory_mode = 0755;
a4b143
 
a4b143
         exec_context_init(&m->exec_context);
a4b143
diff --git a/src/core/scope.c b/src/core/scope.c
a4b143
index 50e5dba..41da3b9 100644
a4b143
--- a/src/core/scope.c
a4b143
+++ b/src/core/scope.c
a4b143
@@ -46,7 +46,7 @@ static void scope_init(Unit *u) {
a4b143
         assert(u);
a4b143
         assert(u->load_state == UNIT_STUB);
a4b143
 
a4b143
-        s->timeout_stop_usec = DEFAULT_TIMEOUT_USEC;
a4b143
+        s->timeout_stop_usec = u->manager->default_timeout_stop_usec;
a4b143
 
a4b143
         watch_init(&s->timer_watch);
a4b143
 
a4b143
diff --git a/src/core/service.c b/src/core/service.c
572a44
index 96ed2d3..e81aa1f 100644
a4b143
--- a/src/core/service.c
a4b143
+++ b/src/core/service.c
a4b143
@@ -124,9 +124,9 @@ static void service_init(Unit *u) {
a4b143
         assert(u);
a4b143
         assert(u->load_state == UNIT_STUB);
a4b143
 
a4b143
-        s->timeout_start_usec = DEFAULT_TIMEOUT_USEC;
a4b143
-        s->timeout_stop_usec = DEFAULT_TIMEOUT_USEC;
a4b143
-        s->restart_usec = DEFAULT_RESTART_USEC;
a4b143
+        s->timeout_start_usec = u->manager->default_timeout_start_usec;
a4b143
+        s->timeout_stop_usec = u->manager->default_timeout_stop_usec;
a4b143
+        s->restart_usec = u->manager->default_restart_usec;
a4b143
         s->type = _SERVICE_TYPE_INVALID;
a4b143
 
a4b143
         watch_init(&s->watchdog_watch);
a4b143
diff --git a/src/core/socket.c b/src/core/socket.c
572a44
index 6c0ac1a..d368f7e 100644
a4b143
--- a/src/core/socket.c
a4b143
+++ b/src/core/socket.c
a4b143
@@ -73,7 +73,7 @@ static void socket_init(Unit *u) {
a4b143
         assert(u->load_state == UNIT_STUB);
a4b143
 
a4b143
         s->backlog = SOMAXCONN;
a4b143
-        s->timeout_usec = DEFAULT_TIMEOUT_USEC;
a4b143
+        s->timeout_usec = u->manager->default_timeout_start_usec;
a4b143
         s->directory_mode = 0755;
a4b143
         s->socket_mode = 0666;
a4b143
 
a4b143
diff --git a/src/core/swap.c b/src/core/swap.c
572a44
index a68ab7c..147f710 100644
a4b143
--- a/src/core/swap.c
a4b143
+++ b/src/core/swap.c
a4b143
@@ -86,7 +86,7 @@ static void swap_init(Unit *u) {
a4b143
         assert(s);
a4b143
         assert(UNIT(s)->load_state == UNIT_STUB);
a4b143
 
a4b143
-        s->timeout_usec = DEFAULT_TIMEOUT_USEC;
a4b143
+        s->timeout_usec = u->manager->default_timeout_start_usec;
a4b143
 
a4b143
         exec_context_init(&s->exec_context);
a4b143
         s->exec_context.std_output = u->manager->default_std_output;
a4b143
diff --git a/src/core/system.conf b/src/core/system.conf
a4b143
index 7b03c87..3c6cc03 100644
a4b143
--- a/src/core/system.conf
a4b143
+++ b/src/core/system.conf
a4b143
@@ -24,6 +24,9 @@
a4b143
 #ShutdownWatchdogSec=10min
a4b143
 #CapabilityBoundingSet=
a4b143
 #TimerSlackNSec=
a4b143
+#DefaultTimeoutStartSec=90s
a4b143
+#DefaultTimeoutStopSec=90s
a4b143
+#DefaultRestartSec=100ms
a4b143
 #DefaultEnvironment=
a4b143
 #DefaultLimitCPU=
a4b143
 #DefaultLimitFSIZE=
a4b143
diff --git a/src/core/user.conf b/src/core/user.conf
a4b143
index 4a0129a..b030701 100644
a4b143
--- a/src/core/user.conf
a4b143
+++ b/src/core/user.conf
a4b143
@@ -14,3 +14,6 @@
a4b143
 #LogLocation=no
a4b143
 #DefaultStandardOutput=inherit
a4b143
 #DefaultStandardError=inherit
a4b143
+#DefaultTimeoutStartSec=90s
a4b143
+#DefaultTimeoutStopSec=90s
a4b143
+#DefaultRestartSec=100ms