Last active
December 23, 2015 00:18
-
-
Save jstott/6552270 to your computer and use it in GitHub Desktop.
redis.io install and initial setup (Ubuntu 13.04 bash shell) for upstart
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 | |
# Install redis and run via upstart on Ubuntu. | |
# | |
# Get Script: | |
# wget -O redis-install-full.sh https://gist.github.com/jstott/6552270/raw | |
# chmod +x redis-install-full.sh | |
# | |
# Usage: sudo ./redis-install-full.sh | |
# | |
# By Jim Stott (https://gist.github.com/jstott) | |
# | |
# Tested on Ubuntu 13.04 x64 | |
# Created at: 2013-09-11 | |
# | |
# Script based on gists: | |
# Roger Leite (https://github.com/rogerleite) | |
# https://gist.github.com/bdotdub/714533 | |
# from Benny Wong (https://github.com/bdotdub) | |
# https://gist.github.com/twoolie/4617553 | |
# from Thomas Woolford (https://github.com/twoolie) | |
if [[ $EUID -ne 0 ]]; then | |
echo "To run this script you need to be root (or use sudo)" 2>&1 | |
exit 1 | |
fi | |
echo "-> apt-get update, upgrade" | |
apt-get update | |
apt-get -y upgrade | |
echo "-> apt-get install build-essential" | |
apt-get -y install build-essential | |
echo "-> sudo apt-get install tcl8.5" | |
apt-get -y install tcl8.5 | |
echo "-> creating redis user" | |
adduser --system --disabled-password --group --no-create-home --shell /bin/bash redis | |
echo "-> download redis and build" | |
wget http://download.redis.io/redis-stable.tar.gz | |
tar xzf redis-stable.tar.gz | |
cd redis-stable | |
make | |
make test | |
make install | |
echo "-> setup directory /etc/redis" | |
mkdir /etc/redis | |
chmod ga+rw /etc/redis | |
cp redis.conf /etc/redis/redis.conf | |
echo "-> setup directory for /var/redis/dump.rdb" | |
mkdir /var/redis | |
chmod ga+rw /var/redis | |
echo "-> fix up redis.conf paths [dir, tcp-keepalive, logfile] options" | |
chmod ga+wr /var/log | |
sed "s:^dir .*$:dir /var/redis/:" -i /etc/redis/redis.conf | |
sed "s:^tcp-keepalive .*$:tcp-keepalive 60:" -i /etc/redis/redis.conf | |
sed "s:^logfile stdout$:logfile /var/log/redis.log:" -i /etc/redis/redis.conf | |
echo "-> set vm.overcommit_memory =1 to prevent background save in low mem condition" | |
grep -q "^vm.overcommit_memory.*" /etc/sysctl.conf && sed "s:^vm.overcommit_memory .*$:vm.overcommit_memory = 1:" -i /etc/sysctl.conf || sed "$ a\vm.overcommit_memory = 1" -i /etc/sysctl.conf | |
echo "-> setup redis config for upstart" | |
echo "-> writing /etc/init/redis-server.conf" | |
cat <<EOF > /etc/init/redis-server.conf | |
description "Redis Server" | |
author "Rdaemon <http://rdaemon.com/author/rda3mon>" | |
# http://rdaemon.com/tech/install-redis-from-source-and-configure-upstart-script | |
# run when the local FS becomes available | |
# Runlevels | |
# 0 : System halt | |
# 1 : Single-User mode | |
# 2-5 : Graphical multi-user plus networking | |
# 6 : System reboot | |
start on local-filesystems | |
stop on runlevel [016] | |
#enable this if daemonize=yes in /etc/redis.conf | |
#expect fork | |
# respawns if server dies, count=15, timeout=5s | |
respawn | |
respawn limit 15 5 | |
env NAME=redis | |
# start a default instance | |
instance \$NAME | |
# run redis as the correct user | |
setuid redis | |
setgid redis | |
# run redis with the correct config file for this instance | |
exec /usr/local/bin/redis-server /etc/redis/\${NAME}.conf | |
EOF | |
echo "-> success!" | |
cat <<EOF | |
-> one can check log | |
tail -f /var/log/redis/redis.log | |
-> commands to control your redis-server | |
sudo start redis-server [ name=redis ] | |
sudo restart redis-server [ name=redis ] | |
sudo status redis-server [ name=redis ] | |
sudo stop redis-server [ name=redis ] | |
EOF | |
redis-server --version |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment