115dde864SJagpal Singh Gill #include "SystemdInterface.hpp"
215dde864SJagpal Singh Gill
315dde864SJagpal Singh Gill #include <phosphor-logging/lg2.hpp>
415dde864SJagpal Singh Gill #include <sdbusplus/async.hpp>
515dde864SJagpal Singh Gill #include <sdbusplus/message/native_types.hpp>
615dde864SJagpal Singh Gill
715dde864SJagpal Singh Gill #include <exception>
815dde864SJagpal Singh Gill #include <string>
915dde864SJagpal Singh Gill
1015dde864SJagpal Singh Gill PHOSPHOR_LOG2_USING;
1115dde864SJagpal Singh Gill
1215dde864SJagpal Singh Gill namespace systemd
1315dde864SJagpal Singh Gill {
1415dde864SJagpal Singh Gill
startUnit(sdbusplus::async::context & ctx,std::string sysdUnit)1515dde864SJagpal Singh Gill auto SystemdInterface::startUnit(sdbusplus::async::context& ctx,
1615dde864SJagpal Singh Gill std::string sysdUnit)
1715dde864SJagpal Singh Gill -> sdbusplus::async::task<>
1815dde864SJagpal Singh Gill {
1915dde864SJagpal Singh Gill if (sysdUnit.empty())
2015dde864SJagpal Singh Gill {
2115dde864SJagpal Singh Gill error("sysdUnit is empty");
2215dde864SJagpal Singh Gill co_return;
2315dde864SJagpal Singh Gill }
2415dde864SJagpal Singh Gill
2515dde864SJagpal Singh Gill try
2615dde864SJagpal Singh Gill {
2715dde864SJagpal Singh Gill constexpr auto systemd =
2815dde864SJagpal Singh Gill sdbusplus::async::proxy()
2915dde864SJagpal Singh Gill .service("org.freedesktop.systemd1")
3015dde864SJagpal Singh Gill .path("/org/freedesktop/systemd1")
3115dde864SJagpal Singh Gill .interface("org.freedesktop.systemd1.Manager");
3215dde864SJagpal Singh Gill
33*7a28d492SYang Chen sdbusplus::message::object_path jobObjectPath =
34*7a28d492SYang Chen co_await systemd.call<sdbusplus::message::object_path>(
3515dde864SJagpal Singh Gill ctx, "StartUnit", sysdUnit, "replace");
3615dde864SJagpal Singh Gill
3715dde864SJagpal Singh Gill debug("Started {UNIT} with {JOBID}", "UNIT", sysdUnit, "JOBID",
38*7a28d492SYang Chen jobObjectPath.str);
3915dde864SJagpal Singh Gill }
4015dde864SJagpal Singh Gill catch (const std::exception& e)
4115dde864SJagpal Singh Gill {
4215dde864SJagpal Singh Gill warning("Failed to start {UNIT}: {ERROR}", "UNIT", sysdUnit, "ERROR",
4315dde864SJagpal Singh Gill e);
4415dde864SJagpal Singh Gill co_return;
4515dde864SJagpal Singh Gill }
4615dde864SJagpal Singh Gill
4715dde864SJagpal Singh Gill co_return;
4815dde864SJagpal Singh Gill }
4915dde864SJagpal Singh Gill
5015dde864SJagpal Singh Gill } // namespace systemd
51