Unicorn Script/Spin

#!/usr/bin/env ruby

UNICORN_RAILS=”/var/www/apps/ruby/bin/unicorn_rails”.freeze
APP_PATH=”/var/www/apps/jjsingh/current/”.freeze

class Runner
class << self

def start
system "#{UNICORN_RAILS} -c #{APP_PATH}/config/unicorn.rb -E production -D"
end

def reload
system "kill -s USR2 #{pid}"
end

def restart
stop
start
end

def graceful_stop
system "kill -s QUIT #{pid}"
end

def stop
system "kill #{pid}"
end

def pid
File.read "#{APP_PATH}/tmp/pids/unicorn.pid"
end

end
end

case ARGV[0]
when "start"
Runner.start
when "reload"
Runner.reload
when "restart"
Runner.restart
when "stop"
Runner.stop
else
STDERR.puts "usage ./script/spin [start|stop|restart]"
exit(1)
end

Follow

Get every new post delivered to your Inbox.