forked from oxen-io/lokinet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
system layer manager (llarp::sys::service_manager)
the win32 and sd_notify components provided a disjointed set of similar high level functionality so we consolidate these duplicate code paths into one that has the same lifecycle regardless of platform to reduce complexity of this feature. this new component is responsible for reporting state changes to the system layer and optionally propagating state change to lokinet requested by the system layer (used by windows service).
- Loading branch information
1 parent
a7f3c35
commit 4103908
Showing
13 changed files
with
400 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include <llarp/util/service_manager.hpp> | ||
|
||
#include <systemd/sd-daemon.h> | ||
#include <cassert> | ||
#include <llarp.hpp> | ||
#include <llarp/router/router.hpp> | ||
#include <llarp/util/logging.hpp> | ||
|
||
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 | ||
{ | ||
assert(m_State != st); | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.