daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
9fc0f6
From 409dbe76d743448629167f4412f290bba1aae11e Mon Sep 17 00:00:00 2001
9fc0f6
From: Lukas Nykryn <lnykryn@redhat.com>
9fc0f6
Date: Fri, 8 Nov 2013 16:01:22 +0100
9fc0f6
Subject: [PATCH] manager: configurable StartLimit default values
9fc0f6
9fc0f6
https://bugzilla.redhat.com/show_bug.cgi?id=821723
9fc0f6
---
9fc0f6
 man/systemd-system.conf.xml | 13 +++++++++++++
9fc0f6
 man/systemd.service.xml     |  9 ++++++---
9fc0f6
 src/core/main.c             |  6 ++++++
9fc0f6
 src/core/manager.h          |  3 +++
9fc0f6
 src/core/service.c          |  4 +++-
9fc0f6
 src/core/system.conf        |  2 ++
9fc0f6
 src/core/user.conf          |  2 ++
9fc0f6
 src/shared/def.h            |  3 +++
9fc0f6
 8 files changed, 38 insertions(+), 4 deletions(-)
9fc0f6
9fc0f6
diff --git a/man/systemd-system.conf.xml b/man/systemd-system.conf.xml
9fc0f6
index c1f2648..9a1a99f 100644
9fc0f6
--- a/man/systemd-system.conf.xml
9fc0f6
+++ b/man/systemd-system.conf.xml
9fc0f6
@@ -115,6 +115,19 @@
9fc0f6
                                 <varname>TimeoutSec=</varname> value.
9fc0f6
                                 </para></listitem>
9fc0f6
                         </varlistentry>
9fc0f6
+                        <varlistentry>
9fc0f6
+                                <term><varname>DefaultStartLimitInterval=</varname></term>
9fc0f6
+                                <term><varname>DefaultStartLimitBurst=</varname></term>
9fc0f6
+
9fc0f6
+                                <listitem><para>Configure the default start rate
9fc0f6
+                                limiting, as configured per-service by
9fc0f6
+                                <varname>StartLimitInterval=</varname> and
9fc0f6
+                                <varname>StartLimitBurst=</varname>. See
9fc0f6
+                                <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
9fc0f6
+                                for details on the per-service
9fc0f6
+                                settings).
9fc0f6
+                                </para></listitem>
9fc0f6
+                        </varlistentry>
9fc0f6
 
9fc0f6
                         <varlistentry>
9fc0f6
                                 <term><varname>CPUAffinity=</varname></term>
9fc0f6
diff --git a/man/systemd.service.xml b/man/systemd.service.xml
9fc0f6
index df04048..3f31c11 100644
9fc0f6
--- a/man/systemd.service.xml
9fc0f6
+++ b/man/systemd.service.xml
9fc0f6
@@ -863,12 +863,15 @@
9fc0f6
                                 these two options, this rate limiting
9fc0f6
                                 may be modified. Use
9fc0f6
                                 <varname>StartLimitInterval=</varname>
