Starting Redis as a service on OS X with Homebrew
I installed Redis via brew install redis
and attempted to add it as a service via:
ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
These didn't generate any errors; however, it appears that Redis does not start. If I run redis-cli ping
, I get back Could not connect to Redis at 127.0.0.1:6379: Connection refused
.
I can manually run redis-server
in another terminal window, but I'd like to have Redis auto-start on login.
I also tried uninstalling Redis, reinstalling it, and using brew services
to manage services (brew services
works fine for me with the installations of MongoDB and Cassandra).
I haven't seen others having this problem so I'm not sure how to diagnose. If anyone has any advice, much appreciated!
make sure you've tapped the services first:
brew tap homebrew/services
then try:
brew services [start/stop/restart] redis
you can also start and stop redis with:
sudo launchctl start io.redis.redis-server
sudo launchctl stop io.redis.redis-server
to make your life easier, you can add aliases for these commands to your .bash_profile.
alias redisstart='sudo launchctl start io.redis.redis-server'
alias redisstop='sudo launchctl stop io.redis.redis-server'
then you can just start and stop redis by typing redisstart
and redisstop
.
another way you can go about this is adding redis as a background service:
sudo vim /Library/LaunchDaemons/io.redis.redis-server.plist
then copy and paste the following into the file:
<?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>/usr/local/etc/redis.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
You may have edited the conf file to daemonize redis when you used to start redis manually before. Check it and change daemonize
to no
, then retry brew services