Also monitor include-files for changes when --reload is set (#2759)

* fixes #675

* feat(configwatcher): method to create config monitor handler

* cleanup

Co-authored-by: patrick96 <p.ziegler96@gmail.com>
This commit is contained in:
Tuur Vanhoutte
2022-07-09 12:24:21 +02:00
committed by GitHub
parent a20f76d7e5
commit 98d584c8fe
4 changed files with 25 additions and 11 deletions

View File

@ -195,6 +195,16 @@ void controller::signal_handler(int signum) {
stop(signum == SIGUSR1);
}
void controller::create_config_watcher(const string& filename) {
auto& fs_event_handler = m_loop.handle<FSEventHandle>();
fs_event_handler.start(
filename, 0, [this](const auto& e) { confwatch_handler(e.path); },
[this, &fs_event_handler](const auto& e) {
m_log.err("libuv error while watching included file for changes: %s", uv_strerror(e.status));
fs_event_handler.close();
});
}
void controller::confwatch_handler(const char* filename) {
m_log.notice("Watched config file changed %s", filename);
stop(true);
@ -251,13 +261,11 @@ void controller::read_events(bool confwatch) {
}
if (confwatch) {
auto& fs_event_handle = m_loop.handle<FSEventHandle>();
fs_event_handle.start(
m_conf.filepath(), 0, [this](const auto& e) { confwatch_handler(e.path); },
[this, &fs_event_handle](const auto& e) {
m_log.err("libuv error while watching config file for changes: %s", uv_strerror(e.status));
fs_event_handle.close();
});
create_config_watcher(m_conf.filepath());
// also watch the include-files for changes
for (auto& module_path : m_conf.get_included_files()) {
create_config_watcher(module_path);
}
}
if (!m_snapshot_dst.empty()) {