How to setup Memcached Server to run at boot time in Mac OS

Filed Under: Scripts

In the last post we learnt how to install Memcached server on Mac OS. If you want to run Memcache when system boots for Mac OS, then you have to put the PList configuration file in /Library/LaunchDaemons/ directory and set the owner to root user.

Create a file in the /Library/LaunchDaemons/ directory with name memcached.plist with below content.


<?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>org.memcached</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/memcached</string>
<string>-d</string>
<string>-u</string>
<string>root</string>
<string>-p</string>
<string>11211</string>
<string>-m</string>
<string>64</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>

Once the file is created change the owner to root with below command:


$chown root:wheel memcached.plist

memcached as daemon process on mac os x

Now when you will boot your Mac OS, Memcached server will get started automatically as a daemon process on port 11211 and allocated memory is 64 MB.

Use ps -eaf | grep memcached or telnet command to verify it.

NOTE: I tried this on macOS Sierra (10.12.x) but this doesn’t seem to work. It seems we have to load the plist file using below command.


$launchctl load -w /Library/LaunchDaemons/org.memcached.plist

But I am getting below error message in console.


Jul 25 14:11:58 --- last message repeated 1 time ---
Jul 25 14:11:58 pankaj com.apple.xpc.launchd[1] (org.memcached[1113]): Service could not initialize: 16F73: xpcproxy + 11769 [1505][34964CF1-9965-3B4D-ADC7-6FBC6669C56D]: 0xd
Jul 25 14:11:58 pankaj com.apple.xpc.launchd[1] (org.memcached): Service only ran for 0 seconds. Pushing respawn out by 10 seconds.

I tried many different options but it doesn’t seem to work. If you have faced something like this and able to get it working, please comment and let me know.

Comments

  1. Sean H. says:

    Good Day Pankaj, and thank you for this article series. It is exactly what I needed to get memcache working on my local dev environment.

    I wanted to reach out regarding your `launchctl load -w /Library/LaunchDaemons/org.memcached.plist` command. Following your initial directions, I named the file `memcached.plist` not `org.memcached.plist` and when I ran the `launchctl load` command without the `org` I did not receive any errors. Not sure if you were able to overcome that issue, but hopefully it will help.

    Cheers!
    – Sean

Leave a Reply

Your email address will not be published. Required fields are marked *

close
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages