Class: Synco::ServerScope

Inherits:
Server show all
Defined in:
lib/synco/scope.rb

Instance Attribute Summary

Attributes inherited from Server

#host, #mountpoint, #name, #root, #shell

Attributes inherited from Controller

#events

Instance Method Summary collapse

Methods inherited from Server

#connection_command, #connection_string, #full_path, #same_host?, #to_s

Methods inherited from Controller

#abort!, build, #fire, #freeze, #on, #try

Constructor Details

#initialize(server, script_scope, from = nil) ⇒ ServerScope

Returns a new instance of ServerScope.



150
151
152
153
154
155
# File 'lib/synco/scope.rb', line 150

def initialize(server, script_scope, from = nil)
	super(server)
	
	@script_scope = script_scope
	@from = from
end

Instance Method Details

#groupObject



157
158
159
# File 'lib/synco/scope.rb', line 157

def group
	@group ||= @script_scope.group
end

#run(*command, from: @from, **options) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/synco/scope.rb', line 161

def run(*command, from: @from, **options)
	# We are invoking a command from the given server, so we need to use the shell to connect..
	if from and !from.same_host?(self)
		if chdir = options.delete(:chdir)
			command = ["synco", "--root", chdir, "spawn"] + command
		end
		
		command = self.connection_command + ["--"] + command
	end
	
	Console::Event::Spawn.for(*command, **options).emit(self)
	
	options[:out] ||= LogPipe.new
	options[:err] ||= LogPipe.new(level: :error)
	
	status = self.group.spawn(*command, **options)
	
	Console.info(self, "Command completed.", status: status)
	
	options[:out].close
	options[:err].close
	
	unless status.success?
		raise CommandFailure.new(command, status)
	end
end