Last active
August 29, 2015 14:03
-
-
Save liudangyi/52f12250b5dfcd1630e5 to your computer and use it in GitHub Desktop.
Homebrew launchctl script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
DEFAULT = %w(mongodb memcached) | |
RUNNING = `launchctl list | grep homebrew.mxcl`.split.select{|s|s.sub!(/\Ahomebrew\.mxcl\./, "")} | |
BREW_PATH = `brew --prefix`.chomp | |
AVAILABLE = Dir.new("#{BREW_PATH}/opt").select{|name|File.exists?("#{BREW_PATH}/opt/#{name}/homebrew.mxcl.#{name}.plist")} | |
def start(app) | |
if AVAILABLE.include? app | |
if RUNNING.include? app | |
puts "#{app} is already running!" | |
else | |
print "Starting #{app}... " | |
`launchctl load #{BREW_PATH}/opt/#{app}/homebrew.mxcl.#{app}.plist` | |
puts "Success!" if $?.exitstatus == 0 | |
end | |
else | |
puts "Do not know #{app}." | |
end | |
end | |
def stop(app) | |
if AVAILABLE.include? app | |
if not RUNNING.include? app | |
puts "#{app} is not running!" | |
else | |
print "Stopping #{app}... " | |
`launchctl unload #{BREW_PATH}/opt/#{app}/homebrew.mxcl.#{app}.plist` | |
puts "Success!" if $?.exitstatus == 0 | |
end | |
else | |
puts "Do not know #{app}." | |
end | |
end | |
if $0 == __FILE__ | |
AVAILABLE.each do |name| | |
print (RUNNING.include? name) ? " [\e[32m✔\e[0m] " : " [\e[31m✘\e[0m] " | |
puts name | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
load File.expand_path('../brew-launch', __FILE__) | |
(ARGV.empty? ? DEFAULT : ARGV).each {|a| start(a)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
load File.expand_path('../brew-launch', __FILE__) | |
(ARGV.empty? ? DEFAULT : ARGV).each {|a| stop(a)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment