-
-
Save Arzte/a3a05fe63adbf2e57f6070f62677fbed to your computer and use it in GitHub Desktop.
Install single instance of Redis on Ubuntu 14.04
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 127.0.0.1 | |
dir /var/lib/redis/${1} | |
logfile /var/log/redis/redis-${1}.log | |
EOF | |
restart redis-${1} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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