Skip to content

Commit ec2f330

Browse files
authored
Merge pull request #274 from rwaffen/deb_timeout
feat: set timeout for apt like with dnf and zypper
2 parents 9aded79 + f9a3723 commit ec2f330

3 files changed

Lines changed: 9 additions & 13 deletions

File tree

REFERENCE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ Should the server reboot after patching has been applied? (Defaults to 'never')
359359

360360
##### `timeout`
361361

362-
Data type: `Optional[Integer]`
362+
Data type: `Integer`
363363

364364
How many seconds should we wait until timing out the patch run? (Defaults to 3600 seconds)
365365

tasks/patch_server.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
},
2020
"timeout": {
2121
"description": "How many seconds should we wait until timing out the patch run? (Defaults to 3600 seconds)",
22-
"type": "Optional[Integer]"
22+
"type": "Integer",
23+
"default": 3600
2324
},
2425
"security_only": {
2526
"description": "Limit patches to those tagged as security related? (Defaults to false)",

tasks/patch_server.rb

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -429,14 +429,11 @@ def gather_facts(log, starttime)
429429
err('110', 'os_patching/zypper_params', 'Unsafe content in zypper_params', starttime)
430430
end
431431
# Set the timeout for the patch run
432-
if params['timeout']
433-
if params['timeout'] > 0
434-
timeout = params['timeout']
435-
else
436-
err('121', 'os_patching/timeout', "timeout set to #{timeout} seconds - invalid", starttime)
437-
end
432+
433+
if params['timeout'].positive?
434+
timeout = params['timeout']
438435
else
439-
timeout = 3600
436+
err('121', 'os_patching/timeout', "timeout set to #{timeout} seconds - invalid", starttime)
440437
end
441438

442439
# Is the patching blocker flag set?
@@ -573,8 +570,6 @@ def gather_facts(log, starttime)
573570
log.info 'Patching complete'
574571
elsif os['family'] == 'Debian'
575572
# Are we doing security only patching?
576-
apt_mode = ''
577-
pkg_list = []
578573
if security_only == true
579574
pkg_list = os_patching['security_package_updates']
580575
apt_mode = 'install ' + pkg_list.join(' ')
@@ -587,8 +582,8 @@ def gather_facts(log, starttime)
587582
log.debug "Running apt #{apt_mode}"
588583
deb_front = 'DEBIAN_FRONTEND=noninteractive'
589584
deb_opts = '-o Apt::Get::Purge=false -o Dpkg::Options::=--force-confold -o Dpkg::Options::=--force-confdef --no-install-recommends'
590-
apt_std_out, stderr, status = Open3.capture3("#{deb_front} apt-get #{dpkg_params} -y #{deb_opts} #{apt_mode}")
591-
err(status, 'os_patching/apt', stderr, starttime) if status != 0
585+
apt_std_out, status = run_with_timeout("#{deb_front} apt-get #{dpkg_params} -y #{deb_opts} #{apt_mode}", timeout, 2)
586+
err(status, 'os_patching/apt', apt_std_out, starttime) if status != 0
592587

593588
output('Success', reboot, security_only, 'Patching complete', pkg_list, apt_std_out, '', pinned_pkgs, starttime, log)
594589
log.info 'Patching complete'

0 commit comments

Comments
 (0)