Sha256: 926196bd115f5b8cd499c8ea7b1375f59854645413bccdf6f0245be18fc43f09

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

module Utils

  def exec_remotely_in_dir(dir, command, announcement = nil)
    if announcement.present?
      exec_remotely("cd #{dir} && #{command}", announcement)
    else
      exec_remotely("cd #{dir} && #{command}")
    end
  end

  def exec_remotely(command, announcement = nil)

    remote_command = "ssh -t #{CONFIG['remote_username']}@#{CONFIG['target_server']} '#{command}'"

    puts ''
    
    print_to_console('', announcement) if announcement.present?

    print_to_console( "/-----<", "Executing: #{remote_command}" )

    Open3.popen2e(remote_command) do |stdin, standard_out_and_standard_err_combined, process_status|
      
      while line = standard_out_and_standard_err_combined.gets
        print_to_console("|      ", line)
      end

      exit_status = process_status.value

      unless exit_status.success?
        abort "\\-----> Error executing #{remote_command}"
      end

      print_to_console('\----->', process_status.value.inspect)

    end

  end

  def print_to_console(padding = '', message = '')

    puts sprintf( '%9s %s', padding, message )

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
depkit-0.0.0.pre1 lib/depkit/utilities.rb