0

I am working on setting up a psql server and would therefore like postgres to run whenever the computer is on, regardless of whether I'm logged it. (The machine is running OS X Yosemite.) I set up a launch daemon to do this, but it doesn't work. syslog gives the following error messages:

Jul 14 17:43:01 user@server sudo[276]:     jaia : TTY=ttys000 ; 
PWD=/Users/jaia ; USER=root ; COMMAND=/usr/bin/nano /Library/LaunchDaemons/homeb
rew.mxcl.postgresql.plist
Jul 14 17:44:35 localhost com.apple.xpc.launchd[1] (homebrew.mxcl.postgresql): T
his service is defined to be constantly running and is inherently inefficient.
Jul 14 17:44:44 localhost com.apple.xpc.launchd[1] (homebrew.mxcl.postgresql): S
ervice only ran for 9 seconds. Pushing respawn out by 1 seconds.
Jul 14 17:44:45 localhost com.apple.xpc.launchd[1] (homebrew.mxcl.postgresql): S
ervice only ran for 0 seconds. Pushing respawn out by 10 seconds.

After that, the last message repeats indefinitely.

Here's my .plist file. The reason for sudo -u _postgres is that postgres can't run as root, which launch daemons do by default.

<?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>sudo</string>
    <string>-u</string>
    <string>_postgres</string>
    <string>/usr/local/bin/pg_ctl</string>
    <string>-D</string>
    <string>/usr/local/var/postgres</string>
    <string>start</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>UserName</key>
  <string>_postgres</string>
  <key>WorkingDirectory</key>
  <string>/usr/local/var/postgres</string>
  <key>StandardErrorPath</key>
  <string>/usr/local/var/postgres/server.log</string>
</dict>
</plist>

MORE INFORMATION: Loading the job manually via ssh gives the ungrammatical error message "Could not find domain for". Loading it on the machine itself gives "/Library/LaunchDaemons/homebrew.mxcl.postgresql.plist: File exists".

What could be going wrong here?

1 Answer 1

1

Leave out the sudo, -u and _postgres in ProgramArguments. launchd takes care of this with the UserName key.

8
  • I made the change and while I'm not getting the "postgresql can't run as root" message, it's still not launching.
    – jaia
    Commented Jul 15, 2015 at 21:33
  • What does launchctl report? What's in /usr/local/var/postgres/server.log?
    – LCC
    Commented Jul 16, 2015 at 6:43
  • There's nothing new in the postgres log. How do I check what launchctl is reporting?
    – jaia
    Commented Jul 16, 2015 at 7:08
  • You may want to check out the 'Troubleshooting' section of this launchd tutorial. It explains how to start a job and what to do if it does not work
    – LCC
    Commented Jul 16, 2015 at 12:29
  • Loading the job manually via ssh gives the error message "Could not find domain for". That's apparently common with ssh. I'll try again when I can get into the room.
    – jaia
    Commented Jul 16, 2015 at 17:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .