diff --git a/include/proxysql_admin.h b/include/proxysql_admin.h index 6906091cc..ac7ff1765 100644 --- a/include/proxysql_admin.h +++ b/include/proxysql_admin.h @@ -638,5 +638,9 @@ class ProxySQL_Admin { bool ProxySQL_Test___CA_Certificate_Load_And_Verify(uint64_t* duration, int cnt, const char* cacert, const char* capath); #endif friend void admin_session_handler(MySQL_Session *sess, void *_pa, PtrSize_t *pkt); + + // FLUSH LOGS + void install_signal_handler(); + bool flush_logs(); }; #endif /* __CLASS_PROXYSQL_ADMIN_H */ diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index 2808beb82..8c190181e 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -1552,6 +1552,38 @@ bool admin_handler_command_kill_connection(char *query_no_space, unsigned int qu return false; } +static void flush_logs_handler(int sig) { + proxy_info("Received SIGUSR1 signal: flushing logs...\n"); +/* +Support system logging facilities sending SIGUSR1 to do log rotation +*/ + GloAdmin->flush_logs(); +} + +void ProxySQL_Admin::install_signal_handler() { + signal(SIGUSR1, flush_logs_handler); +} + +bool ProxySQL_Admin::flush_logs() { + if (GloMyLogger) { + GloMyLogger->flush_log(); + } + this->flush_error_log(); + proxysql_keylog_close(); + char* ssl_keylog_file = this->get_variable((char*)"ssl_keylog_file"); + if (ssl_keylog_file != NULL) { + if (strlen(ssl_keylog_file) > 0) { + if (proxysql_keylog_open(ssl_keylog_file) == false) { + // re-opening file failed, setting ssl_keylog_enabled to false + GloVars.global.ssl_keylog_enabled = false; + proxy_warning("Cannot open SSLKEYLOGFILE '%s' for writing.\n", ssl_keylog_file); + } + } + free(ssl_keylog_file); + } + return false; +} + /* * returns false if the command is a valid one and is processed * return true if the command is not a valid one and needs to be executed by SQLite (that will return an error) @@ -1821,25 +1853,8 @@ bool admin_handler_command_proxysql(char *query_no_space, unsigned int query_no_ if (query_no_space_length==strlen("PROXYSQL FLUSH LOGS") && !strncasecmp("PROXYSQL FLUSH LOGS",query_no_space, query_no_space_length)) { proxy_info("Received PROXYSQL FLUSH LOGS command\n"); ProxySQL_Admin *SPA=(ProxySQL_Admin *)pa; - if (GloMyLogger) { - GloMyLogger->flush_log(); - } - SPA->flush_error_log(); - proxysql_keylog_close(); - char* ssl_keylog_file = SPA->get_variable((char*)"ssl_keylog_file"); - if (ssl_keylog_file != NULL) { - if (strlen(ssl_keylog_file) > 0) { - if (proxysql_keylog_open(ssl_keylog_file) == false) { - // re-opening file failed, setting ssl_keylog_enabled to false - GloVars.global.ssl_keylog_enabled = false; - proxy_warning("Cannot open SSLKEYLOGFILE '%s' for writing.\n", ssl_keylog_file); - } - } - free(ssl_keylog_file); - } - if (sess != NULL) { - SPA->send_MySQL_OK(&sess->client_myds->myprot, NULL); - } + SPA->flush_logs(); + SPA->send_MySQL_OK(&sess->client_myds->myprot, NULL); return false; } diff --git a/lib/ProxySQL_GloVars.cpp b/lib/ProxySQL_GloVars.cpp index 43e751386..b01c62f89 100644 --- a/lib/ProxySQL_GloVars.cpp +++ b/lib/ProxySQL_GloVars.cpp @@ -15,16 +15,6 @@ #include "MySQL_LDAP_Authentication.hpp" extern MySQL_LDAP_Authentication* GloMyLdapAuth; -extern bool admin_handler_command_proxysql(char* query_no_space, unsigned int query_no_spcae_lenght, MySQL_Session *sess, ProxySQL_Admin *pa); -extern ProxySQL_Admin *GloAdmin; - -static void log_handler(int sig) { - proxy_warning("Received SIGUSR1 signal: PROXYSQL FLUSH LOGS; in progress...\n"); -/* -Support system logging facilities sending SIGUSR1 to do log rotation -*/ - admin_handler_command_proxysql("PROXYSQL FLUSH LOGS", 19, NULL, GloAdmin); -} static void term_handler(int sig) { proxy_warning("Received TERM signal: shutdown in progress...\n"); @@ -309,7 +299,6 @@ ProxySQL_GlobalVariables::ProxySQL_GlobalVariables() : }; void ProxySQL_GlobalVariables::install_signal_handler() { - signal(SIGUSR1, log_handler); signal(SIGTERM, term_handler); signal(SIGSEGV, crash_handler); signal(SIGABRT, crash_handler); diff --git a/src/main.cpp b/src/main.cpp index aaac09822..04cb4958f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1898,6 +1898,7 @@ void handleProcessRestart() { parent_open_error_log(); GloVars.global.start_time=monotonic_time(); GloVars.install_signal_handler(); + GloAdmin->install_signal_handler(); } } while (pid > 0); } @@ -2305,6 +2306,7 @@ int main(int argc, const char * argv[]) { cpu_timer t; GloVars.global.start_time=monotonic_time(); GloVars.install_signal_handler(); + GloAdmin->install_signal_handler(); if (ProxySQL_daemonize_phase2()==false) { goto finish; } @@ -2321,6 +2323,7 @@ int main(int argc, const char * argv[]) { } else { GloAdmin->flush_error_log(); GloVars.install_signal_handler(); + GloAdmin->install_signal_handler(); } __start_label: