Installed memcached via homebrew, how to start and stop server?

RubyMemcachedHomebrew

Ruby Problem Overview


I have memcached installed via homebrew.

  1. how do I start/stop the server?

  2. Any command-line tools to interact with memcached?

  3. does homebrew have a way of removing a package?

Ruby Solutions


Solution 1 - Ruby

When you installed it, it put a file named homebrew.mxcl.memcached.plist in /usr/local/Cellar/memcached/$version/; you copy that file into ~/Library/LaunchAgents and then tell launchd to start it with launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist.

If you were watching the console carefully during the brew install command, it should have said something about doing these exact steps. If you run brew info it'll re-print this information, e.g. brew info memcached.

You should probably read https://docs.brew.sh/Manpage -- it has more useful documentation including the brew remove command which will remove the package if you decide you don't want it.

Solution 2 - Ruby

  1. Brew used to have a command brew services (https://thoughtbot.com/blog/starting-and-stopping-background-services-with-homebrew), now deprecated. Instead, to get always-correct advice, run this command:

    brew info memcached

  2. Via telnet: telnet localhost 11211

    See also https://stackoverflow.com/questions/16110143/what-are-some-useful-tips-tools-for-monitoring-tuning-memcached-health

  3. brew remove memcached

Solution 3 - Ruby

Additionally you can run "brew info", if you have forgotten about the instructions.

→ brew info memcached
memcached 1.4.7
http://memcached.org/
Depends on: libevent
/usr/local/Cellar/memcached/1.4.6 (8 files, 156K)

You can enable memcached to automatically load on login with:
mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/memcached/1.4.7/com.danga.memcached.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/com.danga.memcached.plist

Or start it manually:
    /usr/local/bin/memcached

Add "-d" to start it as a daemon.

http://github.com/mxcl/homebrew/commits/master/Library/Formula/memcached.rb

Solution 4 - Ruby

To restart: If you have the memcached starting up with launchd and your plist file has

  <key>KeepAlive</key>
  <true/>

Then you can just kill the process and it will reboot automagically.

ps ux | grep memcached
pkill -f memcached
ps ux | grep memcached

To stop launchd from restarting automatically:

launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist

To add memcached to launchd again:

launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist

To uninstall something installed by homebrew:

brew uninstall memcached

Solution 5 - Ruby

And you can also create aliases

alias memcached-start="launchctl load ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist"
alias memcached-stop="launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist"
alias memcached-restart="launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist;launchctl load ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist"

and after that you cant easy start/stop/restart memcached

memcached-start
memcached-stop
memcached-restart

Solution 6 - Ruby

You can also use Lunchy to set the start/stop. Lunchy is a wrapper written over launchctl. I’ve written a detailed post about this.

$ gem install lunchy
$ mkdir ~/Library/LaunchAgents
$ cp /usr/local/Cellar/memcached/$version/homebrew.mxcl.memcached.plist ~/Library/LaunchAgents/

To start memcached

$ lunchy start memcached

To stop memcahed

$ lunchy stop memcached

Solution 7 - Ruby

You can enable Memcached to automatically load on login.

This first line creates a symlink (symbolic link) from where Homebrew installed it to the LaunchAgents folder.

ln -sfv /usr/local/Cellar/memcached/1.4.17/homebrew.mxcl.memcached.plist ~/Library/LaunchAgents/

Then to launch it now:

launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBlankmanView Question on Stackoverflow
Solution 1 - RubycleeView Answer on Stackoverflow
Solution 2 - RubydubillaView Answer on Stackoverflow
Solution 3 - RubyPratik KhadloyaView Answer on Stackoverflow
Solution 4 - RubyearlonrailsView Answer on Stackoverflow
Solution 5 - RubyAndrey KorchakView Answer on Stackoverflow
Solution 6 - RubyRahul JiresalView Answer on Stackoverflow
Solution 7 - RubyRyanView Answer on Stackoverflow