Running Redis as a User Daemon on OSX with launchd

2011/03/5

If you’re developing on the mac using redis and want it to start automatically on boot, you’ll want to leverage the OSX launchd system to run it as a User Daemon. A User Daemon is a non-gui program that runs in the background as part of the system. It isn’t associated with your user account. If you only want redis to launch when a particular user logs in, you’ll want to make a User Agent instead.

From the command line, create a plist file as root in the /Library/LaunchDaemons directory with your favorite text editor:

sudo vim /Library/LaunchDaemons/io.redis.redis-server.plist

Paste in the following contents and modify it to point it to wherever you’ve got redis-server installed and optionally pass the location of a config file to it (delete the redis.conf line if you’re not using one):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Label</key>
	<string>io.redis.redis-server</string>
	<key>ProgramArguments</key>
	<array>
		<string>/usr/local/bin/redis-server</string>
		<string>/optional/path/to/redis.conf</string>
	</array>
	<key>RunAtLoad</key>
	<true/>
</dict>
</plist>

You’ll then need to load the file (one time) into launchd with launchctl:

sudo launchctl load /Library/LaunchDaemons/io.redis.redis-server.plist

Redis will now automatically be started after every boot. You can manually start it without rebooting with:

sudo launchctl start io.redis.redis-server

You can also shut down the server with

sudo launchctl stop io.redis.redis-server

Or you could add these aliases to your bash/zsh rc file:

alias redisstart='sudo launchctl start io.redis.redis-server'
alias redisstop='sudo launchctl stop io.redis.redis-server'

If you’re having some sort of error (or just want to watch the logs), you can just fire up Console.app to watch the redis logs to see what’s going on.

There are 4 comments in this article:

  1. 2011/03/5Running Redis as a User Daemon on OSX with launchd say:

    [...] as a User Daemon. A User Daemon is a non-gui program that runs in the background as part of the… [full post] tednaleid Ted Naleid command lineosxredis 0 0 0 0 0 [...]

  2. 2011/03/6Shaun Jurgemeyer say:

    If your redis.conf has relative paths you can also add the following to your io.redis.redis-server.plist.

    <key>WorkingDirectory</key>
    <string>/projects/bloomhealth/bloomhealth</string>
  3. 2011/03/6tednaleid say:

    Did that work for you Shaun? I had problems starting up the server when I tried to use the WorkingDirectory key, so I switched paths so they weren’t relative in my redis.conf.

  4. 2011/12/9Robert Ross say:

    If you install redis through Homebrew, they plist file is located in the Cellar path in /usr/local/Cellar/redis.

Write a comment: