unit: introduce OnFailureIsolate=
This commit is contained in:
@@ -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 }, \
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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" },
|
||||
|
||||
+15
-4
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user