def run(options)
      configure_logging

      case options[:action]
        when :attach
          # resolve cloud name.
          cloud_file = RightScale::AgentConfig.cloud_file_path
          cloud_name = options[:cloud]
          if cloud_name.nil? && File.file?(cloud_file)
            cloud_name = File.read(cloud_file).strip
          end
          cloud_name = 'none' if cloud_name.to_s.empty?

          cloud_dir   = File.dirname(cloud_file)
          output_file = File.join(RightScale::Platform.filesystem.spool_dir, 'rightscale', 'user-data.txt')
          output_dir  = File.dirname(output_file)

          if File.exist?(InstanceState::STATE_FILE) && !options[:force]
            puts "It appears this system is already managed by RightScale; cannot continue"
            puts
            puts "To override this decision, use the --force option. Please make sure you"
            puts "know what you are doing! Connecting this system to a server when it is"
            puts "already connected to another server could cause unexpected behavior in"
            puts "the RightScale dashboard, and in certain cases, data loss!"
            exit(-1)
          end

          puts "Fetching launch settings from RightScale"
          url  = options[:url]
          data = http_get(url, false)

          unless data =~ /RS_rn_id/i
            Log.error("Malformed launch settings: #{data}")
            raise MalformedResponse, "Launch settings do not look well-formed; did you specify the right URL?"
          end

          puts "Creating cloud-family hint file (#{cloud_file})"
          FileUtils.mkdir_p(cloud_dir)
          File.open(cloud_file, 'w') do |f|
            f.puts cloud_name
          end

          puts "Writing launch settings to file"
          FileUtils.mkdir_p(output_dir)
          File.open(output_file, 'w') do |f|
            f.puts data
          end

          puts "Done connecting server to RightScale. Will now attempt to start the RightLink services."
          puts "If starting of services fails, you can attempt to start them by rebooting."
          if RightScale::Platform.windows?
            puts `net start rightscale`
            exit $?.exitstatus unless $?.success?
          elsif RightScale::Platform.linux? || RightScale::Platform.darwin?
            puts `/etc/init.d/rightscale start && /etc/init.d/rightlink start`
            exit $?.exitstatus unless $?.success?
          else
            raise UnsupportedPlatform, "Starting services is not supported for this platform."
          end
          exit
        else
          puts Usage.scan(__FILE__)
          exit
      end
    rescue SystemExit => e
      raise e
    rescue Exception => e
      fail(e)
    end
def run(options)
      configure_logging

      case options[:action]
        when :attach
          # resolve cloud name.
          cloud_file = RightScale::AgentConfig.cloud_file_path
          cloud_name = options[:cloud]
          if cloud_name.nil? && File.file?(cloud_file)
            cloud_name = File.read(cloud_file).strip
          end
          cloud_name = 'none' if cloud_name.to_s.empty?

          cloud_dir   = File.dirname(cloud_file)
          output_file = File.join(RightScale::Platform.filesystem.spool_dir, 'rightscale', 'user-data.txt')
          output_dir  = File.dirname(output_file)

          if File.exist?(InstanceState::STATE_FILE) && !options[:force]
            puts "It appears this system is already managed by RightScale; cannot continue"
            puts
            puts "To override this decision, use the --force option. Please make sure you"
            puts "know what you are doing! Connecting this system to a server when it is"
            puts "already connected to another server could cause unexpected behavior in"
            puts "the RightScale dashboard, and in certain cases, data loss!"
            exit(-1)
          end

          puts "Fetching launch settings from RightScale"
          url  = options[:url]
          data = http_get(url, false)

          unless data =~ /RS_rn_id/i
            Log.error("Malformed launch settings: #{data}")
            raise MalformedResponse, "Launch settings do not look well-formed; did you specify the right URL?"
          end

          puts "Creating cloud-family hint file (#{cloud_file})"
          FileUtils.mkdir_p(cloud_dir)
          File.open(cloud_file, 'w') do |f|
            f.puts cloud_name
          end

          puts "Writing launch settings to file"
          FileUtils.mkdir_p(output_dir)
          File.open(output_file, 'w') do |f|
            f.puts data
          end

          puts "Done connecting server to RightScale. Will now attempt to start the RightLink services."
          puts "If starting of services fails, you can attempt to start them by rebooting."
          if RightScale::Platform.windows?
            puts `net start rightscale`
            exit $?.exitstatus unless $?.success?
          elsif RightScale::Platform.linux? || RightScale::Platform.darwin?
            puts `/etc/init.d/rightscale start && /etc/init.d/rightlink start`
            exit $?.exitstatus unless $?.success?
          else
            raise UnsupportedPlatform, "Starting services is not supported for this platform."
          end
          exit
        else
          puts Usage.scan(__FILE__)
          exit
      end
    rescue SystemExit => e
      raise e
    rescue Exception => e
      fail(e)
    end
Run

 === Parameters
 options(Hash):: Hash of options as defined in +parse_args+

 === Return
 true:: Always return true