Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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

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

respawn

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!

@caius

It was helpful - thanks.

@aoberoi

sweet!

@mschwar99

+1 to you. Thanks!

@ganeshnaidu

Thanks

@gremmie

Thank you.

@SamDuvall

Great article. Thank you!

@nathancahill

Thanks, very helpful.

@jmfederico

THANKS!!!

@phpguru

Works perfectly, thanks. The biggest surprise is setting daemonize to no in redis.conf.

@twoolie

check out an updated version that works with default redis.conf https://gist.github.com/4617553

@cvrebert

I think you can setuid redis instead of using sudo -u

@zampino

very nice

@em-cliqz

The "disable" option for update-rc doesn't completely remove the redis bits. Use the 'remove' option instead:
update-rc.d -f redis-server remove

@rogerleite

@bdotdub Great article! I saw @twoolie fork and merged all in a shell script version: https://gist.github.com/rogerleite/5927948#file-redis-install-sh

@dh1tw

That did the trick. thanks!

@beckyb8

You made it almost /too/ easy! Many thanks!

@jzwolak

I also had to create the redis user since I didn't have one.

I used

adduser --system --no-create-home redis

And I created a directory for the database dump in /var/redis, chown redis /var/redis

And finally, changed the /etc/redis/redis.conf to have the following line

dir /var/redis

Thanks a bunch for this info!

@MattSurabian

Why not use setgid and setuid stanzas instead of sudo -u.

description "redis server"

# optional to run under the redis user
#setgid redis
#setuid redis

start on runlevel [23]
stop on shutdown
respawn 

script
  redis-server PATH_TO_CONF
end script

@dh1tw

good tip to run change redis.conf -> deamonized no

@sr3d

nice write up. Very helpful for me to setup a new Redis instance

@antonzaytsev

Thanks so much! Very helpful!

@beckyb8

Worked a treat. Thank you!

@JREAM

Thanks awesome

@algodave

Great job! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.