-
Notifications
You must be signed in to change notification settings - Fork 399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
iox-#2330 add notify systemd #2334
Changes from 2 commits
fe5015f
25155df
e09617a
76dd33f
485bfa4
d72b763
07c89d9
425db5e
952e91f
7abf543
bc13c4b
4aee645
864d7b1
a5f4bb4
4b4651c
3c334a6
8173252
efe3917
4ba2e9e
03d6f0d
62ba7b0
f72cc56
92fa972
2defac8
19f09c5
ad57509
b4e3db2
8b50b7b
5abaede
1d1b73b
93a1ac9
022d7fd
5f5afa1
ef4bffd
f73c9c6
41b10a2
ee418c3
2914009
402a626
250b4e4
7d6d7e2
d84998f
7ab593c
ab28d4f
58c5feb
f4cdef7
e96b661
20793f5
ef310cb
a5f4534
c9236aa
9775883
a60d701
ddce6b5
0921e43
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
#include "iox/smart_lock.hpp" | ||
|
||
#include <cstdint> | ||
#include <systemd/sd-daemon.h> | ||
#include <thread> | ||
|
||
namespace iox | ||
|
@@ -51,6 +52,8 @@ class RouDi | |
PortManager& portManager, | ||
const config::RouDiConfig& roudiConfig) noexcept; | ||
|
||
static constexpr uint16_t SIZE_ERROR_MESSAGE = 4096; | ||
|
||
virtual ~RouDi() noexcept; | ||
|
||
/// @brief Triggers the discovery loop to run immediately instead of waiting for the next tick interval | ||
|
@@ -129,6 +132,7 @@ class RouDi | |
private: | ||
std::thread m_monitoringAndDiscoveryThread; | ||
std::thread m_handleRuntimeMessageThread; | ||
std::thread listen_thread_watchdog; // 8 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please prefix members with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @elBoberido I'm sorry for my mistake, it's been fixed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No Problem. But do not use ifdefs in the code. Please write an abstraction, similar to what we did IpcChannelType and use that abstraction. For platforms which do not support systemd, write an alternative which basically does nothing when the methods are called. Having ifdefs all over the place makes it hard to maintain and therefore we choose the other approach. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @elBoberido I'm not sure if I understood you correctly, please look at the roudi.hpp file did you talk about this? The announcement and the definition will share this is a test for now, thank you :) |
||
|
||
protected: | ||
ProcessIntrospectionType m_processIntrospection; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,6 +161,15 @@ void RouDi::shutdown() noexcept | |
// Postpone the IpcChannelThread in order to receive TERMINATION | ||
m_runHandleRuntimeMessageThread = false; | ||
|
||
/* | ||
* This is necessary to prevent the main thread from exiting before | ||
* the 'listen_thread_watchdog' has finished, hence ensuring a | ||
* proper termination of the entire application. | ||
*/ | ||
if (listen_thread_watchdog.joinable()) { | ||
listen_thread_watchdog.join(); | ||
} | ||
|
||
if (m_handleRuntimeMessageThread.joinable()) | ||
{ | ||
IOX_LOG(DEBUG, "Joining 'IPC-msg-process' thread..."); | ||
|
@@ -254,6 +263,45 @@ void RouDi::processRuntimeMessages(runtime::IpcInterfaceCreator&& roudiIpcInterf | |
IOX_LOG(INFO, "RouDi is ready for clients"); | ||
fflush(stdout); // explicitly flush 'stdout' for 'launch_testing' | ||
|
||
/* | ||
* We get information about how they are running. If as a unit, then we launch | ||
* watchdog and send a notification about the launch, otherwise we do nothing | ||
*/ | ||
const char* invocation_id = std::getenv("INVOCATION_ID"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@elBoberido fixed |
||
if (invocation_id != nullptr) | ||
{ | ||
IOX_LOG(WARN, "Run APP in unit(systemd)"); | ||
listen_thread_watchdog = std::thread([this] { | ||
if (auto wdres = sd_notify(0, "READY=1") < 0) | ||
{ | ||
std::array<char, SIZE_ERROR_MESSAGE> buf{}; | ||
strerror_r(-static_cast<int>(wdres), buf.data(), buf.size()); | ||
IOX_LOG(ERROR, "WatchDogError: " << std::string(buf.data())); | ||
return; | ||
} | ||
IOX_LOG(DEBUG, "WatchDog READY=1"); | ||
|
||
IOX_LOG(INFO, "Start watchdog"); | ||
while (m_runHandleRuntimeMessageThread.load()) | ||
{ | ||
if (auto wdres = sd_notify(0, "WATCHDOG=1") < 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@elBoberido fixed |
||
{ | ||
std::array<char, SIZE_ERROR_MESSAGE> buf{}; | ||
strerror_r(-static_cast<int>(wdres), buf.data(), buf.size()); | ||
IOX_LOG(ERROR, "WatchDogError: " << std::string(buf.data())); | ||
return; | ||
} | ||
std::this_thread::sleep_for(std::chrono::seconds(1)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be replaced with a blocking timed_wait on a semaphore or something else which can be interupted, else the test time will be massively increased. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @elBoberido I'm not very good at multithreaded programming, but in my opinion it's not a very elegant solution :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @elBoberido fixed |
||
} | ||
}); | ||
if (pthread_setname_np(listen_thread_watchdog.native_handle(), "watchdog") != 0) | ||
{ | ||
std::array<char, SIZE_ERROR_MESSAGE> buf{}; | ||
strerror_r(errno, buf.data(), buf.size()); | ||
IOX_LOG(ERROR, "Can not set name for thread watchdog: " << std::string(buf.data())); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@elBoberido fixed |
||
} | ||
|
||
while (m_runHandleRuntimeMessageThread) | ||
{ | ||
// read RouDi's IPC channel | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add this only to the iox-roudi target
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@elBoberido fixed