# File lib/simp/cli/commands/bootstrap.rb, line 77
  def self.run(args = [])
    super
    return if @help_requested

    check_for_start_lock
    set_up_simp_environment

    # Open log file
    logfilepath = File.dirname(File.expand_path(@bootstrap_log))
    FileUtils.mkpath(logfilepath) unless File.exists?(logfilepath)
    @logfile = File.open(@bootstrap_log, 'w')
    FileUtils.mkdir(@bootstrap_backup)

    # Print intro
    system('clear')
    info('=== Starting SIMP Bootstrap ===', 'yellow.bold', '')
    info("The log can be found at '#{@logfile.path}'\n")

    ensure_puppet_agent_stopped

    if @unsafe
      warn('Any interrupts may cause system instability.', 'red.bold')
    else
      # From this point on, capture interrupts
      signals = ['INT','HUP','USR1','USR2']
      signals.each do |sig|
        Signal.trap(sig) { say "\nSafe mode enabled, ignoring interrupt".magenta }
      end
      info('Interrupts will be captured and ignored to ensure bootstrap integrity.', 'magenta.bold')
    end

    ensure_puppet_processes_stopped
    handle_existing_puppet_certs
    configure_bootstrap_puppetserver

    # - Firstrun is tagged and run against the bootstrap puppetserver port, 8150.
    #   This run will configure puppetserver and puppetdb; all subsequent runs
    #   will run against the configured masterport.
    # - Create a unique lockfile, we want to preserve the lock on cron and manual
    #   puppet runs during bootstrap.
    agent_lockfile = "#{File.dirname(::Utils.puppet_info[:config]['agent_disabled_lockfile'])}/bootstrap.lock"
    pupcmd = "puppet agent --onetime --no-daemonize --no-show_diff --verbose" +
      " --no-splay --agent_disabled_lockfile=#{agent_lockfile}" +
      " --masterport=8150 --ca_port=8150"

    info('Running puppet agent, with --tags pupmod,simp', 'cyan')

    # Firstrun is tagged and run against the bootstrap puppetserver port, 8150.
    linecounts = Array.new
    linecounts << track_output("#{pupcmd} --tags pupmod,simp 2> /dev/null", '8150')

    fix_file_contexts

    # SIMP is not single-run idempotent.  Until it is, run puppet twice.
    info('Running puppet without tags', 'cyan')
    pupcmd = "puppet agent --onetime --no-daemonize --no-show_diff --verbose --no-splay" +
      " --agent_disabled_lockfile=#{agent_lockfile}"
    # This is fugly, but until we devise an intelligent way to determine when your system
    # is 'bootstrapped', we're going to run puppet in a loop.
    (0..1).each do
      track_output(pupcmd)
    end

    ensure_bootstrap_puppetserver_process_stopped

    # Print closing banner
    info('=== SIMP Bootstrap Finished! ===', 'yellow', '')
    info("Duration of complete bootstrap: #{Time.now - @start_time} seconds")
    if !system('ps -C httpd > /dev/null 2>&1') && (linecounts.include?(-1) || (linecounts.uniq.length < linecounts.length))
      warn('Warning: Primitive checks indicate there may have been issues', 'magenta')
    end
    info("#{@logfile.path} contains details of the bootstrap actions performed.", 'yellow')
    info('Prior to operation, you must reboot your system.', 'magenta.bold')
    info('Run `puppet agent -t` after reboot to complete the bootstrap process.', 'magenta.bold')
    info('It may take a few minutes before the puppetserver accepts agent', 'magenta.bold')
    info('connections after boot.', 'magenta.bold')

    # Re-enable the non-bootstrap puppet agent
    execute('puppet agent --enable')
  end