Permalink
Browse files

Add and use plist helper methods

These will be used to unify the label namespaces in embedded plists,
i.e. 'homebrew.mxcl.<formula>'.

plist_path returns the full path to a plist file located at the top
level of the keg; plist_path.basename can be used if just the filename
is needed.

c.f. #9346.

Signed-off-by: Jack Nagel <jacknagel@gmail.com>
  • Loading branch information...
1 parent 95e379f commit b5a5217ba3117dfbfcad63532c2054d83d3249c0 @jacknagel jacknagel committed Dec 31, 2011
@@ -31,15 +31,15 @@ def install
prefix.install Dir["*.txt"] + Dir["{bin,interface,javadoc,lib/licenses}"]
prefix.install Dir["lib/*.jar"]
- (prefix+'org.apache.cassandra.plist').write startup_plist
- (prefix+'org.apache.cassandra.plist').chmod 0644
+ plist_path.write startup_plist
+ plist_path.chmod 0644
end
def caveats; <<-EOS.undent
If this is your first install, automatically load on login with:
mkdir -p ~/Library/LaunchAgents
- cp #{prefix}/org.apache.cassandra.plist ~/Library/LaunchAgents/
- launchctl load -w ~/Library/LaunchAgents/org.apache.cassandra.plist
+ cp #{plist_path} ~/Library/LaunchAgents/
+ launchctl load -w ~/Library/LaunchAgents/#{plist_path.basename}
EOS
end
@@ -52,7 +52,7 @@ def startup_plist; <<-EOPLIST
<true/>
<key>Label</key>
- <string>org.apache.cassandra</string>
+ <string>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
@@ -15,16 +15,16 @@ def install
system "mv couchdb-lucene-#{version}/* #{prefix}"
(etc + "couchdb/local.d/couchdb-lucene.ini").write ini_file
- (prefix+"couchdb-lucene.plist").write plist_file
- (prefix+"couchdb-lucene.plist").chmod 0644
+ plist_path.write startup_plist
+ plist_path.chmod 0644
end
def caveats; <<-EOS.undent
You can enable couchdb-lucene to automatically load on login with:
mkdir -p ~/Library/LaunchAgents
- cp "#{prefix}/couchdb-lucene.plist" ~/Library/LaunchAgents/
- launchctl load -w ~/Library/LaunchAgents/couchdb-lucene.plist
+ cp "#{plist_path}" ~/Library/LaunchAgents/
+ launchctl load -w ~/Library/LaunchAgents/#{plist_path.basename}
Or start it manually with:
#{bin}/run
@@ -44,15 +44,15 @@ def ini_file
EOS
end
- def plist_file
+ def startup_plist
return <<-EOS
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
- <string>couchdb-lucene</string>
+ <string>#{plist_name}</string>
<key>EnvironmentVariables</key>
<dict>
<key>HOME</key>
@@ -36,8 +36,8 @@ def install
(var + 'run/ddclient').mkpath
# Write the launchd script
- (prefix + 'org.ddclient.plist').write startup_plist
- (prefix + 'org.ddclient.plist').chmod 0644
+ plist_path.write startup_plist
+ plist_path.chmod 0644
end
def caveats; <<-EOS
@@ -51,21 +51,21 @@ def caveats; <<-EOS
2) Install the launchd item in /Library/LaunchDaemons, like so:
- sudo cp -vf #{prefix}/org.ddclient.plist /Library/LaunchDaemons/
- sudo chown -v root:wheel /Library/LaunchDaemons/org.ddclient.plist
+ sudo cp -vf #{plist_path} /Library/LaunchDaemons/
+ sudo chown -v root:wheel /Library/LaunchDaemons/#{plist_path.basename}
3) Start the daemon using:
- sudo launchctl load /Library/LaunchDaemons/org.ddclient.plist
+ sudo launchctl load /Library/LaunchDaemons/#{plist_path.basename}
The next reboot of the system will automatically start ddclient.
You can adjust the execution interval by changing the value of
-StartInterval (in seconds) in /Library/LaunchDaemons/org.ddclient.plist,
+StartInterval (in seconds) in /Library/LaunchDaemons/#{plist_path.basename},
and then
- sudo launchctl unload /Library/LaunchDaemons/org.ddclient.plist
- sudo launchctl load /Library/LaunchDaemons/org.ddclient.plist
+ sudo launchctl unload /Library/LaunchDaemons/#{plist_path.basename}
+ sudo launchctl load /Library/LaunchDaemons/#{plist_path.basename}
EOS
end
@@ -76,7 +76,7 @@ def startup_plist
<plist version="1.0">
<dict>
<key>Label</key>
- <string>org.ddclient</string>
+ <string>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
<string>#{HOMEBREW_PREFIX}/sbin/ddclient</string>
@@ -43,9 +43,8 @@ def install
ln_s libexec + 'denyhosts.py', sbin + 'denyhosts'
ln_s libexec + 'daemon-control', sbin + 'daemon-control'
- plist = prefix + 'org.denyhosts.cron.plist'
- plist.write cron_plist
- plist.chmod 0644
+ plist_path.write cron_plist
+ plist_path.chmod 0644
end
def cron_plist
@@ -55,7 +54,7 @@ def cron_plist
<plist version="1.0">
<dict>
<key>Label</key>
- <string>org.denyhosts.cron</string>
+ <string>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
<string>#{HOMEBREW_PREFIX}/sbin/denyhosts</string>
@@ -83,7 +82,7 @@ def caveats
/etc/hosts.deny every 10 minutes. It will need to be run by the user that
owns /etc/hosts.deny, usually root, and can be set to load at startup
via:
- sudo cp #{prefix}/org.denyhosts.cron.plist /Library/LaunchDaemons/
+ sudo cp #{plist_path} /Library/LaunchDaemons/
EOS
end
@@ -31,8 +31,8 @@ def install
system "make install PREFIX=#{prefix}"
prefix.install "dnsmasq.conf.example"
- (prefix + "uk.org.thekelleys.dnsmasq.plist").write startup_plist
- (prefix + "uk.org.thekelleys.dnsmasq.plist").chmod 0644
+ plist_path.write startup_plist
+ plist_path.chmod 0644
end
def caveats; <<-EOS.undent
@@ -44,8 +44,8 @@ def caveats; <<-EOS.undent
To load dnsmasq automatically on startup, install and load the provided launchd
item as follows:
- sudo cp #{prefix}/uk.org.thekelleys.dnsmasq.plist /Library/LaunchDaemons
- sudo launchctl load -w /Library/LaunchDaemons/uk.org.thekelleys.dnsmasq.plist
+ sudo cp #{plist_path} /Library/LaunchDaemons
+ sudo launchctl load -w /Library/LaunchDaemons/#{plist_path.basename}
EOS
end
@@ -55,7 +55,7 @@ def startup_plist; <<-EOS.undent
<plist version="1.0">
<dict>
<key>Label</key>
- <string>uk.org.thekelleys.dnsmasq</string>
+ <string>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
<string>#{HOMEBREW_PREFIX}/sbin/dnsmasq</string>
@@ -24,13 +24,13 @@ def caveats; <<-EOS
2) If required by the configuration above, create a dovecot user and group
-3) possibly create a launchd item in /Library/LaunchDaemons/org.dovecot.plist, like so:
+3) possibly create a launchd item in /Library/LaunchDaemons/#{plist_path.basename}, like so:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
- <string>org.dovecot</string>
+ <string>#{plist_name}</string>
<key>OnDemand</key>
<false/>
<key>ProgramArguments</key>
@@ -46,7 +46,7 @@ def caveats; <<-EOS
</plist>
Source: http://wiki.dovecot.org/LaunchdInstall
-4) start the server using: sudo launchctl load /Library/LaunchDaemons/org.dovecot.plist
+4) start the server using: sudo launchctl load /Library/LaunchDaemons/#{plist_path.basename}
EOS
end
end
@@ -48,24 +48,24 @@ def install
end
# Write .plist file for `launchd`
- (prefix+'org.elasticsearch.plist').write startup_plist
- (prefix+'org.elasticsearch.plist').chmod 0644
+ plist_path.write startup_plist
+ plist_path.chmod 0644
end
def caveats
<<-EOS.undent
If this is your first install, automatically load ElasticSearch on login with:
mkdir -p ~/Library/LaunchAgents
- ln -nfs #{prefix}/org.elasticsearch.plist ~/Library/LaunchAgents/
- launchctl load -wF ~/Library/LaunchAgents/org.elasticsearch.plist
+ ln -nfs #{plist_path} ~/Library/LaunchAgents/
+ launchctl load -wF ~/Library/LaunchAgents/#{plist_path.basename}
- If this is an upgrade and you already have the org.elasticsearch.plist loaded:
- launchctl unload -w ~/Library/LaunchAgents/org.elasticsearch.plist
- ln -nfs #{prefix}/org.elasticsearch.plist ~/Library/LaunchAgents/
- launchctl load -wF ~/Library/LaunchAgents/org.elasticsearch.plist
+ If this is an upgrade and you already have the #{plist_path} loaded:
+ launchctl unload -w ~/Library/LaunchAgents/#{plist_path.basename}
+ ln -nfs #{plist_path} ~/Library/LaunchAgents/
+ launchctl load -wF ~/Library/LaunchAgents/#{plist_path.basename}
To stop the ElasticSearch daemon:
- launchctl unload -wF ~/Library/LaunchAgents/org.elasticsearch.plist
+ launchctl unload -wF ~/Library/LaunchAgents/#{plist_path.basename}
To start ElasticSearch manually:
elasticsearch -f -D es.config=#{prefix}/config/elasticsearch.yml
@@ -93,7 +93,7 @@ def startup_plist
<key>KeepAlive</key>
<true/>
<key>Label</key>
- <string>org.elasticsearch</string>
+ <string>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
<string>#{HOMEBREW_PREFIX}/bin/elasticsearch</string>
@@ -71,30 +71,30 @@ def install
end
# sample launchd plists
- (prefix+'org.isc.dhcpd.plist').write dhcpd_plist
- (prefix+'org.isc.dhcpd.plist').chmod 0644
- (prefix+'org.isc.dhcpd6.plist').write dhcpd6_plist
- (prefix+'org.isc.dhcpd6.plist').chmod 0644
+ plist_path.write dhcpd_plist
+ plist_path.chmod 0644
+ (prefix+'homebrew.mxcl.dhcpd6.plist').write dhcpd6_plist
+ (prefix+'homebrew.mxcl.dhcpd6.plist').chmod 0644
end
def caveats
<<-EOCAVEATS.undent
- This install of dhcpd expects config files to be in /usr/local/etc.
- All state files (leases and pids) are stored in /usr/local/var/dhcpd.
+ This install of dhcpd expects config files to be in #{etc}.
+ All state files (leases and pids) are stored in #{var}/dhcpd.
Dhcpd needs to run as root since it listens on privileged ports.
Sample launchd plists to achieve this have been provided at:
- #{prefix}/org.isc.dhcpd.plist
+ #{plist_path}
and:
- #{prefix}/org.isc.dhcpd6.plist
+ #{prefix}/homebrew.mxcl.dhcpd6.plist
There are two plists because a single dhcpd process may do either
DHCPv4 or DHCPv6 but not both. Use one or both as needed.
Copy the plists to /Library/LaunchDaemons and start the services with
cd /Library/LaunchDaemons
- launchctl load -w org.isc.dhcpd.plist
- launchctl load -w org.isc.dhcpd6.plist
+ launchctl load -w #{plist_path.basename}
+ launchctl load -w homebrew.mxcl.dhcpd6.plist
Note that you must create the appropriate config files before starting
the services or dhcpd will refuse to run.
@@ -103,8 +103,8 @@ def caveats
Sample config files may be found in #{etc}.
If you change the config, restart dhcpd with one or both of
- launchctl stop org.isc.dhcpd
- launchctl stop org.isc.dhcpd6
+ launchctl stop #{plist_name}
+ launchctl stop homebrew.mxcl.dhcpd6
EOCAVEATS
end
@@ -115,7 +115,7 @@ def dhcpd_plist
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version='1.0'>
<dict>
- <key>Label</key><string>org.isc.dhcpd</string>
+ <key>Label</key><string>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
<string>#{HOMEBREW_PREFIX}/sbin/dhcpd</string>
@@ -137,7 +137,7 @@ def dhcpd6_plist
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version='1.0'>
<dict>
- <key>Label</key><string>org.isc.dhcpd</string>
+ <key>Label</key><string>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
<string>#{HOMEBREW_PREFIX}/sbin/dhcpd</string>
@@ -10,20 +10,20 @@ class Jenkins < Formula
def install
system "mvn clean install -pl war -am -DskipTests && mv war/target/jenkins.war ." if ARGV.build_head?
lib.install "jenkins.war"
- (prefix+'org.jenkins-ci.plist').write startup_plist
- (prefix+'org.jenkins-ci.plist').chmod 0644
+ plist_path.write startup_plist
+ plist_path.chmod 0644
end
def caveats; <<-EOS
If this is your first install, automatically load on login with:
mkdir -p ~/Library/LaunchAgents
- cp #{prefix}/org.jenkins-ci.plist ~/Library/LaunchAgents/
- launchctl load -w ~/Library/LaunchAgents/org.jenkins-ci.plist
+ cp #{plist_path} ~/Library/LaunchAgents/
+ launchctl load -w ~/Library/LaunchAgents/#{plist_path.basename}
-If this is an upgrade and you already have the org.jenkins-ci.plist loaded:
- launchctl unload -w ~/Library/LaunchAgents/org.jenkins-ci.plist
- cp #{prefix}/org.jenkins-ci.plist ~/Library/LaunchAgents/
- launchctl load -w ~/Library/LaunchAgents/org.jenkins-ci.plist
+If this is an upgrade and you already have the #{plist_path} loaded:
+ launchctl unload -w ~/Library/LaunchAgents/#{plist_path.basename}
+ cp #{plist_path} ~/Library/LaunchAgents/
+ launchctl load -w ~/Library/LaunchAgents/#{plist_path.basename}
Or start it manually:
java -jar #{lib}/jenkins.war
@@ -42,7 +42,7 @@ def startup_plist
<plist version="1.0">
<dict>
<key>Label</key>
- <string>Jenkins</string>
+ <string>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/java</string>
@@ -65,8 +65,8 @@ def install
(prefix+'mysql-test').rmtree unless ARGV.include? '--with-tests' # save 121MB!
(prefix+'sql-bench').rmtree unless ARGV.include? '--with-bench'
- (prefix+'com.mysql.mysqld.plist').write startup_plist
- (prefix+'com.mysql.mysqld.plist').chmod 0644
+ plist_path.write startup_plist
+ plist_path.chmod 0644
end
def caveats; <<-EOS.undent
@@ -75,16 +75,16 @@ def caveats; <<-EOS.undent
mysql_install_db
If this is your first install, automatically load on login with:
- cp #{prefix}/com.mysql.mysqld.plist ~/Library/LaunchAgents
- launchctl load -w ~/Library/LaunchAgents/com.mysql.mysqld.plist
+ cp #{plist_path} ~/Library/LaunchAgents
+ launchctl load -w ~/Library/LaunchAgents/#{plist_path.basename}
- If this is an upgrade and you already have the com.mysql.mysqld.plist loaded:
- launchctl unload -w ~/Library/LaunchAgents/com.mysql.mysqld.plist
- cp #{prefix}/com.mysql.mysqld.plist ~/Library/LaunchAgents
- launchctl load -w ~/Library/LaunchAgents/com.mysql.mysqld.plist
+ If this is an upgrade and you already have the #{plist_path} loaded:
+ launchctl unload -w ~/Library/LaunchAgents/#{plist_path.basename}
+ cp #{plist_path} ~/Library/LaunchAgents
+ launchctl load -w ~/Library/LaunchAgents/#{plist_path.basename}
Note on upgrading:
- We overwrite any existing com.mysql.mysqld.plist in ~/Library/LaunchAgents
+ We overwrite any existing #{plist_path} in ~/Library/LaunchAgents
if we are upgrading because previous versions of this brew created the
plist with a version specific program argument.
@@ -101,7 +101,7 @@ def startup_plist; <<-EOPLIST.undent
<key>KeepAlive</key>
<true/>
<key>Label</key>
- <string>com.mysql.mysqld</string>
+ <string>#{plist_name}</string>
<key>Program</key>
<string>#{HOMEBREW_PREFIX}/bin/mysqld_safe</string>
<key>RunAtLoad</key>
Oops, something went wrong. Retry.

0 comments on commit b5a5217

Please sign in to comment.