Skip to content

Commit

Permalink
chefctl: pass rerun count down to chef-client via env var
Browse files Browse the repository at this point in the history
Summary:
In order to start properly handling chef 401s, we need to change chefctl to
pass whether chefctl is rerunning the chef client.  Then the chef handlers can
use this information to tell if a rekey event is the normal rekey (and not
report an exception to scuba), or if it has
happened multiple times (in which case an exception should still be reported).

Differential Revision: D63587866

fbshipit-source-id: 9602fbb923c8008e2617d88ecc09bd512bf341f9
  • Loading branch information
joshuamiller01 authored and facebook-github-bot committed Oct 1, 2024
1 parent 023a05a commit f306454
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions chefctl/src/chefctl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ def do_chef_runs
retval = 0
num_tries = 0
loop do
retval = run
retval = run(num_tries)
num_tries += 1

# break if we've already run chef the max number of times
Expand Down Expand Up @@ -1000,7 +1000,6 @@ def get_chef_env
env['PATH'] = Chefctl::Config.path.join(File::PATH_SEPARATOR)
end

Chefctl.logger.info("Running chef-client with the following environment variables: #{env.inspect}")
env
end

Expand Down Expand Up @@ -1059,7 +1058,7 @@ def output_copier_thread
end

# Perform a chef run.
def run
def run(retry_count)
if Chefctl.lib.is_a?(Chefctl::Lib::Windows) &&
Chefctl::Config.windows_subshell
# TODO(yottatsa): this code is deprecated.
Expand All @@ -1082,8 +1081,14 @@ def run
"Redirecting chef-client's output to the shell!",
)
end
chef_env = get_chef_env
if retry_count > 0
Chefctl.logger.warn("This is a rerun attempt, rerun number #{retry_count}")
chef_env['RETRY_COUNT'] = retry_count.to_s
end
Chefctl.logger.info("Running chef-client with the following environment variables: #{chef_env.inspect}")
chef_client_pid = Process.spawn(
get_chef_env,
chef_env,
*get_chef_cmd,
# Chefctl.log_file is set at the bottom of this file by the
# init_logger call which is always passed a file, but just
Expand Down

0 comments on commit f306454

Please sign in to comment.