From: 胡玮文 Date: Tue, 3 May 2022 09:35:48 +0000 (+0800) Subject: mon/LogMonitor: reopen log files on SIGHUP X-Git-Tag: v18.0.0~832^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ee80f9fe766fe765d79051ff59a1bcc94fc1f9e7;p=ceph.git mon/LogMonitor: reopen log files on SIGHUP Fixes: https://tracker.ceph.com/issues/55383 Signed-off-by: 胡玮文 --- diff --git a/src/mon/LogMonitor.cc b/src/mon/LogMonitor.cc index c196e8429fbe..80e069d593af 100644 --- a/src/mon/LogMonitor.cc +++ b/src/mon/LogMonitor.cc @@ -387,6 +387,10 @@ void LogMonitor::log_external(const LogEntry& le) } if (g_conf()->mon_cluster_log_to_file) { + if (this->log_rotated.exchange(false)) { + this->log_external_close_fds(); + } + auto p = channel_fds.find(channel); int fd; if (p == channel_fds.end()) { diff --git a/src/mon/LogMonitor.h b/src/mon/LogMonitor.h index 715f380af6a4..01909264ae3b 100644 --- a/src/mon/LogMonitor.h +++ b/src/mon/LogMonitor.h @@ -15,6 +15,7 @@ #ifndef CEPH_LOGMONITOR_H #define CEPH_LOGMONITOR_H +#include #include #include @@ -51,6 +52,7 @@ private: std::map channel_fds; fmt::memory_buffer file_log_buffer; + std::atomic log_rotated = false; struct log_channel_info { @@ -167,6 +169,9 @@ private: void check_subs(); void check_sub(Subscription *s); + void reopen_logs() { + this->log_rotated.store(true); + } void log_external_close_fds(); void log_external(const LogEntry& le); void log_external_backlog(); diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index ef7a7008129c..1cc8da3d6614 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -501,6 +501,7 @@ void Monitor::handle_signal(int signum) derr << "*** Got Signal " << sig_str(signum) << " ***" << dendl; if (signum == SIGHUP) { sighup_handler(signum); + logmon()->reopen_logs(); } else { ceph_assert(signum == SIGINT || signum == SIGTERM); shutdown();