summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2011-04-07 04:11:31 +0200
committerLennart Poettering <lennart@poettering.net>2011-04-07 04:11:31 +0200
commit222ae6a8d7e27dd36552cb9574e63cbdfdf2d264 (patch)
tree0199f004eec3c6f6e968eee43b4e71aececad430 /src
parent51b4af2c2833691976844a13464c1301643043d3 (diff)
unit: introduce OnFailureIsolate=
Diffstat (limited to 'src')
-rw-r--r--src/dbus-unit.h1
-rw-r--r--src/job.c8
-rw-r--r--src/load-fragment.c1
-rw-r--r--src/unit.c19
-rw-r--r--src/unit.h3
5 files changed, 27 insertions, 5 deletions
diff --git a/src/dbus-unit.h b/src/dbus-unit.h
index efb61797f4..dfbc82c0c5 100644
--- a/src/dbus-unit.h
+++ b/src/dbus-unit.h
@@ -148,6 +148,7 @@
{ "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 }, \
diff --git a/src/job.c b/src/job.c
index a3be7becaf..dcfa323b0e 100644
--- 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. */
- 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);
+ }
/* Try to start the next jobs that can be started */
SET_FOREACH(other, u->meta.dependencies[UNIT_AFTER], i)
diff --git a/src/load-fragment.c b/src/load-fragment.c
index 8635bdb226..c27c9d8477 100644
--- a/src/load-fragment.c
+++ b/src/load-fragment.c
@@ -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" },
+ { "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" },
diff --git a/src/unit.c b/src/unit.c
index e4345aeffe..90773e894f 100644
--- a/src/unit.c
+++ b/src/unit.c
@@ -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\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.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",
@@ -1096,8 +1098,17 @@ void unit_trigger_on_failure(Unit *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) {
diff --git a/src/unit.h b/src/unit.h
index 4245f3cf1c..2c5cacd9e3 100644
--- a/src/unit.h
+++ b/src/unit.h
@@ -207,6 +207,9 @@ struct Meta {
/* Allow isolation requests */
bool allow_isolate;
+ /* Isolate OnFailure unit */
+ bool on_failure_isolate;
+
/* Did the last condition check suceed? */
bool condition_result;