#!/usr/bin/ruby
HERE = File.dirname(__FILE__)
# A few requires for helpers
require 'rubygems'
require 'uri'
require 'net/http'
# helpers
def check_running(host, title = '')
Proc.new{
begin
Net::HTTP.get(URI.parse('http://' + host))
rescue
puts "#{title} (#{host})".ljust(35) + "OFF"
else
puts "#{title} (#{host})".ljust(35) + "RUNNING"
end
}
end
# commands list
PROJECTS = {
:default => {
:start => "script/server -d",
:stop => "mongrel_rails stop -P tmp/pids/mongrel.pid",
:cleanup => [:stop, "echo 'Deleting tmp/pids/mongrel.pid' && rm tmp/pids/mongrel.pid"],
:restart => [:stop, :start],
:status => check_running('localhost:3000'),
:pull => "git pull origin master",
:push => "git push origin master",
:gs => "git status",
:gpp => [:pull, :push],
:gc => ["git commit -am \":message\"", %w(message)],
:add => "echo 'Adding files to git' && git add .",
:diff => "git diff",
:test => "rake",
:deploy => "cap deploy",
:routes => 'rake routes',
:sc => 'script/console',
:watch => 'tail -f log/development.log'
},
:jaxer => {
:startj => ". /Applications/Aptana_Jaxer/scripts/start.sh",
:starts => "thin -s1 -C thin/development_config.yml --rackup thin/config.ru start",
:stopj => ". /Applications/Aptana_Jaxer/scripts/stop.sh",
:stops => "thin -s1 -C thin/development_config.yml --rackup thin/config.ru stop",
:start => [:startj, :starts],
:stop => [:stops, :stopj],
:restartj => [:stopj, :startj],
:restarts => [:stops, :starts],
:cleanup => :stop,
:sc => :skip,
:routes => :skip,
:status => [check_running('localhost:8081', 'Apache Server'),
check_running('localhost:4567', 'Sinatra Service')],
:watch => 'tail -f log/thin.4567.log'
},
:assets => {
:start => "script/server -p6500 -d",
:status => check_running('localhost:6500')
},
:products => {
:start => "script/server -p6600 -d",
:status => check_running('localhost:6600')
},
:front => {
:start => "script/server -p3000 -d"
},
:docs => {
:start => :skip,
:stop => :skip,
:cleanup => :skip,
:status => :skip,
:test => :skip,
:deploy => :skip,
:routes => :skip,
:sc => :skip,
:watch => :skip
},
:resources => {
:start => :skip,
:stop => :skip,
:cleanup => :skip,
:status => :skip,
:test => :skip,
:routes => :skip,
:sc => :skip,
:watch => :skip
}
}