diff --git a/README.md b/README.md index cc8801ca5..479135c7a 100644 --- a/README.md +++ b/README.md @@ -168,10 +168,8 @@ option and which are reproduced below: -f, --foreground Don't fork to background -m, --port-min=INT Lowest port to use for RTP -M, --port-max=INT Highest port to use for RTP - -r, --redis=IP:PORT Connect to Redis database - -R, --redis-db=INT Which Redis DB to use - -w, --redis-write=IP:PORT Connect to Redis write database - -W, --redis-write-db=INT Which Redis write DB to use + -r, --redis=IP:PORT/INT Connect to Redis database + -w, --redis-write=IP:PORT/INT Connect to Redis write database -b, --b2b-url=STRING XMLRPC URL of B2B UA -L, --log-level=INT Mask log priorities above this level --log-facility=daemon|local0|... Syslog facility to use for logging @@ -354,10 +352,13 @@ The options are described in more detail below. Delete the call from memory after the specified delay from memory. Can be set to zero for immediate call deletion. -* -r, --redis, -R, --redis-db +* -r, --redis Connect to specified Redis database (with the given database number) and use it for persistence - storage. On startup, *rtpengine* will read the contents of this database and restore all calls + storage. The format of this option is `ADDRESS:PORT/DBNUM`, for example `127.0.0.1:6379/12` + to connect to the Redis DB number 12 running on localhost on the default Redis port. + + On startup, *rtpengine* will read the contents of this database and restore all calls stored therein. During runtime operation, *rtpengine* will continually update the database's contents to keep it current, so that in case of a service disruption, the last state can be restored upon a restart. @@ -365,7 +366,7 @@ The options are described in more detail below. When this option is given, *rtpengine* will delay startup until the Redis database adopts the master role (but see below). -* -w, --redis-write, -W, --redis-write-db +* -w, --redis-write Configures a second Redis database for write operations. If this option is given in addition to the first one, then the first database will be used for read operations (i.e. to restore calls from) while diff --git a/daemon/main.c b/daemon/main.c index 8d0e0321a..2d0206410 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -215,6 +215,30 @@ static struct intf_config *if_addr_parse(char *s) { +static int redis_ep_parse(endpoint_t *ep, int *db, char *str) { + char *sl; + long l; + + sl = strchr(str, '/'); + if (!sl) + return -1; + *sl = 0; + sl++; + if (!*sl) + return -1; + l = strtol(sl, &sl, 10); + if (*sl != 0) + return -1; + if (l < 0) + return -1; + *db = l; + if (endpoint_parse_any(ep, str)) + return -1; + return 0; +} + + + static void options(int *argc, char ***argv) { char **if_a = NULL; char **iter; @@ -252,10 +276,8 @@ static void options(int *argc, char ***argv) { { "foreground", 'f', 0, G_OPTION_ARG_NONE, &foreground, "Don't fork to background", NULL }, { "port-min", 'm', 0, G_OPTION_ARG_INT, &port_min, "Lowest port to use for RTP", "INT" }, { "port-max", 'M', 0, G_OPTION_ARG_INT, &port_max, "Highest port to use for RTP", "INT" }, - { "redis", 'r', 0, G_OPTION_ARG_STRING, &redisps, "Connect to Redis database", "IP:PORT" }, - { "redis-db", 'R', 0, G_OPTION_ARG_INT, &redis_db, "Which Redis DB to use", "INT" }, - { "redis-write",'w', 0, G_OPTION_ARG_STRING, &redisps_write, "Connect to Redis write database", "IP:PORT" }, - { "redis-write-db", 'W', 0, G_OPTION_ARG_INT, &redis_write_db,"Which Redis write DB to use", "INT" }, + { "redis", 'r', 0, G_OPTION_ARG_STRING, &redisps, "Connect to Redis database", "IP:PORT/INT" }, + { "redis-write",'w', 0, G_OPTION_ARG_STRING, &redisps_write, "Connect to Redis write database", "IP:PORT/INT" }, { "b2b-url", 'b', 0, G_OPTION_ARG_STRING, &b2b_url, "XMLRPC URL of B2B UA" , "STRING" }, { "log-level", 'L', 0, G_OPTION_ARG_INT, (void *)&log_level,"Mask log priorities above this level","INT" }, { "log-facility",0, 0, G_OPTION_ARG_STRING, &log_facility_s, "Syslog facility to use for logging", "daemon|local0|...|local7"}, @@ -326,19 +348,13 @@ static void options(int *argc, char ***argv) { if (silent_timeout <= 0) silent_timeout = 3600; - if (redisps) { - if (endpoint_parse_any(&redis_ep, redisps)) - die("Invalid IP or port (--redis)"); - if (redis_db < 0) - die("Must specify Redis DB number (--redis-db) when using Redis"); - } + if (redisps) + if (redis_ep_parse(&redis_ep, &redis_db, redisps)) + die("Invalid Redis endpoint [IP:PORT/INT] (--redis)"); - if (redisps_write) { - if (endpoint_parse_any(&redis_write_ep, redisps_write)) - die("Invalid Redis write IP or port (--redis-write)"); - if (redis_write_db < 0) - die("Must specify Redis write DB number (--redis-write-db) when using Redis"); - } + if (redisps_write) + if (redis_ep_parse(&redis_write_ep, &redis_write_db, redisps_write)) + die("Invalid Redis endpoint [IP:PORT/INT] (--redis-write)"); if (xmlrpc_fmt > 1) die("Invalid XMLRPC format"); @@ -563,19 +579,21 @@ no_kernel: daemonize(); wpidfile(); - // start redis restore timer - gettimeofday(&redis_start, NULL); + if (mc.redis) { + // start redis restore timer + gettimeofday(&redis_start, NULL); - // restore - if (redis_restore(ctx->m, mc.redis)) - die("Refusing to continue without working Redis database"); + // restore + if (redis_restore(ctx->m, mc.redis)) + die("Refusing to continue without working Redis database"); - // stop redis restore timer - gettimeofday(&redis_stop, NULL); + // stop redis restore timer + gettimeofday(&redis_stop, NULL); - // print redis restore duration - redis_diff += timeval_diff(&redis_stop, &redis_start) / 1000.0; - ilog(LOG_INFO, "Redis restore time = %.0lf ms", redis_diff); + // print redis restore duration + redis_diff += timeval_diff(&redis_stop, &redis_start) / 1000.0; + ilog(LOG_INFO, "Redis restore time = %.0lf ms", redis_diff); + } gettimeofday(&ctx->m->latest_graphite_interval_start, NULL); diff --git a/debian/ngcp-rtpengine-daemon.init b/debian/ngcp-rtpengine-daemon.init index 8d586af98..67b4347f7 100755 --- a/debian/ngcp-rtpengine-daemon.init +++ b/debian/ngcp-rtpengine-daemon.init @@ -62,10 +62,8 @@ fi [ -z "$TOS" ] || OPTIONS="$OPTIONS --tos=$TOS" [ -z "$PORT_MIN" ] || OPTIONS="$OPTIONS --port-min=$PORT_MIN" [ -z "$PORT_MAX" ] || OPTIONS="$OPTIONS --port-max=$PORT_MAX" -[ -z "$REDIS" ] || OPTIONS="$OPTIONS --redis=$REDIS" -[ -z "$REDIS_DB" ] || OPTIONS="$OPTIONS --redis-db=$REDIS_DB" -[ -z "$REDIS_WRITE" ] || OPTIONS="$OPTIONS --redis-write=$REDIS_WRITE" -[ -z "$REDIS_WRITE_DB" ] || OPTIONS="$OPTIONS --redis-write-db=$REDIS_WRITE_DB" +[ -z "$REDIS" -o -z "$REDIS_DB" ] || OPTIONS="$OPTIONS --redis=$REDIS/$REDIS_DB" +[ -z "$REDIS_WRITE" -o -z "$REDIS_WRITE_DB" ] || OPTIONS="$OPTIONS --redis-write=$REDIS_WRITE/$REDIS_WRITE_DB" [ -z "$B2B_URL" ] || OPTIONS="$OPTIONS --b2b-url=$B2B_URL" [ -z "$NO_FALLBACK" -o \( "$NO_FALLBACK" != "1" -a "$NO_FALLBACK" != "yes" \) ] || OPTIONS="$OPTIONS --no-fallback" OPTIONS="$OPTIONS --table=$TABLE" diff --git a/el/rtpengine.init b/el/rtpengine.init index 5b584eb59..9bd441446 100644 --- a/el/rtpengine.init +++ b/el/rtpengine.init @@ -108,14 +108,9 @@ build_opts() { OPTS+=" --port-max=$PORT_MAX" fi - if [[ -n "$REDIS" ]] + if [[ -n "$REDIS" -a -n "$REDIS_DB" ]] then - OPTS+=" --redis=$REDIS" - fi - - if [[ -n "$REDIS_DB" ]] - then - OPTS+=" --redis-db=$REDIS_DB" + OPTS+=" --redis=$REDIS/$REDIS_DB" fi if [[ -n "$B2B_URL" ]]