Jagpal Singh Gill | 15dde86 | 2024-10-16 09:42:54 -0700 | [diff] [blame] | 1 | #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 Gill | 15dde86 | 2024-10-16 09:42:54 -0700 | [diff] [blame] | 9 | |
| 10 | PHOSPHOR_LOG2_USING; |
| 11 | |
| 12 | namespace systemd |
| 13 | { |
| 14 | |
| 15 | auto 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 Chen | 7a28d49 | 2025-06-13 21:45:14 +0800 | [diff] [blame^] | 33 | sdbusplus::message::object_path jobObjectPath = |
| 34 | co_await systemd.call<sdbusplus::message::object_path>( |
| 35 | ctx, "StartUnit", sysdUnit, "replace"); |
Jagpal Singh Gill | 15dde86 | 2024-10-16 09:42:54 -0700 | [diff] [blame] | 36 | |
| 37 | debug("Started {UNIT} with {JOBID}", "UNIT", sysdUnit, "JOBID", |
Yang Chen | 7a28d49 | 2025-06-13 21:45:14 +0800 | [diff] [blame^] | 38 | jobObjectPath.str); |
Jagpal Singh Gill | 15dde86 | 2024-10-16 09:42:54 -0700 | [diff] [blame] | 39 | } |
| 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 |