Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include LaunchAgent plist #6

Open
esad opened this issue Mar 27, 2014 · 10 comments
Open

Include LaunchAgent plist #6

esad opened this issue Mar 27, 2014 · 10 comments

Comments

@esad
Copy link

esad commented Mar 27, 2014

Official postgresql formula includes a LaunchAgent plist, any reason for not including it?

@kanmeiban
Copy link

+1

@kanmeiban
Copy link

Looking briefly through the code there are two ways to generate automatically LaunchAgent .plist:

  • by patching pg_createcluster, if one is to manage different versions with postgresql-common. Caveat: pg_createcluster is written in Perl. Even worse: it's targeted at managing Debian Linux which uses init scripts like other UNIXes and unlike OS X.
  • in the formula, like other postgresql formulas. But then if postgresql-common is used, pg_createcluster won't know anything about the generated LaunchAgent file. The user will have to manually copy and edit the .plist to make it work with the generated clusters.

@johnmartirano
Copy link

@petere
Copy link
Owner

petere commented Nov 1, 2014

Here is a thread that discusses why most of the proposed launchd.plist solutions are faulty: http://www.postgresql.org/message-id/[email protected]

@conf
Copy link

conf commented Dec 2, 2014

@petere So what is recommended option for now? I just want some default cluster to start on boot, now I'm doing by hand this command on system start:

$ pg_ctlcluster 9.4 main start

@conf
Copy link

conf commented Dec 19, 2014

@petere any ideas? What do you use?

@sylvesterjakubowski
Copy link

+1

1 similar comment
@xpepermint
Copy link

+1

@tomprats
Copy link

tomprats commented Jan 4, 2017

What did everyone here do? I'm stuck just using pg_ctlcluster for now but would like an option to do on startup

@ndbroadbent
Copy link

ndbroadbent commented Aug 11, 2022

Sorry to bother everyone on an old thread, but this is still a super useful tool and I'm trying to get my clusters to automatically start on boot.

This sorescode.com blog is offline now, but I found a cached version: http://web.archive.org/web/20200219121857/http://sorescode.com/2013/05/17/installing-postgresql-93-beta-using-homebrew.html

I read some of the replies on the postgres thread about launchd not being a good solution, and I believe the main concern was about launchd not waiting for the network to come up. Please correct me if I'm wrong, but I think that would only be relevant for daemons (in /System/Library/LaunchDaemons/, etc.), and wouldn't apply for agents (in ~/Library/LaunchAgents), since these are only run once the user logs in. (Presumably the OS would be ready to start the postgres cluster at that point.)

I have a Postgres 11 cluster named main, and here is how I set it up to start on boot:

I created a launchd plist file at /usr/local/opt/postgresql@11/homebrew.postgresql-common.11-main.start.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.postgresql-common.11-main</string>
	<key>LimitLoadToSessionType</key>
	<array>
		<string>Aqua</string>
		<string>Background</string>
		<string>LoginWindow</string>
		<string>StandardIO</string>
		<string>System</string>
	</array>
	<key>ProgramArguments</key>
	<array>
		<string>/usr/local/bin/pg_ctlcluster</string>
		<string>11</string>
		<string>main</string>
		<string>start</string>
	</array>
	<key>RunAtLoad</key>
	<true/>
	<key>StandardErrorPath</key>
	<string>/usr/local/var/log/postgresql-common.11-main.log</string>
	<key>StandardOutPath</key>
	<string>/usr/local/var/log/postgresql-common.11-main.log</string>
	<key>WorkingDirectory</key>
	<string>/usr/local</string>
</dict>
</plist>

(This just runs pg_ctlcluster 11 main start.)

Symlinked it into ~/Library/LaunchAgents:

ln -sfv /usr/local/opt/postgresql@11/homebrew.postgresql-common.11-main.start.plist ~/Library/LaunchAgents

And ran it to check that it works:

launchctl load ~/Library/LaunchAgents/homebrew.postgresql-common.11-main.start.plist

Then you can create more plists for any other clusters that you want to start. (P.S. Maybe a pg_ctlcluster start or pg_ctlcluster all start command would be helpful, to start all the clusters at once.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants