class RemotesCommand

Constants

MAGIC_RC
ONE_LOCATION
REMOTES_LOCATION

Public Class Methods

run(command, host, remote_dir, logger=nil, stdin=nil, retries=0, timeout=nil) click to toggle source

Creates a command and runs it

# File lib/CommandManager.rb, line 250
def self.run(command, host, remote_dir, logger=nil, stdin=nil, retries=0, timeout=nil)
    cmd_file = command.split(' ')[0]

    cmd_string = "'if [ -x \"#{cmd_file}\" ]; then #{command}; else\
                          exit #{MAGIC_RC}; fi'"

    cmd = self.new(cmd_string, host, logger, stdin, timeout)
    cmd.run

    while cmd.code != 0 and retries != 0
        if cmd.code == MAGIC_RC
            update_remotes(host, remote_dir, logger)
        end

        sleep 1
        cmd.run
        retries = retries - 1
    end

    cmd
end

Private Class Methods

update_remotes(host, remote_dir, logger=nil) click to toggle source
# File lib/CommandManager.rb, line 284
def self.update_remotes(host, remote_dir, logger=nil)
    if logger != nil
        logger.call("Remote worker node files not found")
        logger.call("Updating remotes")
    end

    #recreate remote dir structure
    SSHCommand.run("mkdir -p #{remote_dir}",host,logger)

    # Use SCP to sync:
    sync_cmd = "scp -rp #{REMOTES_LOCATION}/* #{host}:#{remote_dir}"

    # Use rsync to sync:
    # sync_cmd = "rsync -Laz #{REMOTES_LOCATION} #{host}:#{@remote_dir}"
    LocalCommand.run(sync_cmd, logger)
end