Skip to content

Instantly share code, notes, and snippets.

@chucai
Forked from betamatt/faye.rb
Created July 19, 2012 02:52
Show Gist options
  • Save chucai/3140446 to your computer and use it in GitHub Desktop.
Save chucai/3140446 to your computer and use it in GitHub Desktop.
Faye monit wrapper
#!/usr/env ruby
base_dir = File.expand_path("../..", __FILE__)
NAME="faye"
PID="#{base_dir}/tmp/pids/#{NAME}.pid"
COMMAND="bundle exec rackup -s thin -E production -p 3001 faye.ru"
case ARGV[0]
when "start"
pid = fork do
Dir.chdir(base_dir)
exec *COMMAND.split(' ') # fails for quoted args, obviously
end
Process.detach(pid)
File.open(PID, "w+") do |f|
f.write(pid)
end
when "stop"
Process.kill "TERM", File.read(PID).to_i
else
puts "usage: #{$0} {start|stop}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment