<commit_before>module Capistrano
  module Puppeteer
    module Bootstrap

      def self.extended(configuration)
        configuration.load do
          set(:bootstrap_domain) { abort "Please specify a domain, set :bootstrap_domain, 'inodes.org'" } unless exists? :bootstrap_domain
          set(:bootstrap_user)   { abort "Please specify a user, set :bootstrap_user, 'johnf'" } unless exists? :bootstrap_domain
          set(:puppet_path)      { abort "Please specify the path to puppet, set :puppet_path, '/srv/puppet'" } unless exists? :puppet_path
          set(:puppet_repo)      { abort "Please specify the path to puppet, set :puppet_reop, 'git@...'" } unless exists? :puppet_repo

          namespace :bootstrap do

            desc 'Create and bootstrap the server'
            task :create do
              puts "NOTE: Add host to puppet first and git push"
              puts
              sleep 5

              name = ENV['name'] or abort('please supply a name')
              ENV['FQDN'] ||= "#{name}.#{bootstrap_domain}"
              aws.create
              sleep 20 # Give SSH time to come up
              bootstrap.go
            end

            desc 'Bootstrap the server with puppet'
            task :go do
              if exists? :ssh_key
                system "ssh-add #{ssh_key}"
              end
              hostname
              github
              upgrade
              puppet_setup
              unless ENV['skip_puppet']
                puppet_ubuntu if exists?(:cloud_provider) && cloud_provider == 'AWS'
                puppet.go
              end
            end

            task :hostname do
              set :user, 'ubuntu' if exists?(:cloud_provider) && cloud_provider == 'AWS'
              fqdn = ENV['fqdn'] || Capistrano::CLI.ui.ask('What is the full fqdn for the host')
              hostname = fqdn.split('.')[0]

              run "#{sudo} sudo sed -i -e '/127.0.0.1/a127.0.1.1 #{fqdn} #{hostname}' /etc/hosts"
              run "echo #{hostname} | #{sudo} tee /etc/hostname > /dev/null"<commit_msg>Actually wait for SSH to be ready rather than just sleeping<commit_after>require 'socket'
require 'timeout'

module Capistrano
  module Puppeteer
    module Bootstrap

      def self.extended(configuration)
        configuration.load do
          set(:bootstrap_domain) { abort "Please specify a domain, set :bootstrap_domain, 'inodes.org'" } unless exists? :bootstrap_domain
          set(:bootstrap_user)   { abort "Please specify a user, set :bootstrap_user, 'johnf'" } unless exists? :bootstrap_domain
          set(:puppet_path)      { abort "Please specify the path to puppet, set :puppet_path, '/srv/puppet'" } unless exists? :puppet_path
          set(:puppet_repo)      { abort "Please specify the path to puppet, set :puppet_reop, 'git@...'" } unless exists? :puppet_repo

          namespace :bootstrap do

            desc 'Create and bootstrap the server'
            task :create do
              puts "NOTE: Add host to puppet first and git push"
              puts
              sleep 5

              name = ENV['name'] or abort('please supply a name')
              ENV['fqdn'] ||= "#{name}.#{bootstrap_domain}"
              aws.create
              unless wait_for_ssh
                abort "Timed out waiting for SSH to come up on #{ENV['HOSTS']}"
              end
              bootstrap.go
            end

            def wait_for_ssh
              60.times do
                begin
                  Timeout::timeout(1) do
                    s = TCPSocket.new(ENV['HOSTS'], 22)
                    s.close
                    return true
                  end
                rescue Timeout::Error, Errno::ECONNREFUSED, Errno::EHOSTUNREACH
                end
              end

              return false
            end

            desc 'Bootstrap the server with puppet'
            task :go do
              if exists? :ssh_key
                system "ssh-add #{ssh_key}"
              end
              hostname
              github
              upgrade
              puppet_setup
              unless ENV['skip_puppet']
                puppet_ubuntu if exists?(:cloud_provider) && cloud_provider == 'AWS'
                puppet.go
              end
            end

            task :hostname do
              set :user, 'ubuntu' if exists?(:cloud_provider) && cloud_provider == 'AWS'
              fqdn = ENV['fqdn'] || Capistrano::CLI.ui.ask('What is the full fqdn for the host')
              hostname = fqdn.split('.')[0]

              run "#{sudo} sudo sed -i -e '/127.0.0.1/a127.0.1.1 #{fqdn} #{hostname}' /etc/hosts"
              run "echo #{hostname} | #{sudo} tee /etc/hostname > /dev/null"
{'fraction_non_alphanumeric': 0.09660908509277032, 'fraction_numerical': 0.007464278097675411, 'mean_word_length': 1.6407657657657657, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3295907', 'n_tokens_mistral': 1354, 'n_tokens_neox': 1273, 'n_words': 394}