diff --git a/src/sentinel.c b/src/sentinel.c index 892fbc9c9..bb4cc4fa7 100644 --- a/src/sentinel.c +++ b/src/sentinel.c @@ -549,14 +549,12 @@ void initSentinel(void) { server.sentinel_config = NULL; } -/* This function gets called when the server is in Sentinel mode, started, - * loaded the configuration, and is ready for normal operations. */ -void sentinelIsRunning(void) { - int j; - +/* This function is for checking whether sentinel config file has been set, + * also checking whether we have write permissions. */ +void sentinelCheckConfigFile(void) { if (server.configfile == NULL) { serverLog(LL_WARNING, - "Sentinel started without a config file. Exiting..."); + "Sentinel needs config file on disk to save state. Exiting..."); exit(1); } else if (access(server.configfile,W_OK) == -1) { serverLog(LL_WARNING, @@ -564,6 +562,12 @@ void sentinelIsRunning(void) { server.configfile,strerror(errno)); exit(1); } +} + +/* This function gets called when the server is in Sentinel mode, started, + * loaded the configuration, and is ready for normal operations. */ +void sentinelIsRunning(void) { + int j; /* If this Sentinel has yet no ID set in the configuration file, we * pick a random one and persist the config on disk. From now on this diff --git a/src/server.c b/src/server.c index 25cb1b40a..dcaef1ebf 100644 --- a/src/server.c +++ b/src/server.c @@ -6247,7 +6247,6 @@ int main(int argc, char **argv) { server.exec_argv[1] = zstrdup(server.configfile); j = 2; // Skip this arg when parsing options } - while(j < argc) { /* Either first or last argument - Should we read config from stdin? */ if (argv[j][0] == '-' && argv[j][1] == '\0' && (j == 1 || j == argc-1)) { @@ -6270,16 +6269,11 @@ int main(int argc, char **argv) { j++; } - if (server.sentinel_mode && ! server.configfile) { - serverLog(LL_WARNING, - "Sentinel needs config file on disk to save state. Exiting..."); - exit(1); - } loadServerConfig(server.configfile, config_from_stdin, options); if (server.sentinel_mode) loadSentinelConfigFromQueue(); sdsfree(options); } - + if (server.sentinel_mode) sentinelCheckConfigFile(); server.supervised = redisIsSupervised(server.supervised_mode); int background = server.daemonize && !server.supervised; if (background) daemonize(); diff --git a/src/server.h b/src/server.h index 407072972..f32f33f0e 100644 --- a/src/server.h +++ b/src/server.h @@ -2404,6 +2404,7 @@ const char *sentinelHandleConfiguration(char **argv, int argc); void queueSentinelConfig(sds *argv, int argc, int linenum, sds line); void loadSentinelConfigFromQueue(void); void sentinelIsRunning(void); +void sentinelCheckConfigFile(void); /* redis-check-rdb & aof */ int redis_check_rdb(char *rdbfilename, FILE *fp);