Skip to content

Instantly share code, notes, and snippets.

@liudangyi
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liudangyi/52f12250b5dfcd1630e5 to your computer and use it in GitHub Desktop.
Save liudangyi/52f12250b5dfcd1630e5 to your computer and use it in GitHub Desktop.
Homebrew launchctl script
#!/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
#!/usr/bin/env ruby
load File.expand_path('../brew-launch', __FILE__)
(ARGV.empty? ? DEFAULT : ARGV).each {|a| start(a)}
#!/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