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

Advertisements

1 Comment

  1. April 8, 2010 at 6:07 pm

    […] found this very usefull blogpost on the net https://rubynyc.wordpress.com/2009/12/24/unicorn-scriptspin/ and modified the script with 2 additional “methods”: status and monitor. (I know […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: