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