chiark / gitweb /
unit: introduce OnFailureIsolate=
authorLennart Poettering <lennart@poettering.net>
Thu, 7 Apr 2011 02:11:31 +0000 (04:11 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 7 Apr 2011 02:11:31 +0000 (04:11 +0200)
TODO
man/systemd.unit.xml
src/dbus-unit.h
src/job.c
src/load-fragment.c
src/unit.c
src/unit.h

diff --git a/TODO b/TODO
index e8c1388ed68072a1c60b6168b4255b438d35eb9f..af264d3a2046c8d5becd9cc1f9f570de2ad00bd0 100644 (file)
--- a/TODO
+++ b/TODO
@@ -12,9 +12,11 @@ F15:
 
 * ntpd should pull in time-sync.target. (PENDING)
 
 
 * ntpd should pull in time-sync.target. (PENDING)
 
+* bluetooth should be possible to disable (PENDING)
+
 * add fstab fields to add wait timeouts, change Wants to Requires by local-fs.target
 
 * add fstab fields to add wait timeouts, change Wants to Requires by local-fs.target
 
-* hook emergency.target into local-fs.target in some way as OnFailure with isolate
+* hook emergency.target into local-fs.target in some way as OnFailure with isolate, add warning log message
 
 * bind mounts are ignored
   https://bugzilla.redhat.com/show_bug.cgi?id=682662
 
 * bind mounts are ignored
   https://bugzilla.redhat.com/show_bug.cgi?id=682662
@@ -22,12 +24,10 @@ F15:
 * 0595f9a1c182a84581749823ef47c5f292e545f9 is borked, freezes shutdown
     (path: after installing inotify watches, recheck file again to fix race)
 
 * 0595f9a1c182a84581749823ef47c5f292e545f9 is borked, freezes shutdown
     (path: after installing inotify watches, recheck file again to fix race)
 
-* bluetooth should be possible to disable
+Features:
 
 * fix alsa mixer restore to not print error when no config is stored
 
 
 * fix alsa mixer restore to not print error when no config is stored
 
-Features:
-
 * don't trim empty cgroups
   https://bugzilla.redhat.com/show_bug.cgi?id=678555
 
 * don't trim empty cgroups
   https://bugzilla.redhat.com/show_bug.cgi?id=678555
 
@@ -49,7 +49,7 @@ Features:
 
 * introduce /usr/lib/binfmt.d/, /usr/lib/tmpfiles.d/
 
 
 * introduce /usr/lib/binfmt.d/, /usr/lib/tmpfiles.d/
 
-* in pam_systemd: don't rely on /proc/self/loginuid in a container
+* in pam_systemd: don't rely on /proc/self/loginuid in a container (check if audit caps are there)
 
 * take BSD file lock on tty devices when using them?
 
 
 * take BSD file lock on tty devices when using them?
 
index 5460ebeb2f1923755cbcfd2b625cce11d9c56178..0fc2fbe730614c1271b65c014128eb8dd2ae88c5 100644 (file)
                                 state.</para></listitem>
                         </varlistentry>
 
                                 state.</para></listitem>
                         </varlistentry>
 
+                        <varlistentry>
+                                <term><varname>OnFailureIsolate=</varname></term>
+
+                                <listitem><para>Takes a boolean
+                                argument. If <option>true</option> the
+                                unit listed in
+                                <varname>OnFailure=</varname> will be
+                                enqueued in isolation mode, i.e. all
+                                units that are not its dependency will
+                                be stopped. If this is set only a
+                                single unit may be listed in
+                                <varname>OnFailure=</varname>. Defaults
+                                to
+                                <option>false</option>.</para></listitem>
+                        </varlistentry>
+
                         <varlistentry>
                                 <term><varname>StopWhenUnneeded=</varname></term>
 
                         <varlistentry>
                                 <term><varname>StopWhenUnneeded=</varname></term>
 
index efb61797f40521efdb976b7c3e540a7d438b8c35..dfbc82c0c553961b53ca5ca9fc954087d709f167 100644 (file)
         { "org.freedesktop.systemd1.Unit", "RefuseManualStop",     bus_property_append_bool,       "b",    &u->meta.refuse_manual_stop       }, \
         { "org.freedesktop.systemd1.Unit", "AllowIsolate",         bus_property_append_bool,       "b",    &u->meta.allow_isolate            }, \
         { "org.freedesktop.systemd1.Unit", "DefaultDependencies",  bus_property_append_bool,       "b",    &u->meta.default_dependencies     }, \
         { "org.freedesktop.systemd1.Unit", "RefuseManualStop",     bus_property_append_bool,       "b",    &u->meta.refuse_manual_stop       }, \
         { "org.freedesktop.systemd1.Unit", "AllowIsolate",         bus_property_append_bool,       "b",    &u->meta.allow_isolate            }, \
         { "org.freedesktop.systemd1.Unit", "DefaultDependencies",  bus_property_append_bool,       "b",    &u->meta.default_dependencies     }, \
+        { "org.freedesktop.systemd1.Unit", "OnFailureIsolate",     bus_property_append_bool,       "b",    &u->meta.on_failure_isolate       }, \
         { "org.freedesktop.systemd1.Unit", "DefaultControlGroup",  bus_unit_append_default_cgroup, "s",    u                                 }, \
         { "org.freedesktop.systemd1.Unit", "ControlGroup",         bus_unit_append_cgroups,        "as",   u                                 }, \
         { "org.freedesktop.systemd1.Unit", "NeedDaemonReload",     bus_unit_append_need_daemon_reload, "b", u                                }, \
         { "org.freedesktop.systemd1.Unit", "DefaultControlGroup",  bus_unit_append_default_cgroup, "s",    u                                 }, \
         { "org.freedesktop.systemd1.Unit", "ControlGroup",         bus_unit_append_cgroups,        "as",   u                                 }, \
         { "org.freedesktop.systemd1.Unit", "NeedDaemonReload",     bus_unit_append_need_daemon_reload, "b", u                                }, \
index a3be7becaf5e41e1e90d894e6cb5858dfb28ca08..dcfa323b0ef1cf9b4ef75326f17960e18c91b518 100644 (file)
--- a/src/job.c
+++ b/src/job.c
@@ -563,8 +563,14 @@ int job_finish_and_invalidate(Job *j, JobResult result) {
          * the unit itself. We don't tread JOB_CANCELED as failure in
          * this context. And JOB_FAILURE is already handled by the
          * unit itself. */
          * the unit itself. We don't tread JOB_CANCELED as failure in
          * this context. And JOB_FAILURE is already handled by the
          * unit itself. */
-        if (result == JOB_TIMEOUT || result == JOB_DEPENDENCY)
+        if (result == JOB_TIMEOUT || result == JOB_DEPENDENCY) {
+                log_notice("Job %s/%s failed with result '%s'.",
+                           u->meta.id,
+                           job_type_to_string(t),
+                           job_result_to_string(result));
+
                 unit_trigger_on_failure(u);
                 unit_trigger_on_failure(u);
+        }
 
         /* Try to start the next jobs that can be started */
         SET_FOREACH(other, u->meta.dependencies[UNIT_AFTER], i)
 
         /* Try to start the next jobs that can be started */
         SET_FOREACH(other, u->meta.dependencies[UNIT_AFTER], i)
index 8635bdb226b6eee2397ee290120fa122e1db703e..c27c9d84777fa0bcae57688ac8980d746d6b854e 100644 (file)
@@ -1851,6 +1851,7 @@ static int load_from_path(Unit *u, const char *path) {
                 { "RefuseManualStop",       config_parse_bool,            0, &u->meta.refuse_manual_stop,                     "Unit"    },
                 { "AllowIsolate",           config_parse_bool,            0, &u->meta.allow_isolate,                          "Unit"    },
                 { "DefaultDependencies",    config_parse_bool,            0, &u->meta.default_dependencies,                   "Unit"    },
                 { "RefuseManualStop",       config_parse_bool,            0, &u->meta.refuse_manual_stop,                     "Unit"    },
                 { "AllowIsolate",           config_parse_bool,            0, &u->meta.allow_isolate,                          "Unit"    },
                 { "DefaultDependencies",    config_parse_bool,            0, &u->meta.default_dependencies,                   "Unit"    },
+                { "OnFailureIsolate",       config_parse_bool,            0, &u->meta.on_failure_isolate,                     "Unit"    },
                 { "JobTimeoutSec",          config_parse_usec,            0, &u->meta.job_timeout,                            "Unit"    },
                 { "ConditionPathExists",        config_parse_condition_path, CONDITION_PATH_EXISTS, u,                        "Unit"    },
                 { "ConditionPathIsDirectory",   config_parse_condition_path, CONDITION_PATH_IS_DIRECTORY, u,                  "Unit"    },
                 { "JobTimeoutSec",          config_parse_usec,            0, &u->meta.job_timeout,                            "Unit"    },
                 { "ConditionPathExists",        config_parse_condition_path, CONDITION_PATH_EXISTS, u,                        "Unit"    },
                 { "ConditionPathIsDirectory",   config_parse_condition_path, CONDITION_PATH_IS_DIRECTORY, u,                  "Unit"    },
index e4345aeffe30529acb952f4876222f915b651d93..90773e894f55891c6133c44f0f1328c7f7550068 100644 (file)
@@ -666,11 +666,13 @@ void unit_dump(Unit *u, FILE *f, const char *prefix) {
                         "%s\tStopWhenUnneeded: %s\n"
                         "%s\tRefuseManualStart: %s\n"
                         "%s\tRefuseManualStop: %s\n"
                         "%s\tStopWhenUnneeded: %s\n"
                         "%s\tRefuseManualStart: %s\n"
                         "%s\tRefuseManualStop: %s\n"
-                        "%s\tDefaultDependencies: %s\n",
+                        "%s\tDefaultDependencies: %s\n"
+                        "%s\rOnFailureIsolate: %s\n",
                         prefix, yes_no(u->meta.stop_when_unneeded),
                         prefix, yes_no(u->meta.refuse_manual_start),
                         prefix, yes_no(u->meta.refuse_manual_stop),
                         prefix, yes_no(u->meta.stop_when_unneeded),
                         prefix, yes_no(u->meta.refuse_manual_start),
                         prefix, yes_no(u->meta.refuse_manual_stop),
-                        prefix, yes_no(u->meta.default_dependencies));
+                        prefix, yes_no(u->meta.default_dependencies),
+                        prefix, yes_no(u->meta.on_failure_isolate));
 
                 LIST_FOREACH(by_unit, b, u->meta.cgroup_bondings)
                         fprintf(f, "%s\tControlGroup: %s:%s\n",
 
                 LIST_FOREACH(by_unit, b, u->meta.cgroup_bondings)
                         fprintf(f, "%s\tControlGroup: %s:%s\n",
@@ -1096,8 +1098,17 @@ void unit_trigger_on_failure(Unit *u) {
 
         assert(u);
 
 
         assert(u);
 
-        SET_FOREACH(other, u->meta.dependencies[UNIT_ON_FAILURE], i)
-                manager_add_job(u->meta.manager, JOB_START, other, JOB_REPLACE, true, NULL, NULL);
+        if (set_size(u->meta.dependencies[UNIT_ON_FAILURE]) <= 0)
+                return;
+
+        log_info("Triggering OnFailure= dependencies of %s.", u->meta.id);
+
+        SET_FOREACH(other, u->meta.dependencies[UNIT_ON_FAILURE], i) {
+                int r;
+
+                if ((r = manager_add_job(u->meta.manager, JOB_START, other, u->meta.on_failure_isolate ? JOB_ISOLATE : JOB_REPLACE, true, NULL, NULL)) < 0)
+                        log_error("Failed to enqueue OnFailure= job: %s", strerror(-r));
+        }
 }
 
 void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_success) {
 }
 
 void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_success) {
index 4245f3cf1ca7875b6963fd2566169d98d74f3b30..2c5cacd9e31a4b681dbf3b48bff1e8d14cb6195f 100644 (file)
@@ -207,6 +207,9 @@ struct Meta {
         /* Allow isolation requests */
         bool allow_isolate;
 
         /* Allow isolation requests */
         bool allow_isolate;
 
+        /* Isolate OnFailure unit */
+        bool on_failure_isolate;
+
         /* Did the last condition check suceed? */
         bool condition_result;
 
         /* Did the last condition check suceed? */
         bool condition_result;