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



173
174
175
176
177
178
# File 'lib/synco/scope.rb', line 173

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

Instance Method Details

#groupObject



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

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

#loggerObject



180
181
182
# File 'lib/synco/scope.rb', line 180

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

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



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/synco/scope.rb', line 188

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