Class: RemoteRun::Host

Inherits:
Object
  • Object
show all
Defined in:
lib/remote_run/host.rb

Defined Under Namespace

Classes: LockFile

Constant Summary collapse

FAIL =
1
PASS =
0

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#configurationObject (readonly)

Returns the value of attribute configuration.



5
6
7
# File 'lib/remote_run/host.rb', line 5

def configuration
  @configuration
end

#hostnameObject (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_codebaseObject



29
30
31
32
33
34
35
36
37
# File 'lib/remote_run/host.rb', line 29

def copy_codebase
  system("ssh #{configuration.ssh_options} #{ssh_host_and_user} 'mkdir -p #{$runner.remote_path}'")
  excludes = $runner.exclude.map { |dir| "--exclude '#{dir}'"}
  if system(%{rsync #{configuration.rsync_options} --delete-excluded #{excludes.join(" ")} #{$runner.temp_path}/ #{ssh_host_and_user}:#{$runner.remote_path}/})
    return true
  else
    return false
  end
end

#is_up?Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
46
# File 'lib/remote_run/host.rb', line 39

def is_up?
  result = `ssh #{configuration.ssh_options} #{ssh_host_and_user} "echo 'success'" 2>/dev/null`.strip
  if result == "success"
    return true
  else
    return false
  end
end

#lockObject



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_options} #{ssh_host_and_user} 'cd #{$runner.remote_path}; #{task}' 2>&1}
  system(command)
  $?.exitstatus
end

#start_ssh_master_connectionObject



48
49
50
51
52
# File 'lib/remote_run/host.rb', line 48

def start_ssh_master_connection
  fork do
    system("ssh #{configuration.ssh_options} #{ssh_host_and_user} -M &> /dev/null")
  end
end

#unlockObject



19
20
21
# File 'lib/remote_run/host.rb', line 19

def unlock
  @lock_file.release
end