]>
git.saurik.com Git - redis.git/blob - utils/install_server.sh
0ac98a79ae092668bbe2d1debc726e32d689918c
   2 # Interactive service installer for redis server 
   3 # this generates a redis config file and an /etc/init.d script, and installs them 
   4 # this scripts should be run as root 
   6 # Contributed by Dvir Volk dvirsky at gmail dot com 2011 
   7 # This code is contributed to public domain 
  11         echo "ERROR: $1. Aborting!"  
  19 echo "Welcome to the redis service installer" 
  20 echo "This script will help you easily set up a running redis server 
  24 #check for root user TODO: replace this with a call to "id" 
  25 if [ `whoami` != "root" ] ; then 
  26         echo "You must run this script as root. Sorry!" 
  31 read  -p "Please select the redis port for this instance: [$_REDIS_PORT] " REDIS_PORT 
 
  32 if [ ! `echo $REDIS_PORT | egrep "^[0-9]+\$"`  ] ; then 
  33         echo "Selecting default: $_REDIS_PORT" 
  34         REDIS_PORT
=$_REDIS_PORT  
  37 #read the redis config file 
  38 _REDIS_CONFIG_FILE
="/etc/redis/$REDIS_PORT.conf" 
  39 read -p "Please select the redis config file name [$_REDIS_CONFIG_FILE] " REDIS_CONFIG_FILE
 
  40 if [ !"$REDIS_CONFIG_FILE" ] ; then 
  41         REDIS_CONFIG_FILE
=$_REDIS_CONFIG_FILE 
  42         echo "Selected default - $REDIS_CONFIG_FILE" 
  45 mkdir -p `dirname "$REDIS_CONFIG_FILE"` || die 
"Could not create redis config directory" 
  47 #read the redis log file path 
  48 _REDIS_LOG_FILE
="/var/log/redis_$REDIS_PORT.log" 
  49 read -p "Please select the redis log file name [$_REDIS_LOG_FILE] " REDIS_LOG_FILE
 
  50 if [ !"$REDIS_LOG_FILE" ] ; then 
  51         REDIS_LOG_FILE
=$_REDIS_LOG_FILE 
  52         echo "Selected default - $REDIS_LOG_FILE" 
  56 #get the redis data directory 
  57 _REDIS_DATA_DIR
="/var/lib/redis/$REDIS_PORT" 
  58 read -p "Please select the data directory for this instance [$_REDIS_DATA_DIR] " REDIS_DATA_DIR
 
  59 if [ !"$REDIS_DATA_DIR" ] ; then 
  60         REDIS_DATA_DIR
=$_REDIS_DATA_DIR 
  61         echo "Selected default - $REDIS_DATA_DIR" 
  63 mkdir -p $REDIS_DATA_DIR || die 
"Could not create redis data directory" 
  65 #get the redis executable path 
  66 _REDIS_EXECUTABLE
=`which redis-server` 
  67 read -p "Please select the redis executable path [$_REDIS_EXECUTABLE] " REDIS_EXECUTABLE
 
  68 if [ ! -f "$REDIS_EXECUTABLE" ] ; then 
  69         REDIS_EXECUTABLE
=$_REDIS_EXECUTABLE 
  71         if [ ! -f "$REDIS_EXECUTABLE" ] ; then 
  72                 echo "Mmmmm...  it seems like you don't have a redis executable. Did you run make install yet?" 
  79 TMP_FILE
="/tmp/$REDIS_PORT.conf" 
  80 TPL_FILE
="./redis.conf.tpl" 
  81 INIT_TPL_FILE
="./redis_init_script.tpl" 
  82 INIT_SCRIPT_DEST
="/etc/init.d/redis_$REDIS_PORT" 
  84 #check the default for redis cli 
  85 CLI_EXEC
=`which redis-cli` 
  86 if [ ! "$CLI_EXEC" ] ; then  
  87         CLI_EXEC
=`dirname $REDIS_EXECUTABLE`"/redis-cli" 
  90 #Generate config file from template 
  91 echo "## Generated by install_server.sh ##" > $TMP_FILE 
  92 cat $TPL_FILE | while read line
; do eval "echo \"$line\"" >> $TMP_FILE; done 
  93 cp -f $TMP_FILE $REDIS_CONFIG_FILE || exit 1 
  95 #Generate sample script from template file 
  98 #we hard code the configs here to avoid issues with templates containing env vars 
  99 #kinda lame but works! 
 102 #Configurations injected by install_server below....\n\n 
 103 EXEC=$REDIS_EXECUTABLE\n 
 105 PIDFILE=/var/run/redis_${REDIS_PORT}.pid\n 
 106 CONF=\"$REDIS_CONFIG_FILE\"\n\n 
 109 #combine the header and the template (which is actually a static footer) 
 110 echo $REDIS_INIT_HEADER > $TMP_FILE && cat $INIT_TPL_FILE >> $TMP_FILE || die 
"Could not write init script to $TMP_FILE" 
 113 cp -f $TMP_FILE $INIT_SCRIPT_DEST && chmod +x 
$INIT_SCRIPT_DEST || die 
"Could not copy redis init script to  $INIT_SCRIPT_DEST" 
 114 echo "Copied $TMP_FILE => $INIT_SCRIPT_DEST" 
 117 echo "Installing service..." 
 118 update
-rc.d redis_
$REDIS_PORT defaults 
&& echo "Success!" 
 119 /etc
/init.d
/redis_
$REDIS_PORT start 
|| die 
"Failed starting service..." 
 122 echo "Installation successful!"