From 8bc30256b7f1735fc368a2a0a88d4279aaab5648 Mon Sep 17 00:00:00 2001 From: Michiel De Mey Date: Fri, 13 May 2016 11:47:55 +0200 Subject: [PATCH 1/4] Allow non-interactive execution of install_server This PR adds the ability to execute the installation script non-interactively, useful for automated provisioning scripts such as Chef, Puppet, Ansible, Salt, etc. Simply feed the environment variables into the install script to skip the prompts. For debug and verification purposes, the script will still output the selected config variables. The plus side is that the environment variables also support command substitution (see REDIS_EXECUTABLE). ``` sudo REDIS_PORT=1234 REDIS_CONFIG_FILE=/etc/redis/1234.conf REDIS_LOG_FILE=/var/log/redis_1234.log REDIS_DATA_DIR=/var/lib/redis/1234 REDIS_EXECUTABLE=`command -v redis-server` ./utils/install_server.sh Welcome to the redis service installer This script will help you easily set up a running redis server Selected config: Port : 1234 Config file : /etc/redis/1234.conf Log file : /var/log/redis_1234.log Data dir : /var/lib/redis/1234 Executable : /usr/local/bin/redis-server Cli Executable : /usr/local/bin/redis-cli Copied /tmp/1234.conf => /etc/init.d/redis_1234 Installing service... Successfully added to chkconfig! Successfully added to runlevels 345! Starting Redis server... Installation successful! ``` --- utils/install_server.sh | 73 +++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 28 deletions(-) diff --git a/utils/install_server.sh b/utils/install_server.sh index 98e047e3d..34c238197 100755 --- a/utils/install_server.sh +++ b/utils/install_server.sh @@ -42,6 +42,7 @@ SCRIPTPATH=$(dirname $SCRIPT) #Initial defaults _REDIS_PORT=6379 +_MANUAL_EXECUTION=false echo "Welcome to the redis service installer" echo "This script will help you easily set up a running redis server" @@ -53,47 +54,61 @@ if [ "$(id -u)" -ne 0 ] ; then exit 1 fi -#Read the redis port -read -p "Please select the redis port for this instance: [$_REDIS_PORT] " REDIS_PORT if ! echo $REDIS_PORT | egrep -q '^[0-9]+$' ; then - echo "Selecting default: $_REDIS_PORT" - REDIS_PORT=$_REDIS_PORT + _MANUAL_EXECUTION=true + #Read the redis port + read -p "Please select the redis port for this instance: [$_REDIS_PORT] " REDIS_PORT + if ! echo $REDIS_PORT | egrep -q '^[0-9]+$' ; then + echo "Selecting default: $_REDIS_PORT" + REDIS_PORT=$_REDIS_PORT + fi fi -#read the redis config file -_REDIS_CONFIG_FILE="/etc/redis/$REDIS_PORT.conf" -read -p "Please select the redis config file name [$_REDIS_CONFIG_FILE] " REDIS_CONFIG_FILE if [ -z "$REDIS_CONFIG_FILE" ] ; then - REDIS_CONFIG_FILE=$_REDIS_CONFIG_FILE - echo "Selected default - $REDIS_CONFIG_FILE" + _MANUAL_EXECUTION=true + #read the redis config file + _REDIS_CONFIG_FILE="/etc/redis/$REDIS_PORT.conf" + read -p "Please select the redis config file name [$_REDIS_CONFIG_FILE] " REDIS_CONFIG_FILE + if [ -z "$REDIS_CONFIG_FILE" ] ; then + REDIS_CONFIG_FILE=$_REDIS_CONFIG_FILE + echo "Selected default - $REDIS_CONFIG_FILE" + fi fi -#read the redis log file path -_REDIS_LOG_FILE="/var/log/redis_$REDIS_PORT.log" -read -p "Please select the redis log file name [$_REDIS_LOG_FILE] " REDIS_LOG_FILE if [ -z "$REDIS_LOG_FILE" ] ; then - REDIS_LOG_FILE=$_REDIS_LOG_FILE - echo "Selected default - $REDIS_LOG_FILE" + _MANUAL_EXECUTION=true + #read the redis log file path + _REDIS_LOG_FILE="/var/log/redis_$REDIS_PORT.log" + read -p "Please select the redis log file name [$_REDIS_LOG_FILE] " REDIS_LOG_FILE + if [ -z "$REDIS_LOG_FILE" ] ; then + REDIS_LOG_FILE=$_REDIS_LOG_FILE + echo "Selected default - $REDIS_LOG_FILE" + fi fi - -#get the redis data directory -_REDIS_DATA_DIR="/var/lib/redis/$REDIS_PORT" -read -p "Please select the data directory for this instance [$_REDIS_DATA_DIR] " REDIS_DATA_DIR if [ -z "$REDIS_DATA_DIR" ] ; then - REDIS_DATA_DIR=$_REDIS_DATA_DIR - echo "Selected default - $REDIS_DATA_DIR" + _MANUAL_EXECUTION=true + #get the redis data directory + _REDIS_DATA_DIR="/var/lib/redis/$REDIS_PORT" + read -p "Please select the data directory for this instance [$_REDIS_DATA_DIR] " REDIS_DATA_DIR + if [ -z "$REDIS_DATA_DIR" ] ; then + REDIS_DATA_DIR=$_REDIS_DATA_DIR + echo "Selected default - $REDIS_DATA_DIR" + fi fi -#get the redis executable path -_REDIS_EXECUTABLE=`command -v redis-server` -read -p "Please select the redis executable path [$_REDIS_EXECUTABLE] " REDIS_EXECUTABLE if [ ! -x "$REDIS_EXECUTABLE" ] ; then - REDIS_EXECUTABLE=$_REDIS_EXECUTABLE - + _MANUAL_EXECUTION=true + #get the redis executable path + _REDIS_EXECUTABLE=`command -v redis-server` + read -p "Please select the redis executable path [$_REDIS_EXECUTABLE] " REDIS_EXECUTABLE if [ ! -x "$REDIS_EXECUTABLE" ] ; then - echo "Mmmmm... it seems like you don't have a redis executable. Did you run make install yet?" - exit 1 + REDIS_EXECUTABLE=$_REDIS_EXECUTABLE + + if [ ! -x "$REDIS_EXECUTABLE" ] ; then + echo "Mmmmm... it seems like you don't have a redis executable. Did you run make install yet?" + exit 1 + fi fi fi @@ -112,7 +127,9 @@ echo "Data dir : $REDIS_DATA_DIR" echo "Executable : $REDIS_EXECUTABLE" echo "Cli Executable : $CLI_EXEC" -read -p "Is this ok? Then press ENTER to go on or Ctrl-C to abort." _UNUSED_ +if $_MANUAL_EXECUTION == true ; then + read -p "Is this ok? Then press ENTER to go on or Ctrl-C to abort." _UNUSED_ +fi mkdir -p `dirname "$REDIS_CONFIG_FILE"` || die "Could not create redis config directory" mkdir -p `dirname "$REDIS_LOG_FILE"` || die "Could not create redis log dir" From 386f7f5ae0f155caeb1215cb07080f5b54b37751 Mon Sep 17 00:00:00 2001 From: wenduo Date: Mon, 30 May 2016 16:21:08 +0800 Subject: [PATCH 2/4] bitcount bug:return non-zero value when start > end (both negative) --- src/bitops.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/bitops.c b/src/bitops.c index a7fad899f..f3a7747b4 100644 --- a/src/bitops.c +++ b/src/bitops.c @@ -768,6 +768,10 @@ void bitcountCommand(client *c) { /* Convert negative indexes */ if (start < 0) start = strlen+start; if (end < 0) end = strlen+end; + if ((start < 0) && (end < 0) && (start > end)) { + addReply(c,shared.czero); + return; + } if (start < 0) start = 0; if (end < 0) end = 0; if (end >= strlen) end = strlen-1; From 80ce0f7c13a88034999a3fac0273e43cdea6f7de Mon Sep 17 00:00:00 2001 From: Michiel De Mey Date: Fri, 10 Jun 2016 10:11:46 +0200 Subject: [PATCH 3/4] Added documentation for non-interactive install procedure --- utils/install_server.sh | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/utils/install_server.sh b/utils/install_server.sh index 34c238197..3d920a125 100755 --- a/utils/install_server.sh +++ b/utils/install_server.sh @@ -25,9 +25,25 @@ # ################################################################################ # -# Interactive service installer for redis server -# this generates a redis config file and an /etc/init.d script, and installs them -# this scripts should be run as root +# Service installer for redis server, runs interactively by default. +# +# To run this script non-interactively (for automation/provisioning purposes), +# feed the variables into the script. Any missing variables will be prompted! +# Tip: Environment variables also support command substitution (see REDIS_EXECUTABLE) +# +# Example: +# +# sudo REDIS_PORT=1234 \ +# REDIS_CONFIG_FILE=/etc/redis/1234.conf \ +# REDIS_LOG_FILE=/var/log/redis_1234.log \ +# REDIS_DATA_DIR=/var/lib/redis/1234 \ +# REDIS_EXECUTABLE=`command -v redis-server` ./utils/install_server.sh +# +# This generates a redis config file and an /etc/init.d script, and installs them. +# +# /!\ This script should be run as root +# +################################################################################ die () { echo "ERROR: $1. Aborting!" From ad5cf5e25a401351016bceec7228f22248a946b6 Mon Sep 17 00:00:00 2001 From: zach shipko Date: Tue, 14 Jun 2016 13:46:42 +0000 Subject: [PATCH 4/4] BSDs don't have -ldl --- src/Makefile | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Makefile b/src/Makefile index d73f381bf..89355984c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -55,7 +55,7 @@ endif FINAL_CFLAGS=$(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) $(REDIS_CFLAGS) -I../deps/geohash-int FINAL_LDFLAGS=$(LDFLAGS) $(REDIS_LDFLAGS) $(DEBUG) -FINAL_LIBS=-lm -ldl +FINAL_LIBS=-lm DEBUG=-g -ggdb ifeq ($(uname_S),SunOS) @@ -65,17 +65,27 @@ ifeq ($(uname_S),SunOS) FINAL_LIBS+= -ldl -lnsl -lsocket -lresolv -lpthread -lrt else ifeq ($(uname_S),Darwin) - # Darwin (nothing to do) + # Darwin + FINAL_LIBS+= -ldl else ifeq ($(uname_S),AIX) # AIX FINAL_LDFLAGS+= -Wl,-bexpall - FINAL_LIBS+= -pthread -lcrypt -lbsd - + FINAL_LIBS+=-ldl -pthread -lcrypt -lbsd +else +ifeq ($(uname_S),OpenBSD) + # OpenBSD + FINAL_LIBS+= -lpthread +else +ifeq ($(uname_S),FreeBSD) + # FreeBSD + FINAL_LIBS+= -lpthread else # All the other OSes (notably Linux) FINAL_LDFLAGS+= -rdynamic - FINAL_LIBS+= -pthread + FINAL_LIBS+=-ldl -pthread +endif +endif endif endif endif