Skip to content

Instantly share code, notes, and snippets.

@brow
Forked from bdotdub/redis.markdown
Created October 26, 2011 10:13
Show Gist options
  • Save brow/1315952 to your computer and use it in GitHub Desktop.
Save brow/1315952 to your computer and use it in GitHub Desktop.
Running redis using upstart on Ubuntu

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 script:

description "redis server"

start on runlevel [23]
stop on shutdown
expect daemon
respawn

exec sudo -u redis /usr/bin/redis-server /etc/redis/redis.conf

What this is is the script for upstart to know what command to run to start the process. The last line also tells upstart to keep trying to respawn if it dies.

One thing I had to change in /etc/redis/redis.conf is to change daemonize yes to daemonize no. What happens if you don't change it is that redis-server will fork and daemonize itself, and the parent process goes away. When this happens, upstart thinks that the process has died/stopped and you won't have control over the process from within upstart.

Now you can use the folowing commands to control your redis-server:

sudo start redis-server
sudo restart redis-server
sudo stop redis-server

Hope this was helpful!

@jmfederico
Copy link

Hello, one question, if you set daemonize no why should we use expect daemon

Cheers

@MattSurabian
Copy link

As @jmfederico suggests if Redis is set to daemonize no you don't need expect daemon or expect fork

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