ryantimwilson / rpms / systemd

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