util::dbus: Make common the transition host support
Move transition host support from attention handler specific code to
common util code.
Signed-off-by: Ben Tyner <ben.tyner@ibm.com>
Change-Id: I7fb4970354aaeca65fcc074107f99262e504ac34
diff --git a/util/dbus.cpp b/util/dbus.cpp
index 7e8a234..968a44f 100644
--- a/util/dbus.cpp
+++ b/util/dbus.cpp
@@ -165,6 +165,38 @@
return names;
}
+/** @brief Transition the host state */
+void transitionHost(const HostState i_hostState)
+{
+ try
+ {
+ // We will be transitioning host by starting appropriate dbus target
+ std::string target = "obmc-host-quiesce@0.target"; // quiesce is default
+
+ // crash (mpipl) mode state requested
+ if (HostState::Crash == i_hostState)
+ {
+ target = "obmc-host-crash@0.target";
+ }
+
+ auto bus = sdbusplus::bus::new_system();
+ auto method = bus.new_method_call(
+ "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
+ "org.freedesktop.systemd1.Manager", "StartUnit");
+
+ method.append(target); // target unit to start
+ method.append("replace"); // mode = replace conflicting queued jobs
+
+ bus.call_noreply(method); // start the service
+ }
+ catch (const sdbusplus::exception::SdBusError& e)
+ {
+ trace::err("util::dbus::transitionHost exception");
+ std::string traceMsg = std::string(e.what());
+ trace::err(traceMsg.c_str());
+ }
+}
+
} // namespace dbus
} // namespace util