Class: RemoteRun::Host
- Inherits:
-
Object
- Object
- RemoteRun::Host
- Defined in:
- lib/remote_run/host.rb
Defined Under Namespace
Classes: LockFile
Constant Summary collapse
- FAIL =
1
- PASS =
0
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
Instance Method Summary collapse
- #copy_codebase ⇒ Object
-
#initialize(hostname, configuration) ⇒ Host
constructor
A new instance of Host.
- #is_up? ⇒ Boolean
- #lock ⇒ Object
- #run(task) ⇒ Object
- #start_ssh_master_connection ⇒ Object
- #unlock ⇒ Object
Constructor Details
#initialize(hostname, configuration) ⇒ Host
Returns a new instance of Host.
7 8 9 10 11 |
# File 'lib/remote_run/host.rb', line 7 def initialize(hostname, configuration) @hostname = hostname @lock_file = LockFile.new(@hostname, $runner.local_hostname, $runner.identifier, configuration) @configuration = configuration end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
5 6 7 |
# File 'lib/remote_run/host.rb', line 5 def configuration @configuration end |
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
5 6 7 |
# File 'lib/remote_run/host.rb', line 5 def hostname @hostname end |
Instance Method Details
#copy_codebase ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/remote_run/host.rb', line 29 def copy_codebase system("ssh #{configuration.} #{ssh_host_and_user} 'mkdir -p #{$runner.remote_path}'") excludes = $runner.exclude.map { |dir| "--exclude '#{dir}'"} if system(%{rsync #{configuration.} --delete-excluded #{excludes.join(" ")} #{$runner.temp_path}/ #{ssh_host_and_user}:#{$runner.remote_path}/}) return true else return false end end |
#is_up? ⇒ Boolean
39 40 41 42 43 44 45 46 |
# File 'lib/remote_run/host.rb', line 39 def is_up? result = `ssh #{configuration.} #{ssh_host_and_user} "echo 'success'" 2>/dev/null`.strip if result == "success" return true else return false end end |
#lock ⇒ Object
13 14 15 16 17 |
# File 'lib/remote_run/host.rb', line 13 def lock unless locked? @lock_file.get && locked_by_me? end end |
#run(task) ⇒ Object
23 24 25 26 27 |
# File 'lib/remote_run/host.rb', line 23 def run(task) command = %Q{ssh #{configuration.} #{ssh_host_and_user} 'cd #{$runner.remote_path}; #{task}' 2>&1} system(command) $?.exitstatus end |
#start_ssh_master_connection ⇒ Object
48 49 50 51 52 |
# File 'lib/remote_run/host.rb', line 48 def start_ssh_master_connection fork do system("ssh #{configuration.} #{ssh_host_and_user} -M &> /dev/null") end end |
#unlock ⇒ Object
19 20 21 |
# File 'lib/remote_run/host.rb', line 19 def unlock @lock_file.release end |