Skip to content

Instantly share code, notes, and snippets.

@twoolie
Forked from bdotdub/redis.markdown
Last active February 9, 2022 09:21
Show Gist options
  • Save twoolie/4617553 to your computer and use it in GitHub Desktop.
Save twoolie/4617553 to your computer and use it in GitHub Desktop.

Running redis using upstart on Ubuntu

I've been trying to understand how to setup systems from the ground up on Ubuntu. I just installed redis onto the box and here's how I did it and some things to look out for.

To install:

sudo apt-get install redis-server

That will create a redis user and install the init.d script for it. Since upstart is now the replacement for using init.d, I figure I should convert it to run using upstart.

To disable the default init.d script for redis:

sudo update-rc.d redis-server disable

Then create /etc/init/redis-server.conf with the following

description "Redis Server"
author "Thomas Woolford <[email protected]>"

# run when the local FS becomes available
start on local-filesystems
stop on shutdown

# The default redis conf has `daemonize = yes` and will naiively fork itself.
expect fork

# Respawn unless redis dies 10 times in 5 seconds
respawn
respawn limit 10 5

# start a default instance
instance $NAME
env NAME=redis

# run redis as the correct user
setuid redis
setgid redis

# run redis with the correct config file for this instance
exec /usr/bin/redis-server /etc/redis/${NAME}.conf

What this is is the script for upstart to know what command to run to start the process.

Now you can use the folowing 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 ]

Hope this was helpful!

@juriglx
Copy link

juriglx commented Feb 24, 2015

you can also increase the file limit with:
limit nofile 10032 10032

@hawko2600
Copy link

For versions of upstart that setuid/setgid doesn't exist in because they're 4 years / 21 major versions behind (Hi Redhat!), you can have redis start as another user by exploiting functionality of chroot

exec chroot --userspec redis:redis / /usr/local/bin/redis-server /usr/local/etc/${NAME}.conf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment