chiark / gitweb /
systemd: introduced new timeout types
authorMichal Sekletar <msekleta@redhat.com>
Tue, 7 Aug 2012 12:41:48 +0000 (14:41 +0200)
committerMichal Schmidt <mschmidt@redhat.com>
Wed, 8 Aug 2012 16:11:09 +0000 (18:11 +0200)
Makes possible to specify separate timeout for start and stop of
the service.

[ Improved the manpage. Coding style fix. -- michich ]

man/systemd.service.xml
src/core/dbus-service.c
src/core/load-fragment-gperf.gperf.m4
src/core/load-fragment.c
src/core/service.c
src/core/service.h

index f43201dc7e9b9501a1f36631d657c63ce846a75f..1946d85f483ea3e85a98a3c7eab67c100c92a1c3 100644 (file)
                         </varlistentry>
 
                         <varlistentry>
-                                <term><varname>TimeoutSec=</varname></term>
+                                <term><varname>TimeoutStartSec=</varname></term>
                                 <listitem><para>Configures the time to
-                                wait for start-up and stop. If a
+                                wait for start-up. If a
                                 daemon service does not signal
                                 start-up completion within the
-                                configured time the service will be
+                                configured time, the service will be
                                 considered failed and be shut down
-                                again. If a service is asked to stop
-                                but does not terminate in the
-                                specified time it will be terminated
+                                again.
+                                Takes a unit-less value in seconds, or a
+                                time span value such as "5min
+                                20s". Pass 0 to disable the timeout
+                                logic. Defaults to 90s, except when
+                                <varname>Type=oneshot</varname> is
+                                used in which case the timeout
+                                is disabled by default.
+                                </para></listitem>
+                        </varlistentry>
+
+                        <varlistentry>
+                                <term><varname>TimeoutStopSec=</varname></term>
+                                <listitem><para>Configures the time to
+                                wait for stop. If a service is asked
+                                to stop but does not terminate in the
+                                specified time, it will be terminated
                                 forcibly via SIGTERM, and after
                                 another delay of this time with
