refactor FLUSH LOGS and signal handler

pull/4502/head
Miro Stauder 2 years ago
parent 3e3b6ecd1a
commit 9ac76349fe

@ -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 */

@ -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;
}

@ -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);

@ -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:

Loading…
Cancel
Save