lokinet/llarp/linux/sd_service_manager.cpp
dr7ana 46ad8d4058 Clang format include sorting + CMake
- includes are now sorted in consistent, logical order; first step in an attempt to fix the tomfoolery (no relation to Tom) brought in by include-what-you-use
- shuffled around some cmake linking to simplify dependency graph
- superfluous files removed
2023-10-24 12:11:51 -07:00

61 lines
1.3 KiB
C++

#include <llarp.hpp>
#include <llarp/router/router.hpp>
#include <llarp/util/logging.hpp>
#include <llarp/util/service_manager.hpp>
#include <systemd/sd-daemon.h>
#include <cassert>
namespace llarp::sys
{
class SD_Manager : public I_SystemLayerManager
{
llarp::sys::ServiceState m_State{ServiceState::Initial};
public:
/// change our state and report it to the system layer
void
we_changed_our_state(ServiceState st) override
{
m_State = st;
report_changed_state();
}
void
report_changed_state() override
{
if (m_State == ServiceState::Running)
{
::sd_notify(0, "READY=1");
return;
}
if (m_State == ServiceState::Stopping)
{
::sd_notify(0, "STOPPING=1");
return;
}
}
void
report_periodic_stats() override
{
if (m_Context and m_Context->router and not m_disable)
{
auto status = fmt::format("WATCHDOG=1\nSTATUS={}", m_Context->router->status_line());
::sd_notify(0, status.c_str());
}
}
void
system_changed_our_state(ServiceState) override
{
// not applicable on systemd
}
};
SD_Manager _manager{};
I_SystemLayerManager* const service_manager = &_manager;
} // namespace llarp::sys