Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Install single instance of Redis on Ubuntu 14.04
#!/bin/bash
if [ "$#" -ne "2" ]; then
echo "Usage: ./install-redis-instance.sh NAME PORT"
exit 1
fi
if [ ! -x /usr/local/bin/redis-server ]; then
apt-get install -y build-essential
curl -O -L http://download.redis.io/releases/redis-2.8.9.tar.gz
tar xf redis-2.8.9.tar.gz
cd redis-2.8.9
make
make install
fi
if [ -z `getent passwd redis` ]; then
useradd -s /bin/false -m -b /var/lib redis
mkdir -p /etc/redis
mkdir -p /var/log/redis
chown redis:redis /var/log/redis
fi
mkdir -p /var/lib/redis/${1}
chown redis:redis /var/lib/redis/${1}
cat <<EOF > /etc/init/redis-${1}.conf
description "redis-${1}"
start on virtual-filesystems
stop on runlevel [06]
console log
setuid redis
setgid redis
exec /usr/local/bin/redis-server /etc/redis/redis-${1}.conf
EOF
cat <<EOF > /etc/redis/redis-${1}.conf
daemonize no
port ${2}
bind 0.0.0.0
dir /var/lib/redis/${1}
logfile /var/log/redis/redis-${1}.log
EOF
restart redis-${1}
#!/bin/bash
if [ "$#" -ne "1" ]; then
echo "Usage: ./remove-redis-instance.sh NAME"
exit 1
fi
if [ ! -f /etc/init/redis-${1}.conf ]; then
exit 0
fi
stop redis-${1}
rm -rf /var/lib/redis/${1}
rm -f /var/log/redis/redis-${1}.log
rm -f /etc/init/redis-${1}.conf
rm -f /etc/redis/redis-${1}.conf
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment