Skip to content

Instantly share code, notes, and snippets.

@remvee
Created November 23, 2009 09:03
Show Gist options
  • Save remvee/240974 to your computer and use it in GitHub Desktop.
Save remvee/240974 to your computer and use it in GitHub Desktop.
cap avoid too fast restart of mongrel-cluster
namespace :deploy do
task :start, :roles => :app do
sudo "mongrel_rails cluster::start -C #{mongrel_conf}"
end
task :stop, :roles => :app do
sudo "mongrel_rails cluster::stop -C #{mongrel_conf}"
y = {
"port" => 3000, "servers" => 2, "pid_file" => "tmp/pids/mongrel.pid"
}.merge(YAML.load(capture("cat #{mongrel_conf}")))
dir, file, port, servers = %w(cwd pid_file port servers).map{|k| y[k]}
ports = port...(port + servers)
dir = File.join(dir, File.dirname(file))
ext = File.extname(file)
name = File.basename(file, ext)
files = ports.map{|p| File.join(dir, [name, p].join('.') + ext)}
cmd = "test #{files.map{|v| '-f ' + v}.join(' -o ')} || echo t"
sleep 1 until capture(cmd).strip == 't'
end
task :restart, :roles => :app do
find_and_execute_task "deploy:stop"
find_and_execute_task "deploy:start"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment