Configurable option for MOTD

Former-commit-id: 49a89d636ba698dbd0858d5059d3d6387c8c1fc7
This commit is contained in:
Kajaruban Surendran 2020-11-27 21:42:08 +00:00 committed by John Sully
parent 9748c7af67
commit 188e7a5693
8 changed files with 18 additions and 8 deletions

View File

@ -282,6 +282,9 @@ databases 16
# ASCII art logo in startup logs by setting the following option to yes. # ASCII art logo in startup logs by setting the following option to yes.
always-show-logo yes always-show-logo yes
# Retrieving "message of today" using CURL requests.
#enable-motd yes
################################ SNAPSHOTTING ################################ ################################ SNAPSHOTTING ################################
# #
# Save the DB on disk: # Save the DB on disk:

View File

@ -2344,6 +2344,7 @@ standardConfig configs[] = {
createBoolConfig("daemonize", NULL, IMMUTABLE_CONFIG, cserver.daemonize, 0, NULL, NULL), createBoolConfig("daemonize", NULL, IMMUTABLE_CONFIG, cserver.daemonize, 0, NULL, NULL),
createBoolConfig("lua-replicate-commands", NULL, MODIFIABLE_CONFIG, g_pserver->lua_always_replicate_commands, 1, NULL, NULL), createBoolConfig("lua-replicate-commands", NULL, MODIFIABLE_CONFIG, g_pserver->lua_always_replicate_commands, 1, NULL, NULL),
createBoolConfig("always-show-logo", NULL, IMMUTABLE_CONFIG, g_pserver->always_show_logo, 0, NULL, NULL), createBoolConfig("always-show-logo", NULL, IMMUTABLE_CONFIG, g_pserver->always_show_logo, 0, NULL, NULL),
createBoolConfig("enable-motd", NULL, IMMUTABLE_CONFIG, cserver.enable_motd, 1, NULL, NULL),
createBoolConfig("protected-mode", NULL, MODIFIABLE_CONFIG, g_pserver->protected_mode, 1, NULL, NULL), createBoolConfig("protected-mode", NULL, MODIFIABLE_CONFIG, g_pserver->protected_mode, 1, NULL, NULL),
createBoolConfig("rdbcompression", NULL, MODIFIABLE_CONFIG, g_pserver->rdb_compression, 1, NULL, NULL), createBoolConfig("rdbcompression", NULL, MODIFIABLE_CONFIG, g_pserver->rdb_compression, 1, NULL, NULL),
createBoolConfig("rdb-del-sync-files", NULL, MODIFIABLE_CONFIG, g_pserver->rdb_del_sync_files, 0, NULL, NULL), createBoolConfig("rdb-del-sync-files", NULL, MODIFIABLE_CONFIG, g_pserver->rdb_del_sync_files, 0, NULL, NULL),

View File

@ -71,12 +71,16 @@ static void setMOTDCache(const char *sz)
fclose(pf); fclose(pf);
} }
extern "C" char *fetchMOTD(int cache) extern "C" char *fetchMOTD(int cache, int enable_motd)
{ {
sds str; sds str;
CURL *curl; CURL *curl;
CURLcode res; CURLcode res;
/* Do not try the CURL if the motd is disabled*/
if (!enable_motd) {
return NULL;
}
/* First try and get the string from the cache */ /* First try and get the string from the cache */
if (cache) { if (cache) {
str = fetchMOTDFromCache(); str = fetchMOTDFromCache();
@ -124,7 +128,7 @@ extern "C" char *fetchMOTD(int cache)
#else #else
extern "C" char *fetchMOTD(int /* cache */) extern "C" char *fetchMOTD(int /* cache */, int /* enable_motd */)
{ {
return NULL; return NULL;
} }

View File

@ -6,8 +6,7 @@ extern const char *motd_cache_file;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
char *fetchMOTD(int fCache, int enable_motd);
char *fetchMOTD(int fCache);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -7113,7 +7113,8 @@ int main(int argc, char **argv) {
if (argc == 0 && !config.eval) { if (argc == 0 && !config.eval) {
/* Show the message of the day if we are interactive */ /* Show the message of the day if we are interactive */
if (config.output == OUTPUT_STANDARD && !config.disable_motd) { if (config.output == OUTPUT_STANDARD && !config.disable_motd) {
char *szMotd = fetchMOTD(1 /* cache */); /*enable_motd=1 will retrieve the message of today using CURL*/
char *szMotd = fetchMOTD(1 /* cache */, 1 /* enable_motd */);
if (szMotd != NULL) { if (szMotd != NULL) {
printf("Message of the day:\n %s\n", szMotd); printf("Message of the day:\n %s\n", szMotd);
sdsfree(szMotd); sdsfree(szMotd);

View File

@ -5136,7 +5136,7 @@ void redisAsciiArt(void) {
mode, g_pserver->port ? g_pserver->port : g_pserver->tls_port mode, g_pserver->port ? g_pserver->port : g_pserver->tls_port
); );
} else { } else {
sds motd = fetchMOTD(true); sds motd = fetchMOTD(true, cserver.enable_motd);
snprintf(buf,1024*16,ascii_logo, snprintf(buf,1024*16,ascii_logo,
KEYDB_REAL_VERSION, KEYDB_REAL_VERSION,
redisGitSHA1(), redisGitSHA1(),

View File

@ -1456,6 +1456,7 @@ struct redisServerConst {
bool fUsePro = false; bool fUsePro = false;
int thread_min_client_threshold = 50; int thread_min_client_threshold = 50;
int multimaster_no_forward; int multimaster_no_forward;
int enable_motd; /* Flag to retrieve the Message of today using CURL request*/
}; };
struct redisServer { struct redisServer {

View File

@ -67,6 +67,7 @@ start_server {tags {"introspection"}} {
io-threads-do-reads io-threads-do-reads
tcp-backlog tcp-backlog
always-show-logo always-show-logo
enable-motd
syslog-enabled syslog-enabled
cluster-enabled cluster-enabled
aclfile aclfile