Sha256: dd817e360b14a5e7e434ca8b90056e1c7d234f6ebde2b9e9be761de76f0ccd16

Contents?: true

Size: 1.07 KB

Versions: 4

Compression:

Stored size: 1.07 KB

Contents

require 'linecook/commands/vbox_command'

module Linecook
  module Commands
    
    # :startdoc::desc ssh to a vm
    #
    # Connects to a virtual machine using ssh, as configured in config/ssh.
    # 
    class Ssh < VboxCommand
      undef_config :names
      
      def default_host
        load_hosts(ssh_config_file).collect {|host, vm_name| host }.first
      end
      
      def process(host=default_host)
        if host.to_s.strip.empty?
          raise CommandError.new("no host specified")
        end
        
        ssh = "ssh -F '#{ssh_config_file}' '#{host}' --"

        # Patterned after vagrant/ssh.rb (circa 0.6.6)
        # Some hackery going on here. On Mac OS X Leopard (10.5), exec fails
        # (GH-51). As a workaround, we fork and wait. On all other platforms, we
        # simply exec.

        platform = RUBY_PLATFORM.to_s.downcase
        pid = nil
        pid = fork if platform.include?("darwin9") || platform.include?("darwin8")
        Kernel.exec(ssh)  if pid.nil?
        Process.wait(pid) if pid

        exit $?.exitstatus
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
linecook-1.2.1 lib/linecook/commands/ssh.rb
linecook-1.2.0 lib/linecook/commands/ssh.rb
linecook-1.1.0 lib/linecook/commands/ssh.rb
linecook-1.0.0 lib/linecook/commands/ssh.rb