chiark / gitweb /
service: introduce Restart=on-failure and Restart=on-abort
authorLennart Poettering <lennart@poettering.net>
Fri, 8 Oct 2010 16:34:54 +0000 (18:34 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 8 Oct 2010 16:34:54 +0000 (18:34 +0200)
TODO
man/systemd.service.xml
src/service.c
src/service.h

diff --git a/TODO b/TODO
index 0a7efa111a279342d0e411227c72c850f3bba845..3828a1132610e8ca79cafd41013eb95a96e72b13 100644 (file)
--- a/TODO
+++ b/TODO
@@ -84,8 +84,6 @@
 
 * enable syslog.socket by default, activating our kmsg bridge
 
 
 * enable syslog.socket by default, activating our kmsg bridge
 
-* Restart=on-failure and Restart=on-abort
-
 * when processes remain in a service even though the start command failed enter active
 
 * fix plymouth socket, when plymouth started to use a clean one
 * when processes remain in a service even though the start command failed enter active
 
 * fix plymouth socket, when plymouth started to use a clean one
index 66806f1bd25d0b14fe194bfb7f170e7cb7319e17..c9cd51f739dda1cd0da27273fc07f9fb0c3d3a5a 100644 (file)
                         <varlistentry>
                                 <term><varname>Restart=</varname></term>
                                 <listitem><para>Configures whether the
                         <varlistentry>
                                 <term><varname>Restart=</varname></term>
                                 <listitem><para>Configures whether the
-                                main service process shall be restarted when
-                                it exists. Takes one of
+                                main service process shall be
+                                restarted when it exists. Takes one of
                                 <option>no</option>,
                                 <option>no</option>,
-                                <option>on-success</option> or
-                                <option>always</option>. If
-                                set to <option>no</option> (the
-                                default) the service will not be
-                                restarted when it exits. If set to
-                                <option>on-success</option> it
-                                will be restarted only when it exited
-                                cleanly, i.e. terminated with an exit
-                                code of 0. If set to
-                                <option>always</option> the
+                                <option>on-success</option>,
+                                <option>on-failure</option>,
+                                <option>on-abort</option> or
+                                <option>always</option>. If set to
+                                <option>no</option> (the default) the
+                                service will not be restarted when it
+                                exits. If set to
+                                <option>on-success</option> it will be
+                                restarted only when it exited cleanly,
+                                i.e. terminated with an exit code of
+                                0. If set to
+                                <option>on-failure</option> it will be
+                                restared only when it exited with an
+                                exit code not equalling 0, or when
+                                terminated by a signal. If set to
+                                <option>on-abort</option> it will be
+                                restarted only if it exits due to
+                                reception of an uncaught signal. If
+                                set to <option>always</option> the
                                 service will be restarted regardless
                                 whether it exited cleanly or not, or
                                 got terminated abnormally by a
                                 service will be restarted regardless
                                 whether it exited cleanly or not, or
                                 got terminated abnormally by a
index 04496a2dd2913897801e8db5f63b6564b5405b73..d3852c76a13644570b7d8967e90e6570c6b2cb21 100644 (file)
@@ -1627,7 +1627,11 @@ static void service_enter_dead(Service *s, bool success, bool allow_restart) {
         if (allow_restart &&
             !s->forbid_restart &&
             (s->restart == SERVICE_RESTART_ALWAYS ||
         if (allow_restart &&
             !s->forbid_restart &&
             (s->restart == SERVICE_RESTART_ALWAYS ||
-             (s->restart == SERVICE_RESTART_ON_SUCCESS && !s->failure))) {
+             (s->restart == SERVICE_RESTART_ON_SUCCESS && !s->failure) ||
+             (s->restart == SERVICE_RESTART_ON_FAILURE && s->failure) ||
+             (s->restart == SERVICE_RESTART_ON_ABORT && s->failure &&
+              (s->main_exec_status.code == CLD_KILLED ||
+               s->main_exec_status.code == CLD_DUMPED)))) {
 
                 if ((r = unit_watch_timer(UNIT(s), s->restart_usec, &s->timer_watch)) < 0)
                         goto fail;
 
                 if ((r = unit_watch_timer(UNIT(s), s->restart_usec, &s->timer_watch)) < 0)
                         goto fail;
@@ -3115,7 +3119,9 @@ DEFINE_STRING_TABLE_LOOKUP(service_state, ServiceState);
 static const char* const service_restart_table[_SERVICE_RESTART_MAX] = {
         [SERVICE_RESTART_NO] = "no",
         [SERVICE_RESTART_ON_SUCCESS] = "on-success",
 static const char* const service_restart_table[_SERVICE_RESTART_MAX] = {
         [SERVICE_RESTART_NO] = "no",
         [SERVICE_RESTART_ON_SUCCESS] = "on-success",
-        [SERVICE_RESTART_ALWAYS] = "always",
+        [SERVICE_RESTART_ON_FAILURE] = "on-failure",
+        [SERVICE_RESTART_ON_ABORT] = "on-abort",
+        [SERVICE_RESTART_ALWAYS] = "always"
 };
 
 DEFINE_STRING_TABLE_LOOKUP(service_restart, ServiceRestart);
 };
 
 DEFINE_STRING_TABLE_LOOKUP(service_restart, ServiceRestart);
index f47346702f54634cceda131cd1c71d98427dad75..eb44a43895709a4592fd3e407944197254ce59a9 100644 (file)
@@ -50,6 +50,8 @@ typedef enum ServiceState {
 typedef enum ServiceRestart {
         SERVICE_RESTART_NO,
         SERVICE_RESTART_ON_SUCCESS,
 typedef enum ServiceRestart {
         SERVICE_RESTART_NO,
         SERVICE_RESTART_ON_SUCCESS,
+        SERVICE_RESTART_ON_FAILURE,
+        SERVICE_RESTART_ON_ABORT,
         SERVICE_RESTART_ALWAYS,
         _SERVICE_RESTART_MAX,
         _SERVICE_RESTART_INVALID = -1
         SERVICE_RESTART_ALWAYS,
         _SERVICE_RESTART_MAX,
         _SERVICE_RESTART_INVALID = -1