ryantimwilson / rpms / systemd

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