Add support for sending the SIGRTMIN signal to trigger log rotation.

Closes #2337. Thanks to Evgeny S.
pull/2346/head
Roger Light 4 years ago committed by Roger A. Light
parent 7857e5cedb
commit 1cc8ebb782

@ -80,6 +80,8 @@ Broker:
- Add more efficient keepalive check. - Add more efficient keepalive check.
- Send DISCONNECT With session-takeover return code to MQTT v5 clients when a - Send DISCONNECT With session-takeover return code to MQTT v5 clients when a
client connects with the same client id. Closes #2340. client connects with the same client id. Closes #2340.
- Add support for sending the SIGRTMIN signal to trigger log rotation.
Closes #2337.
Client library: Client library:
- Add MOSQ_OPT_DISABLE_SOCKETPAIR to allow the disabling of the socketpair - Add MOSQ_OPT_DISABLE_SOCKETPAIR to allow the disabling of the socketpair

@ -693,6 +693,18 @@
for details.</para> for details.</para>
<para>If TLS certificates are in use, then mosquitto will <para>If TLS certificates are in use, then mosquitto will
also reload certificate on receiving a SIGHUP.</para> also reload certificate on receiving a SIGHUP.</para>
<para>
The logs will also be closed and reopened.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>SIGRTMIN</term>
<listitem>
<para>
Upon receiving the SIGRTMIN signal, mosquitto will
close and reopen the logs to support log rotation.
</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>

@ -55,11 +55,6 @@ Contributors:
#include "time_mosq.h" #include "time_mosq.h"
#include "util_mosq.h" #include "util_mosq.h"
extern bool flag_reload;
#ifdef WITH_PERSISTENCE
extern bool flag_db_backup;
#endif
extern bool flag_tree_print;
extern int g_run; extern int g_run;
#if defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == WS_IS_WEBSOCKETS && LWS_LIBRARY_VERSION_NUMBER == 3002000 #if defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == WS_IS_WEBSOCKETS && LWS_LIBRARY_VERSION_NUMBER == 3002000
@ -231,38 +226,7 @@ int mosquitto_main_loop(struct mosquitto__listener_sock *listensock, int listens
} }
#endif #endif
#ifdef WITH_PERSISTENCE signal__flag_check();
if(flag_db_backup){
persist__backup(false);
flag_db_backup = false;
}
#endif
if(flag_reload){
log__printf(NULL, MOSQ_LOG_INFO, "Reloading config.");
config__read(db.config, true);
listeners__reload_all_certificates();
mosquitto_security_cleanup(true);
mosquitto_security_init(true);
mosquitto_security_apply();
log__close(db.config);
log__init(db.config);
keepalive__cleanup();
keepalive__init();
#ifdef WITH_CJSON
broker_control__reload();
#endif
#ifdef WITH_BRIDGE
bridge__reload();
#endif
flag_reload = false;
}
if(flag_tree_print){
sub__tree_print(db.subs, 0);
flag_tree_print = false;
#ifdef WITH_XTREPORT
xtreport();
#endif
}
#if defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == WS_IS_LWS #if defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == WS_IS_LWS
for(i=0; i<db.config->listener_count; i++){ for(i=0; i<db.config->listener_count; i++){
/* Extremely hacky, should be using the lws provided external poll /* Extremely hacky, should be using the lws provided external poll

@ -896,6 +896,7 @@ void session_expiry__send_all(void);
* Signals * Signals
* ============================================================ */ * ============================================================ */
void signal__setup(void); void signal__setup(void);
void signal__flag_check(void);
/* ============================================================ /* ============================================================
* Window service and signal related functions * Window service and signal related functions

@ -33,11 +33,12 @@ Contributors:
extern int g_run; extern int g_run;
bool flag_reload = false; static bool flag_reload = false;
static bool flag_log_rotate = false;
#ifdef WITH_PERSISTENCE #ifdef WITH_PERSISTENCE
bool flag_db_backup = false; static bool flag_db_backup = false;
#endif #endif
bool flag_tree_print = false; static bool flag_tree_print = false;
static void handle_signal(int signal) static void handle_signal(int signal)
{ {
@ -55,6 +56,10 @@ static void handle_signal(int signal)
#endif #endif
}else if(signal == SIGUSR2){ }else if(signal == SIGUSR2){
flag_tree_print = true; flag_tree_print = true;
#ifdef SIGRTMIN
}else if(signal == SIGRTMIN){
flag_log_rotate = true;
#endif
} }
} }
@ -71,11 +76,55 @@ void signal__setup(void)
signal(SIGUSR2, handle_signal); signal(SIGUSR2, handle_signal);
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
#endif #endif
#ifdef SIGRTMIN
signal(SIGRTMIN, handle_signal);
#endif
#ifdef WIN32 #ifdef WIN32
CreateThread(NULL, 0, SigThreadProc, NULL, 0, NULL); CreateThread(NULL, 0, SigThreadProc, NULL, 0, NULL);
#endif #endif
} }
void signal__flag_check(void)
{
#ifdef WITH_PERSISTENCE
if(flag_db_backup){
persist__backup(false);
flag_db_backup = false;
}
#endif
if(flag_log_rotate){
log__close(db.config);
log__init(db.config);
flag_log_rotate = false;
}
if(flag_reload){
log__printf(NULL, MOSQ_LOG_INFO, "Reloading config.");
config__read(db.config, true);
listeners__reload_all_certificates();
mosquitto_security_cleanup(true);
mosquitto_security_init(true);
mosquitto_security_apply();
log__close(db.config);
log__init(db.config);
keepalive__cleanup();
keepalive__init();
#ifdef WITH_CJSON
broker_control__reload();
#endif
#ifdef WITH_BRIDGE
bridge__reload();
#endif
flag_reload = false;
}
if(flag_tree_print){
sub__tree_print(db.subs, 0);
flag_tree_print = false;
#ifdef WITH_XTREPORT
xtreport();
#endif
}
}
/* /*
* *
* Signalling mosquitto process on Win32. * Signalling mosquitto process on Win32.

Loading…
Cancel
Save