Class: Rubble::Executor::Remote
- Inherits:
-
Base
- Object
- Base
- Rubble::Executor::Remote
show all
- Defined in:
- lib/rubble/executor/remote.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Base
#convert_options, #exec, #redirect, #rsync, #rsync_includes
Constructor Details
#initialize(server, local_executor) ⇒ Remote
Returns a new instance of Remote.
13
14
15
16
17
18
19
|
# File 'lib/rubble/executor/remote.rb', line 13
def initialize(server, local_executor)
super()
@server = server
@local_executor = local_executor
@box = Rye::Box.new(server.name, :safe => false)
end
|
Instance Attribute Details
#box ⇒ Object
Returns the value of attribute box.
9
10
11
|
# File 'lib/rubble/executor/remote.rb', line 9
def box
@box
end
|
#local_executor ⇒ Object
Returns the value of attribute local_executor.
11
12
13
|
# File 'lib/rubble/executor/remote.rb', line 11
def local_executor
@local_executor
end
|
#server ⇒ Object
Returns the value of attribute server.
10
11
12
|
# File 'lib/rubble/executor/remote.rb', line 10
def server
@server
end
|
Instance Method Details
#cd(directory, create) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/rubble/executor/remote.rb', line 34
def cd(directory, create)
@log.info("Changing directory to #{directory}.")
if create then
mkdir directory
end
box.cd(directory.to_s)
end
|
#close ⇒ Object
55
56
57
58
59
|
# File 'lib/rubble/executor/remote.rb', line 55
def close
if not @box.nil? then
@box.disconnect
end
end
|
#file_exists?(file_name) ⇒ Boolean
25
26
27
|
# File 'lib/rubble/executor/remote.rb', line 25
def file_exists?(file_name)
box.file_exists?(file_name)
end
|
#mkdir(directory) ⇒ Object
29
30
31
32
|
# File 'lib/rubble/executor/remote.rb', line 29
def mkdir(directory)
@log.info("Creating directory '#{directory}'.")
exec('mkdir', '-p', directory.to_s)
end
|
#rsync_remote_prefix ⇒ Object
21
22
23
|
# File 'lib/rubble/executor/remote.rb', line 21
def rsync_remote_prefix
"#{server.name}:"
end
|
#run(*command) ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/rubble/executor/remote.rb', line 47
def run(*command)
Logging.context(:server => server.name) do
command_str = Shellwords.join(command)
@log.debug(command_str)
box.execute(command_str)
end
end
|
#symlink(source, target) ⇒ Object
42
43
44
45
|
# File 'lib/rubble/executor/remote.rb', line 42
def symlink(source, target)
@log.info("Symlinking #{source} to #{target}.")
run('ln', '-s', '-f', '-T', source.to_s, target.to_s)
end
|
#sync_down(filesets, target_dir, *options) ⇒ Object
68
69
70
71
72
73
|
# File 'lib/rubble/executor/remote.rb', line 68
def sync_down(filesets, target_dir, *options)
files = rsync_includes(filesets).map {|f| rsync_remote_prefix + f}
parameters = [target_dir].concat(files)
parameters.concat(options)
@local_executor.rsync *parameters
end
|
#sync_remote(source_dir, target_dir, *options) ⇒ Object
75
76
77
78
|
# File 'lib/rubble/executor/remote.rb', line 75
def sync_remote(source_dir, target_dir, *options)
parameters = [source_dir, target_dir, *options]
rsync *parameters
end
|
#sync_up(filesets, target_dir, *options) ⇒ Object
61
62
63
64
65
66
|
# File 'lib/rubble/executor/remote.rb', line 61
def sync_up(filesets, target_dir, *options)
includes = rsync_includes(filesets)
parameters = includes.dirs.dup << (rsync_remote_prefix + target_dir).to_s
@local_executor.rsync(*parameters, :includes => includes.files, :recursive => true, :delete => true,
:delete_excluded => true)
end
|