From 43d30047c5a0cbec78c3dc540035b5b7cc0e361d Mon Sep 17 00:00:00 2001 From: Adam Saponara Date: Fri, 15 Mar 2024 15:16:22 -0400 Subject: [PATCH] BOR-449: fb_apt: Add `apt_update_strace_path` --- cookbooks/fb_apt/README.md | 8 ++++++++ cookbooks/fb_apt/attributes/default.rb | 2 ++ cookbooks/fb_apt/recipes/default.rb | 7 +++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cookbooks/fb_apt/README.md b/cookbooks/fb_apt/README.md index 560f2732..84642e47 100644 --- a/cookbooks/fb_apt/README.md +++ b/cookbooks/fb_apt/README.md @@ -23,6 +23,7 @@ Attributes * node['fb_apt']['preserve_unknown_keyrings'] * node['fb_apt']['allow_modified_pkg_keyrings'] * node['fb_apt']['apt_update_log_path'] +* node['fb_apt']['apt_update_strace_path'] Usage ----- @@ -113,3 +114,10 @@ want to use Chef to upgrade across distros, however, you can set Set `node['fb_apt']['apt_update_log_path']` to log stdout and stderr of the `apt-get update` command invoked by this cookbook. This may be useful for debugging purposes. The caller must handle log rotation. + +Similarly, set `node['fb_apt']['apt_update_strace_path']` to capture strace +output of the `apt-get update` command invoked by this cookbook. This may be +useful for debugging purposes. Set `node['fb_apt']['apt_update_strace_flags']` +to override the default strace flags (`-v -f -yy -Y -ttt -T -s4096 -A`). Note +that by default, the log is appended to on each invocation. The caller must +handle log rotation. diff --git a/cookbooks/fb_apt/attributes/default.rb b/cookbooks/fb_apt/attributes/default.rb index f4f21781..5c977b46 100644 --- a/cookbooks/fb_apt/attributes/default.rb +++ b/cookbooks/fb_apt/attributes/default.rb @@ -39,6 +39,8 @@ 'preserve_unknown_keyrings' => false, 'allow_modified_pkg_keyrings' => false, 'apt_update_log_path' => nil, + 'apt_update_strace_path' => nil, + 'apt_update_strace_flags' => '-v -f -yy -Y -ttt -T -s4096 -A', } # fb_apt must be defined for this to work... keys = FB::Apt.get_official_keyids(node).map { |id| [id, nil] }.to_h diff --git a/cookbooks/fb_apt/recipes/default.rb b/cookbooks/fb_apt/recipes/default.rb index 85f0dbcb..71a7ef87 100644 --- a/cookbooks/fb_apt/recipes/default.rb +++ b/cookbooks/fb_apt/recipes/default.rb @@ -98,8 +98,11 @@ execute 'apt-get update' do command(lazy do log_path = node['fb_apt']['apt_update_log_path'] - cmd_suffix = " >>#{Shellwords.shellescape(log_path)} 2>&1" if log_path - "apt-get update#{cmd_suffix}" + strace_path = node['fb_apt']['apt_update_strace_path'] + strace_flags = node['fb_apt']['apt_update_strace_flags'] + cmd_suffix = " >>#{log_path.shellescape} 2>&1" if log_path + cmd_prefix = "strace #{strace_flags} -o #{strace_path.shellescape} " if strace_path && ::File.exist?('/usr/bin/strace') + "#{cmd_prefix}apt-get update#{cmd_suffix}" end) action :nothing end