使用Homebrew自动启动PostgreSQL的正确方法是什么?

bur*_*ger 5 postgresql macos plist

安装结束时的说明提供了用户登录时启动PostgreSQL的解决方案:

  cp /usr/local/Cellar/postgresql/9.1.3/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
  launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Run Code Online (Sandbox Code Playgroud)

我希望如果我把plist放在/ Library/LaunchAgents /中,它会在没有等我登录的情况下启动.不幸的是,这不是它的工作原理.我没有找到好的plist编辑说明,我真的害怕尝试修补它.我猜测问题在于UserName键,但我不想删除它,只是希望它有效.

这是生成的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.postgresql</string>
  <key>ProgramArguments</key>
  <array>
    <string>/usr/local/bin/postgres</string>
    <string>-D</string>
    <string>/usr/local/var/postgres</string>
    <string>-r</string>
    <string>/usr/local/var/postgres/server.log</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>UserName</key>
  <string>my_username</string>
  <key>WorkingDirectory</key>
  <string>/usr/local</string>
  <key>StandardErrorPath</key>
  <string>/usr/local/var/postgres/server.log</string>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)

kgr*_*kgr 5

我强烈推荐使用Supervisord.我在Mac上使用它,它非常好.如果您更喜欢使用PLists,那么有一个很好的工具叫做Lingon,它是一个用于管理这些工具的GUI应用程序.新版本不是免费的,但旧的版本似乎是免费的并且有效.