使用Homebrew安装的redis将自动启动

安装Homebrew后,会附带一个配置文件,可以使用它来自动启动launchctl(在Mac上用于自动启动的一些东西)。只需适时更改版本部分即可。

$ cp /usr/local/Cellar/redis/2.4.8/homebrew.mxcl.redis.plist ~/Library/LaunchAgents/
$ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
$ launchctl start homebrew.mxcl.redis

homebrew.mxcl.redis.plist的内容可以进行如下释义:

<?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>KeepAlive</key>
    <true/>
    <key>Label</key>
    <string>homebrew.mxcl.redis</string>
    <key>ProgramArguments</key>
    <array>
      <string>/usr/local/bin/redis-server</string>
      <string>/usr/local/etc/redis.conf</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>UserName</key>
    <string>marqs</string>
    <key>WorkingDirectory</key>
    <string>/usr/local/var</string>
    <key>StandardErrorPath</key>
    <string>/usr/local/var/log/redis.log</string>
    <key>StandardOutPath</key>
    <string>/usr/local/var/log/redis.log</string>
  </dict>
</plist>

请参考以下链接:
http://www.maruko2.com/mw/LaunchDaemons_(launchctl,_launchd.plist)_%E7%9A%84%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95
https://github.com/mxcl/homebrew/pull/10913

广告
将在 10 秒后关闭
bannerAds