# File lib/simp/cli/commands/bootstrap.rb, line 260
  def self.ensure_puppet_agent_stopped
    agent_run_lockfile = ::Utils.puppet_info[:config]['agent_catalog_run_lockfile']
    if @kill_agent
      info('Killing puppet agents', 'cyan')
      execute("pkill -9 -f 'puppet agent' >& /dev/null")
      execute('puppet resource service puppet ensure=stopped >& /dev/null')
      FileUtils.rm_f(agent_run_lockfile)
      info('Successfully removed agent lock file #{agent_run_lockfile}', 'green')
    else
      run_locked = File.exists?(agent_run_lockfile)
      # TODO: make the following spinner a function; it's used in ensure_puppetserver_running as well.
      if run_locked
        info("Detected puppet agent run lockfile #{agent_run_lockfile}", 'magenta')
        info('Waiting for agent run to complete', 'cyan')
        info('  If you wish to forcibly kill a running agent during bootstrap, re-run with --kill_agent')
        info('  Otherwise, you can wait for the lock to release or manually stop the running agent')
        stages = ["\\",'|','/','-']
        rest = 0.1
        while run_locked do
          run_locked = File.exists?(agent_run_lockfile)
          stages.each{ |x|
            $stdout.flush
            print "> #{x}\r"
            sleep(rest)
          }
        end
        $stdout.flush
      else
        debug('Did not detect a running puppet agent')
      end
    end

    # Now, disable non-bootstrap agent runs
    # Don't need to re-enable agents, puppetagent_cron will do that
    execute('puppet agent --disable Bootstrap')
    info('Successfully disabled non-bootstrap puppet agent', 'green')
  end