diff options
author | Lennart Poettering <lennart@poettering.net> | 2017-11-16 15:18:01 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2017-11-20 16:37:22 +0100 |
commit | e7dfbb4e7414fdea57fd0ff7ad20585295b6e1b0 (patch) | |
tree | 6e79ed4ee53860fd317a30f862867f5cd67a1e6c /src/core/dbus-unit.c | |
parent | core: generalize FailureAction= move it from service to unit (diff) | |
download | systemd-e7dfbb4e7414fdea57fd0ff7ad20585295b6e1b0.tar.xz systemd-e7dfbb4e7414fdea57fd0ff7ad20585295b6e1b0.zip |
core: introduce SuccessAction= as unit file property
SuccessAction= is similar to FailureAction= but declares what to do on
success of a unit, rather than on failure. This is useful for running
commands in qemu/nspawn images, that shall power down on completion. We
frequently see "ExecStopPost=/usr/bin/systemctl poweroff" or so in unit
files like this. Offer a simple, more declarative alternative for this.
While we are at it, hook up failure action with unit_dump() and
transient units too.
Diffstat (limited to 'src/core/dbus-unit.c')
-rw-r--r-- | src/core/dbus-unit.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c index 5344183508..d4bdf1760a 100644 --- a/src/core/dbus-unit.c +++ b/src/core/dbus-unit.c @@ -799,6 +799,7 @@ const sd_bus_vtable bus_unit_vtable[] = { SD_BUS_PROPERTY("StartLimitBurst", "u", bus_property_get_unsigned, offsetof(Unit, start_limit.burst), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("StartLimitAction", "s", property_get_emergency_action, offsetof(Unit, start_limit_action), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("FailureAction", "s", property_get_emergency_action, offsetof(Unit, failure_action), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("SuccessAction", "s", property_get_emergency_action, offsetof(Unit, success_action), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("RebootArgument", "s", NULL, offsetof(Unit, reboot_arg), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("InvocationID", "ay", bus_property_get_id128, offsetof(Unit, invocation_id), 0), SD_BUS_PROPERTY("CollectMode", "s", property_get_collect_mode, offsetof(Unit, collect_mode), 0), @@ -1471,6 +1472,30 @@ static int bus_unit_set_transient_property( return 1; + } else if (STR_IN_SET(name, "FailureAction", "SuccessAction")) { + EmergencyAction action; + const char *s; + + r = sd_bus_message_read(message, "s", &s); + if (r < 0) + return r; + + action = emergency_action_from_string(s); + if (action < 0) + return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid emergency action: %s", s); + + if (mode != UNIT_CHECK) { + + if (streq(name, "FailureAction")) + u->failure_action = action; + else + u->success_action = action; + + unit_write_drop_in_format(u, mode, name, "%s=%s", name, emergency_action_to_string(action)); + } + + return 1; + } else if (streq(name, "AddRef")) { int b; |