Class: RCS::Deploy::Target
- Inherits:
-
Object
- Object
- RCS::Deploy::Target
- Defined in:
- lib/rcs-common/deploy.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #add_slash(path) ⇒ Object
-
#initialize(params) ⇒ Target
constructor
A new instance of Target.
- #mirror(local_folder, remote_folder, opts = {}) ⇒ Object
- #mirror!(local_folder, remote_folder, opts = {}) ⇒ Object
- #restart_service(name) ⇒ Object
- #run_with_ssh(command, opts = {}) ⇒ Object (also: #run)
- #run_without_ssh(cmd, opts = {}) ⇒ Object
- #transfer(src, remote_folder, opts = {}) ⇒ Object
Constructor Details
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
43 44 45 |
# File 'lib/rcs-common/deploy.rb', line 43 def address @address end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
43 44 45 |
# File 'lib/rcs-common/deploy.rb', line 43 def user @user end |
Instance Method Details
#add_slash(path) ⇒ Object
50 51 52 |
# File 'lib/rcs-common/deploy.rb', line 50 def add_slash(path) path.end_with?('/') ? "#{path}" : "#{path}/" end |
#mirror(local_folder, remote_folder, opts = {}) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rcs-common/deploy.rb', line 67 def mirror(local_folder, remote_folder, opts = {}) opts[:trap] = true result = mirror!(local_folder, remote_folder, opts) changes = result.split("\n")[1..-3].reject { |x| x.empty? } changed = changes.size > 0 && changes != ["./"] if opts[:changes] changed ? result : nil else changed end end |
#mirror!(local_folder, remote_folder, opts = {}) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/rcs-common/deploy.rb', line 60 def mirror!(local_folder, remote_folder, opts = {}) src = add_slash(local_folder) dst = add_slash(remote_folder) run_without_ssh("rsync --delete -vazc \"#{src}\" #{user}@#{address}:\"#{dst}\"", opts) end |
#restart_service(name) ⇒ Object
80 81 82 |
# File 'lib/rcs-common/deploy.rb', line 80 def restart_service(name) run_with_ssh("net stop \"#{name}\"; net start \"#{name}\"") end |
#run_with_ssh(command, opts = {}) ⇒ Object Also known as: run
84 85 86 |
# File 'lib/rcs-common/deploy.rb', line 84 def run_with_ssh(command, opts = {}) run_without_ssh("ssh #{user}@#{address} \""+ command.gsub('"', '\"') +"\"", opts) end |
#run_without_ssh(cmd, opts = {}) ⇒ Object
90 91 92 93 |
# File 'lib/rcs-common/deploy.rb', line 90 def run_without_ssh(cmd, opts = {}) puts "executing: #{cmd}" opts[:trap] ? `#{cmd}` : Kernel.system(cmd) end |
#transfer(src, remote_folder, opts = {}) ⇒ Object
54 55 56 57 58 |
# File 'lib/rcs-common/deploy.rb', line 54 def transfer(src, remote_folder, opts = {}) dst = add_slash(remote_folder) run_without_ssh("rsync -tcv #{src} #{user}@#{address}:\"#{dst}\"", opts) end |