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.



182
183
184
185
186
187
# File 'lib/synco/scope.rb', line 182

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

Instance Method Details

#groupObject



193
194
195
# File 'lib/synco/scope.rb', line 193

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

#loggerObject



189
190
191
# File 'lib/synco/scope.rb', line 189

def logger
	@logger ||= @script_scope.logger
end

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



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/synco/scope.rb', line 197

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
	
	logger.info("shell") {[command, options]}
	
	options[:out] ||= LogPipe.new(logger)
	options[:err] ||= LogPipe.new(logger, :error)
	
	status = self.group.spawn(*command, **options)
	logger.debug{"Process finished: #{status}."}
	
	options[:out].close
	options[:err].close
	
	unless status.success?
		raise CommandFailure.new(command, status)
	end
end