-                                SIGKILL. (See
+                                SIGKILL (See
                                 <varname>KillMode=</varname>
-                                in <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>) Takes a unit-less value in seconds, or a
+                                in <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
+                                Takes a unit-less value in seconds, or a
                                 time span value such as "5min
                                 20s". Pass 0 to disable the timeout
-                                logic. Defaults to
-                                90s, except when <varname>Type=oneshot</varname> is
-                                used in which case the timeout
-                                is disabled by default.</para></listitem>
+                                logic. Defaults to 90s.
+                                </para></listitem>
+                        </varlistentry>
+
+                        <varlistentry>
+                                <term><varname>TimeoutSec=</varname></term>
+                                <listitem><para>A shorthand for configuring
+                                both <varname>TimeoutStartSec=</varname>
+                                and <varname>TimeoutStopSec=</varname>
+                                to the specified value.
+                                </para></listitem>
                         </varlistentry>
 
                         <varlistentry>
index c0fac16d2b8fd92a4f58429c342bc1d0ed575219..129e131a6552b8f23722509397da6d7695598b6d 100644 (file)
@@ -115,7 +115,9 @@ static const BusProperty bus_service_properties[] = {
         { "PIDFile",                bus_property_append_string,       "s", offsetof(Service, pid_file),               true },
         { "NotifyAccess",           bus_service_append_notify_access, "s", offsetof(Service, notify_access)                },
         { "RestartUSec",            bus_property_append_usec,         "t", offsetof(Service, restart_usec)                 },
-        { "TimeoutUSec",            bus_property_append_usec,         "t", offsetof(Service, timeout_usec)                 },
+        { "TimeoutUSec",            bus_property_append_usec,         "t", offsetof(Service, timeout_start_usec)           },
+        { "TimeoutStartUSec",       bus_property_append_usec,         "t", offsetof(Service, timeout_start_usec)           },
+        { "TimeoutStopUSec",        bus_property_append_usec,         "t", offsetof(Service, timeout_stop_usec)            },
         { "WatchdogUSec",           bus_property_append_usec,         "t", offsetof(Service, watchdog_usec)                },
         { "WatchdogTimestamp",      bus_property_append_usec,         "t", offsetof(Service, watchdog_timestamp.realtime)  },
         { "WatchdogTimestampMonotonic",bus_property_append_usec,      "t", offsetof(Service, watchdog_timestamp.monotonic) },
index 2b1cfa073ca5170028ef1e8377448330624f4073..e738213e27cdca7d3361cfc2c226f2ceb3cfc8cc 100644 (file)
@@ -145,7 +145,9 @@ Service.ExecReload,              config_parse_exec,                  SERVICE_EXE
 Service.ExecStop,                config_parse_exec,                  SERVICE_EXEC_STOP,             offsetof(Service, exec_command)
 Service.ExecStopPost,            config_parse_exec,                  SERVICE_EXEC_STOP_POST,        offsetof(Service, exec_command)
 Service.RestartSec,              config_parse_usec,                  0,                             offsetof(Service, restart_usec)
-Service.TimeoutSec,              config_parse_service_timeout,       0,                             offsetof(Service, timeout_usec)
+Service.TimeoutSec,              config_parse_service_timeout,       0,                             offsetof(Service, timeout_start_usec)
+Service.TimeoutStartSec,         config_parse_service_timeout,       0,                             offsetof(Service, timeout_start_usec)
+Service.TimeoutStopSec,          config_parse_service_timeout,       0,                             offsetof(Service, timeout_stop_usec)
 Service.WatchdogSec,             config_parse_usec,                  0,                             offsetof(Service, watchdog_usec)
 Service.StartLimitInterval,      config_parse_usec,                  0,                             offsetof(Service, start_limit.interval)
 Service.StartLimitBurst,         config_parse_unsigned,              0,                             offsetof(Service, start_limit.burst)
index bbd82b9d2472d4cda178d530fbb49506da80cad4..10681307cfc2fe3d7d628a2f6dca6aa3faae590c 100644 (file)
@@ -1376,10 +1376,16 @@ int config_parse_service_timeout(
 
         r = config_parse_usec(filename, line, section, lvalue, ltype, rvalue, data, userdata);
 
-        if (!r)
-                s->timeout_defined = true;
+        if (r)
+                return r;
 
-        return r;
+        if (streq(lvalue, "TimeoutSec")) {
+                s->start_timeout_defined = true;
+                s->timeout_stop_usec = s->timeout_start_usec;
+        } else if (streq(lvalue, "TimeoutStartSec"))
+                s->start_timeout_defined = true;
+
+        return 0;
 }
 
 int config_parse_unit_env_file(
index 1c127bdbcb2ffc5c6926d210a63d278ea90078a8..e74da54eac5b288ed54c7c839335fb73a460807e 100644 (file)
@@ -134,7 +134,8 @@ static void service_init(Unit *u) {
         assert(u);
         assert(u->load_state == UNIT_STUB);
 
-        s->timeout_usec = DEFAULT_TIMEOUT_USEC;
+        s->timeout_start_usec = DEFAULT_TIMEOUT_USEC;
+        s->timeout_stop_usec = DEFAULT_TIMEOUT_USEC;
         s->restart_usec = DEFAULT_RESTART_USEC;
         s->type = _SERVICE_TYPE_INVALID;
 
@@ -914,9 +915,13 @@ static int service_load_sysv_path(Service *s, const char *path) {
                 UNIT(s)->default_dependencies = false;
 
                 /* Don't timeout special services during boot (like fsck) */
-                s->timeout_usec = 0;
-        } else
-                s->timeout_usec = DEFAULT_SYSV_TIMEOUT_USEC;
+                s->timeout_start_usec = 0;
+                s->timeout_stop_usec = 0;
+        } else {
+                s->timeout_start_usec = DEFAULT_SYSV_TIMEOUT_USEC;
+                s->timeout_stop_usec = DEFAULT_SYSV_TIMEOUT_USEC;
+        }
+
 
         /* Special setting for all SysV services */
         s->type = SERVICE_FORKING;
@@ -1241,9 +1246,9 @@ static int service_load(Unit *u) {
                 if (s->type == _SERVICE_TYPE_INVALID)
                         s->type = s->bus_name ? SERVICE_DBUS : SERVICE_SIMPLE;
 
-                /* Oneshot services have disabled timeout by default */
-                if (s->type == SERVICE_ONESHOT && !s->timeout_defined)
-                        s->timeout_usec = 0;
+                /* Oneshot services have disabled start timeout by default */
+                if (s->type == SERVICE_ONESHOT && !s->start_timeout_defined)
+                        s->timeout_start_usec = 0;
 
                 service_fix_output(s);
 
@@ -1603,11 +1608,10 @@ static int service_coldplug(Unit *u) {
                     s->deserialized_state == SERVICE_FINAL_SIGTERM ||
                     s->deserialized_state == SERVICE_FINAL_SIGKILL ||
                     s->deserialized_state == SERVICE_AUTO_RESTART) {
-
-                        if (s->deserialized_state == SERVICE_AUTO_RESTART || s->timeout_usec > 0) {
+                        if (s->deserialized_state == SERVICE_AUTO_RESTART || s->timeout_start_usec > 0) {
                                 usec_t k;
 
-                                k = s->deserialized_state == SERVICE_AUTO_RESTART ? s->restart_usec : s->timeout_usec;
+                                k = s->deserialized_state == SERVICE_AUTO_RESTART ? s->restart_usec : s->timeout_start_usec;
 
                                 if ((r = unit_watch_timer(UNIT(s), k, &s->timer_watch)) < 0)
                                         return r;
@@ -1753,8 +1757,9 @@ static int service_spawn(
                 }
         }
 
-        if (timeout && s->timeout_usec) {
-                if ((r = unit_watch_timer(UNIT(s), s->timeout_usec, &s->timer_watch)) < 0)
+        if (timeout && s->timeout_start_usec) {
+                r = unit_watch_timer(UNIT(s), s->timeout_start_usec, &s->timer_watch);
+                if (r < 0)
                         goto fail;
         } else
                 unit_unwatch_timer(UNIT(s), &s->timer_watch);
@@ -2011,9 +2016,11 @@ static void service_enter_signal(Service *s, ServiceState state, ServiceResult f
         }
 
         if (wait_for_exit) {
-                if (s->timeout_usec > 0)
-                        if ((r = unit_watch_timer(UNIT(s), s->timeout_usec, &s->timer_watch)) < 0)
+                if (s->timeout_stop_usec > 0) {
+                        r = unit_watch_timer(UNIT(s), s->timeout_stop_usec, &s->timer_watch);
+                        if (r < 0)
                                 goto fail;
+                }
 
                 service_set_state(s, state);
         } else if (state == SERVICE_STOP_SIGTERM || state == SERVICE_STOP_SIGKILL)
index cc63347c76adbb032eb509880179ef154a31eb66..c78de79a09c9615c1aa0f74ff9f191d454b1cd9d 100644 (file)
@@ -120,7 +120,8 @@ struct Service {
         char *pid_file;
 
         usec_t restart_usec;
-        usec_t timeout_usec;
+        usec_t timeout_start_usec;
+        usec_t timeout_stop_usec;
 
         dual_timestamp watchdog_timestamp;
         usec_t watchdog_usec;
@@ -166,7 +167,7 @@ struct Service {
         bool bus_name_good:1;
         bool forbid_restart:1;
         bool got_socket_fd:1;
-        bool timeout_defined:1;
+        bool start_timeout_defined:1;
 #ifdef HAVE_SYSV_COMPAT
         bool is_sysv:1;
         bool sysv_has_lsb:1;