Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Rakefile
- require File.join(File.dirname(__FILE__), 'lib')
- @deploy_to = '/home/igc/repo'
- @servers = [{ :host => '69.56.251.135', :user => 'root', :pass => 'eocewreito'}]
- @mongrel_cluster_path = '/home/igc/cluster.yml'
- namespace :igc do
- task :deploy => [:update, :restart]
- task :update => [:update_code, :database_yml_rename]
- task :update_code do
- run "cd #{@deploy_to}; git pull;"
- end
- task :restart do
- run "mongrel_rails cluster::restart -C #{@mongrel_cluster_path} --clean"
- end
- task :submodules do
- run "cd #{@deploy_to}; git submodule init; git submodule update;"
- end
- task :database_yml_rename do
- run "cp -f #{@deploy_to}/rails/config/database.yml.server #{@deploy_to}/rails/config/database.yml"
- end
- end
- ## lib.rb
- require 'net/ssh'
- def run(cmd)
- @servers.each do |server|
- Net::SSH.start(server[:host], server[:user], :password => server[:pass]) do |ssh|
- channel = ssh.open_channel do |ch|
- puts "execute `#{cmd}`"
- ch.exec cmd do |ch, success|
- raise "could not execute command" unless success
- # "on_data" is called when the process writes something to stdout
- ch.on_data do |c, data|
- puts data
- end
- # "on_extended_data" is called when the process writes something to stderr
- ch.on_extended_data do |c, type, data|
- puts data
- end
- ch.on_close { puts "iGC cmd done!" }
- end
- end
- channel.wait
- end
- end
- end
Add Comment
Please, Sign In to add comment