9fc0f6
-                                to configure the checking interval
9fc0f6
-                                (defaults to 10s, set to 0 to disable
9fc0f6
+                                to configure the checking interval (defaults to
9fc0f6
+                                <varname>DefaultStartLimitInterval=</varname> in
9fc0f6
+                                manager configuration file, set to 0 to disable
9fc0f6
                                 any kind of rate limiting). Use
9fc0f6
                                 <varname>StartLimitBurst=</varname> to
9fc0f6
                                 configure how many starts per interval
9fc0f6
-                                are allowed (defaults to 5). These
9fc0f6
+                                are allowed (defaults to
9fc0f6
+                                <varname>DefaultStartLimitBurst=</varname> in
9fc0f6
+                                manager configuration file). These
9fc0f6
                                 configuration options are particularly
9fc0f6
                                 useful in conjunction with
9fc0f6
                                 <varname>Restart=</varname>, however
9fc0f6
diff --git a/src/core/main.c b/src/core/main.c
9fc0f6
index 937994c..00fd394 100644
9fc0f6
--- a/src/core/main.c
9fc0f6
+++ b/src/core/main.c
9fc0f6
@@ -93,6 +93,8 @@ static ExecOutput arg_default_std_error = EXEC_OUTPUT_INHERIT;
9fc0f6
 static usec_t arg_default_restart_usec = DEFAULT_RESTART_USEC;
9fc0f6
 static usec_t arg_default_timeout_start_usec = DEFAULT_TIMEOUT_USEC;
9fc0f6
 static usec_t arg_default_timeout_stop_usec = DEFAULT_TIMEOUT_USEC;
9fc0f6
+static usec_t arg_default_start_limit_interval = DEFAULT_START_LIMIT_INTERVAL;
9fc0f6
+static unsigned arg_default_start_limit_burst = DEFAULT_START_LIMIT_BURST;
9fc0f6
 static usec_t arg_runtime_watchdog = 0;
9fc0f6
 static usec_t arg_shutdown_watchdog = 10 * USEC_PER_MINUTE;
9fc0f6
 static char **arg_default_environment = NULL;
9fc0f6
@@ -642,6 +644,8 @@ static int parse_config_file(void) {
9fc0f6
                 { "Manager", "DefaultTimeoutStartSec", config_parse_sec,         0, &arg_default_timeout_start_usec },
9fc0f6
                 { "Manager", "DefaultTimeoutStopSec", config_parse_sec,          0, &arg_default_timeout_stop_usec  },
9fc0f6
                 { "Manager", "DefaultRestartSec",     config_parse_sec,          0, &arg_default_restart_usec  },
9fc0f6
+                { "Manager", "DefaultStartLimitInterval", config_parse_sec,      0, &arg_default_start_limit_interval },
9fc0f6
+                { "Manager", "DefaultStartLimitBurst", config_parse_unsigned,    0, &arg_default_start_limit_burst },
9fc0f6
                 { "Manager", "JoinControllers",       config_parse_join_controllers, 0, &arg_join_controllers },
9fc0f6
                 { "Manager", "RuntimeWatchdogSec",    config_parse_sec,          0, &arg_runtime_watchdog    },
9fc0f6
                 { "Manager", "ShutdownWatchdogSec",   config_parse_sec,          0, &arg_shutdown_watchdog   },
9fc0f6
@@ -1551,6 +1555,8 @@ int main(int argc, char *argv[]) {
9fc0f6
         m->default_restart_usec = arg_default_restart_usec;
9fc0f6
         m->default_timeout_start_usec = arg_default_timeout_start_usec;
9fc0f6
         m->default_timeout_stop_usec = arg_default_timeout_stop_usec;
9fc0f6
+        m->default_start_limit_interval = arg_default_start_limit_interval;
9fc0f6
+        m->default_start_limit_burst = arg_default_start_limit_burst;
9fc0f6
         m->runtime_watchdog = arg_runtime_watchdog;
9fc0f6
         m->shutdown_watchdog = arg_shutdown_watchdog;
9fc0f6
         m->userspace_timestamp = userspace_timestamp;
9fc0f6
diff --git a/src/core/manager.h b/src/core/manager.h
9fc0f6
index e74c609..ee42c5e 100644
9fc0f6
--- a/src/core/manager.h
9fc0f6
+++ b/src/core/manager.h
9fc0f6
@@ -233,6 +233,9 @@ struct Manager {
9fc0f6
         usec_t default_restart_usec, default_timeout_start_usec,
9fc0f6
                 default_timeout_stop_usec;
9fc0f6
 
9fc0f6
+        usec_t default_start_limit_interval;
9fc0f6
+        unsigned default_start_limit_burst;
9fc0f6
+
9fc0f6
         struct rlimit *rlimit[RLIMIT_NLIMITS];
9fc0f6
 
9fc0f6
         /* non-zero if we are reloading or reexecuting, */
9fc0f6
diff --git a/src/core/service.c b/src/core/service.c
9fc0f6
index e81aa1f..5662180 100644
9fc0f6
--- a/src/core/service.c
9fc0f6
+++ b/src/core/service.c
9fc0f6
@@ -143,7 +143,9 @@ static void service_init(Unit *u) {
9fc0f6
         kill_context_init(&s->kill_context);
9fc0f6
         cgroup_context_init(&s->cgroup_context);
9fc0f6
 
9fc0f6
-        RATELIMIT_INIT(s->start_limit, 10*USEC_PER_SEC, 5);
9fc0f6
+        RATELIMIT_INIT(s->start_limit,
9fc0f6
+                       u->manager->default_start_limit_interval,
9fc0f6
+                       u->manager->default_start_limit_burst);
9fc0f6
 
9fc0f6
         s->control_command_id = _SERVICE_EXEC_COMMAND_INVALID;
9fc0f6
 }
9fc0f6
diff --git a/src/core/system.conf b/src/core/system.conf
9fc0f6
index 3c6cc03..38bbca5 100644
9fc0f6
--- a/src/core/system.conf
9fc0f6
+++ b/src/core/system.conf
9fc0f6
@@ -27,6 +27,8 @@
9fc0f6
 #DefaultTimeoutStartSec=90s
9fc0f6
 #DefaultTimeoutStopSec=90s
9fc0f6
 #DefaultRestartSec=100ms
9fc0f6
+#DefaultStartLimitInterval=10s
9fc0f6
+#DefaultStartLimitBurst=5
9fc0f6
 #DefaultEnvironment=
9fc0f6
 #DefaultLimitCPU=
9fc0f6
 #DefaultLimitFSIZE=
9fc0f6
diff --git a/src/core/user.conf b/src/core/user.conf
9fc0f6
index b030701..923ca66 100644
9fc0f6
--- a/src/core/user.conf
9fc0f6
+++ b/src/core/user.conf
9fc0f6
@@ -17,3 +17,5 @@
9fc0f6
 #DefaultTimeoutStartSec=90s
9fc0f6
 #DefaultTimeoutStopSec=90s
9fc0f6
 #DefaultRestartSec=100ms
9fc0f6
+#DefaultStartLimitInterval=10s
9fc0f6
+#DefaultStartLimitBurst=5
9fc0f6
diff --git a/src/shared/def.h b/src/shared/def.h
9fc0f6
index edd0bcf..e4ef735 100644
9fc0f6
--- a/src/shared/def.h
9fc0f6
+++ b/src/shared/def.h
9fc0f6
@@ -27,6 +27,9 @@
9fc0f6
 #define DEFAULT_RESTART_USEC (100*USEC_PER_MSEC)
9fc0f6
 #define DEFAULT_CONFIRM_USEC (30*USEC_PER_SEC)
9fc0f6
 
9fc0f6
+#define DEFAULT_START_LIMIT_INTERVAL (10*USEC_PER_SEC)
9fc0f6
+#define DEFAULT_START_LIMIT_BURST 5
9fc0f6
+
9fc0f6
 #define DEFAULT_EXIT_USEC (5*USEC_PER_MINUTE)
9fc0f6
 
9fc0f6
 #define SYSTEMD_CGROUP_CONTROLLER "name=systemd"