diff --git a/src/asciilogo.h b/src/asciilogo.h index c8b18a0ac..ed849fee1 100644 --- a/src/asciilogo.h +++ b/src/asciilogo.h @@ -30,7 +30,7 @@ const char *ascii_logo = " \n" " \n" -" KeyDB %s (%s/%d) %s bit\n" +" KeyDB Pro %s (%s/%d) %s bit \n" " \n" " Running in %s mode\n" " Port: %d\n" diff --git a/src/config.cpp b/src/config.cpp index e68a385b1..d4e8ca188 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -840,6 +840,8 @@ void loadServerConfigFromString(char *config) { } else if (!strcasecmp(argv[0],"storage-provider") && argc >= 2) { if (!initializeStorageProvider(argv+1, argc-1, &err)) goto loaderr; + } else if (!strcasecmp(argv[0],"enable-pro") && argc == 2) { + cserver.license_key = zstrdup(argv[1]); } else { err = "Bad directive or wrong number of arguments"; goto loaderr; } @@ -2258,6 +2260,7 @@ int rewriteConfig(char *path) { rewriteConfigEnumOption(state,"supervised",cserver.supervised_mode,supervised_mode_enum,SUPERVISED_NONE); rewriteConfigYesNoOption(state,"active-replica",g_pserver->fActiveReplica,CONFIG_DEFAULT_ACTIVE_REPLICA); rewriteConfigStringOption(state, "version-override",KEYDB_SET_VERSION,KEYDB_REAL_VERSION); + rewriteConfigStringOption(state, "enable-pro", cserver.license_key, CONFIG_DEFAULT_LICENSE_KEY); /* Rewrite Sentinel config if in Sentinel mode. */ if (g_pserver->sentinel_mode) rewriteConfigSentinelOption(state); diff --git a/src/server.cpp b/src/server.cpp index 92a5b6f6a..3bc79918f 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1093,6 +1093,23 @@ void serverLog(int level, const char *fmt, ...) { serverLogRaw(level,msg); } +static void checkTrialTimeout() +{ + time_t curtime = time(NULL); + int64_t elapsed = (int64_t)curtime - (int64_t)cserver.stat_starttime; + int64_t remaining = (cserver.trial_timeout * 60L) - elapsed; + if (remaining <= 0) + { + serverLog(LL_WARNING, "Trial timeout exceeded. KeyDB will now exit."); + prepareForShutdown(SHUTDOWN_SAVE); + exit(0); + } + else + { + serverLog(LL_WARNING, "Trial timeout in %ld:%02ld minutes", remaining/60, remaining % 60); + } +} + /* Log a fixed message without printf-alike capabilities, in a way that is * safe to call from a signal handler. * @@ -2071,6 +2088,10 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) { migrateCloseTimedoutSockets(); } + run_with_period(15000) { + checkTrialTimeout(); + } + /* Start a scheduled BGSAVE if the corresponding flag is set. This is * useful when we are forced to postpone a BGSAVE because an AOF * rewrite is in progress. @@ -4833,6 +4854,12 @@ void redisAsciiArt(void) { ); serverLogRaw(LL_NOTICE|LL_RAW,buf); } + + if (cserver.license_key == nullptr) + { + serverLog(LL_WARNING, "!!!! KeyDB Pro is being run in trial mode !!!!"); + serverLog(LL_WARNING, "!!!! Execution will terminate in %d minutes !!!!", cserver.trial_timeout); + } zfree(buf); } diff --git a/src/server.h b/src/server.h index c3752acb2..2e58877fb 100644 --- a/src/server.h +++ b/src/server.h @@ -388,6 +388,8 @@ public: #define CONFIG_DEFAULT_ACTIVE_REPLICA 0 #define CONFIG_DEFAULT_ENABLE_MULTIMASTER 0 +#define CONFIG_DEFAULT_LICENSE_KEY "" + #define ACTIVE_EXPIRE_CYCLE_LOOKUPS_PER_LOOP 64 /* Loopkups per loop. */ #define ACTIVE_EXPIRE_CYCLE_FAST_DURATION 1000 /* Microseconds */ #define ACTIVE_EXPIRE_CYCLE_SLOW_TIME_PERC 25 /* CPU max % for keys collection */ @@ -1958,6 +1960,9 @@ struct redisServerConst { size_t system_memory_size; /* Total memory in system as reported by OS */ unsigned char uuid[UUID_BINARY_LEN]; /* This server's UUID - populated on boot */ + + sds license_key = nullptr; + int trial_timeout = 20; }; struct redisServer {