]>
git.saurik.com Git - redis.git/blob - utils/install_server.sh
7f4d2672ddf69d855c068311bb8c30f02bfeab26
3 # Copyright (c) 2011, Dvir Volk <dvirsky at gmail dot com >
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # # # # # # # # # # # # # # # # # # # # # # # # # #
20 # Interactive service installer for redis server
21 # this generates a redis config file and an /etc/init.d script, and installs them
22 # this scripts should be run as root
27 echo "ERROR: $1. Aborting!"
35 echo "Welcome to the redis service installer"
36 echo "This script will help you easily set up a running redis server
40 #check for root user TODO: replace this with a call to "id"
41 if [ `whoami` != "root" ] ; then
42 echo "You must run this script as root. Sorry!"
47 read -p "Please select the redis port for this instance: [$_REDIS_PORT] " REDIS_PORT
48 if [ ! `echo $REDIS_PORT | egrep "^[0-9]+\$"` ] ; then
49 echo "Selecting default: $_REDIS_PORT"
50 REDIS_PORT
=$_REDIS_PORT
53 #read the redis config file
54 _REDIS_CONFIG_FILE
="/etc/redis/$REDIS_PORT.conf"
55 read -p "Please select the redis config file name [$_REDIS_CONFIG_FILE] " REDIS_CONFIG_FILE
56 if [ !"$REDIS_CONFIG_FILE" ] ; then
57 REDIS_CONFIG_FILE
=$_REDIS_CONFIG_FILE
58 echo "Selected default - $REDIS_CONFIG_FILE"
61 mkdir -p `dirname "$REDIS_CONFIG_FILE"` || die
"Could not create redis config directory"
63 #read the redis log file path
64 _REDIS_LOG_FILE
="/var/log/redis_$REDIS_PORT.log"
65 read -p "Please select the redis log file name [$_REDIS_LOG_FILE] " REDIS_LOG_FILE
66 if [ !"$REDIS_LOG_FILE" ] ; then
67 REDIS_LOG_FILE
=$_REDIS_LOG_FILE
68 echo "Selected default - $REDIS_LOG_FILE"
72 #get the redis data directory
73 _REDIS_DATA_DIR
="/var/lib/redis/$REDIS_PORT"
74 read -p "Please select the data directory for this instance [$_REDIS_DATA_DIR] " REDIS_DATA_DIR
75 if [ !"$REDIS_DATA_DIR" ] ; then
76 REDIS_DATA_DIR
=$_REDIS_DATA_DIR
77 echo "Selected default - $REDIS_DATA_DIR"
79 mkdir -p $REDIS_DATA_DIR || die
"Could not create redis data directory"
81 #get the redis executable path
82 _REDIS_EXECUTABLE
=`which redis-server`
83 read -p "Please select the redis executable path [$_REDIS_EXECUTABLE] " REDIS_EXECUTABLE
84 if [ ! -f "$REDIS_EXECUTABLE" ] ; then
85 REDIS_EXECUTABLE
=$_REDIS_EXECUTABLE
87 if [ ! -f "$REDIS_EXECUTABLE" ] ; then
88 echo "Mmmmm... it seems like you don't have a redis executable. Did you run make install yet?"
95 TMP_FILE
="/tmp/$REDIS_PORT.conf"
96 TPL_FILE
="./redis.conf.tpl"
97 INIT_TPL_FILE
="./redis_init_script.tpl"
98 INIT_SCRIPT_DEST
="/etc/init.d/redis_$REDIS_PORT"
100 #check the default for redis cli
101 CLI_EXEC
=`which redis-cli`
102 if [ ! "$CLI_EXEC" ] ; then
103 CLI_EXEC
=`dirname $REDIS_EXECUTABLE`"/redis-cli"
106 #Generate config file from template
107 echo "## Generated by install_server.sh ##" > $TMP_FILE
108 cat $TPL_FILE | while read line
; do eval "echo \"$line\"" >> $TMP_FILE; done
109 cp -f $TMP_FILE $REDIS_CONFIG_FILE || exit 1
111 #Generate sample script from template file
114 #we hard code the configs here to avoid issues with templates containing env vars
115 #kinda lame but works!
118 #Configurations injected by install_server below....\n\n
119 EXEC=$REDIS_EXECUTABLE\n
121 PIDFILE=/var/run/redis_${REDIS_PORT}.pid\n
122 CONF=\"$REDIS_CONFIG_FILE\"\n\n
125 #combine the header and the template (which is actually a static footer)
126 echo $REDIS_INIT_HEADER > $TMP_FILE && cat $INIT_TPL_FILE >> $TMP_FILE || die
"Could not write init script to $TMP_FILE"
129 cp -f $TMP_FILE $INIT_SCRIPT_DEST && chmod +x
$INIT_SCRIPT_DEST || die
"Could not copy redis init script to $INIT_SCRIPT_DEST"
130 echo "Copied $TMP_FILE => $INIT_SCRIPT_DEST"
133 echo "Installing service..."
134 update
-rc.d redis_
$REDIS_PORT defaults
&& echo "Success!"
135 /etc
/init.d
/redis_
$REDIS_PORT start
|| die
"Failed starting service..."
138 echo "Installation successful!"