blob: 63878a903ef21859965cea4244929035d068878e [file] [log] [blame]
Jagpal Singh Gill15dde862024-10-16 09:42:54 -07001#include "SystemdInterface.hpp"
2
3#include <phosphor-logging/lg2.hpp>
4#include <sdbusplus/async.hpp>
5#include <sdbusplus/message/native_types.hpp>
6
7#include <exception>
8#include <string>
Jagpal Singh Gill15dde862024-10-16 09:42:54 -07009
10PHOSPHOR_LOG2_USING;
11
12namespace systemd
13{
14
15auto SystemdInterface::startUnit(sdbusplus::async::context& ctx,
16 std::string sysdUnit)
17 -> sdbusplus::async::task<>
18{
19 if (sysdUnit.empty())
20 {
21 error("sysdUnit is empty");
22 co_return;
23 }
24
25 try
26 {
27 constexpr auto systemd =
28 sdbusplus::async::proxy()
29 .service("org.freedesktop.systemd1")
30 .path("/org/freedesktop/systemd1")
31 .interface("org.freedesktop.systemd1.Manager");
32
Yang Chen7a28d492025-06-13 21:45:14 +080033 sdbusplus::message::object_path jobObjectPath =
34 co_await systemd.call<sdbusplus::message::object_path>(
35 ctx, "StartUnit", sysdUnit, "replace");
Jagpal Singh Gill15dde862024-10-16 09:42:54 -070036
37 debug("Started {UNIT} with {JOBID}", "UNIT", sysdUnit, "JOBID",
Yang Chen7a28d492025-06-13 21:45:14 +080038 jobObjectPath.str);
Jagpal Singh Gill15dde862024-10-16 09:42:54 -070039 }
40 catch (const std::exception& e)
41 {
42 warning("Failed to start {UNIT}: {ERROR}", "UNIT", sysdUnit, "ERROR",
43 e);
44 co_return;
45 }
46
47 co_return;
48}
49
50} // namespace systemd