Guest User

Untitled

a guest
Apr 27th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. ## Rakefile
  2.  
  3. require File.join(File.dirname(__FILE__), 'lib')
  4.  
  5. @deploy_to = '/home/igc/repo'
  6. @servers = [{ :host => '69.56.251.135', :user => 'root', :pass => 'eocewreito'}]
  7. @mongrel_cluster_path = '/home/igc/cluster.yml'
  8.  
  9. namespace :igc do
  10. task :deploy => [:update, :restart]
  11.  
  12. task :update => [:update_code, :database_yml_rename]
  13.  
  14. task :update_code do
  15. run "cd #{@deploy_to}; git pull;"
  16. end
  17.  
  18. task :restart do
  19. run "mongrel_rails cluster::restart -C #{@mongrel_cluster_path} --clean"
  20. end
  21.  
  22. task :submodules do
  23. run "cd #{@deploy_to}; git submodule init; git submodule update;"
  24. end
  25.  
  26. task :database_yml_rename do
  27. run "cp -f #{@deploy_to}/rails/config/database.yml.server #{@deploy_to}/rails/config/database.yml"
  28. end
  29. end
  30.  
  31. ## lib.rb
  32.  
  33. require 'net/ssh'
  34.  
  35. def run(cmd)
  36. @servers.each do |server|
  37. Net::SSH.start(server[:host], server[:user], :password => server[:pass]) do |ssh|
  38. channel = ssh.open_channel do |ch|
  39. puts "execute `#{cmd}`"
  40. ch.exec cmd do |ch, success|
  41. raise "could not execute command" unless success
  42.  
  43. # "on_data" is called when the process writes something to stdout
  44. ch.on_data do |c, data|
  45. puts data
  46. end
  47.  
  48. # "on_extended_data" is called when the process writes something to stderr
  49. ch.on_extended_data do |c, type, data|
  50. puts data
  51. end
  52.  
  53. ch.on_close { puts "iGC cmd done!" }
  54. end
  55. end
  56.  
  57. channel.wait
  58. end
  59. end
  60. end
Add Comment
Please, Sign In to add comment