Skip to content

Commit ce145a0

Browse files
authored
v1.1.4: Full process detection for unsafe_process_list (#62)
* add support for unsafe process arguments * update documentation & changelog for 1.1.4 * bump version to 1.1.4
1 parent fb758b9 commit ce145a0

File tree

6 files changed

+34
-5
lines changed

6 files changed

+34
-5
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## Release 1.1.4
6+
7+
**Improvements**
8+
- Added support for matching against full process arguments for the `patching_as_code::unsafe_process_list`.
9+
510
## Release 1.1.3
611

712
**Bugfixes**

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,14 @@ patching_as_code::unsafe_process_list:
237237

238238
This works on both Linux and Windows, and the matching is done case-insensitive. If one process from the `unsafe_process_list` is found as an active process, patching will be skipped.
239239

240+
If you need to match on a specific process including its arguments, prepend the entry with `{full}`:
241+
```yaml
242+
patching_as_code::unsafe_process_list:
243+
- application1
244+
- '{full} /usr/bin/python3 /usr/bin/networkd-dispatcher --run-startup-triggers'
245+
```
246+
You can have whitespace between `{full}` and the process value for sake of readability, this will be automatically stripped before the matching happens.
247+
240248
### Managing patching over metered links (Windows only)
241249

242250
By default, this module will not perform patching over metered links (e.g. 3G/4G connections). You can control this behavior through the `patch_on_metered_links` parameter. To force patching to occur even over metered links, either define this value in Hiera:

REFERENCE.md

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ List of Chocolatey updates to install on the patch schedule set by `$high_priori
110110
Data type: `Array`
111111

112112
List of processes that will cause patching to be skipped if any of the processes in the list are active on the system.
113+
Prepend an entry with `{full}` to match against the full process arguments.
113114

114115
##### `pre_patch_commands`
115116

lib/facter/patch_unsafe_process_active.rb

+18-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,22 @@
33
Facter.add('patch_unsafe_process_active') do
44
confine { Facter.value(:kernel) == 'windows' || Facter.value(:kernel) == 'Linux' }
55
setcode do
6-
def process_running(processname)
6+
def process_running(processname, full = false)
77
case Facter.value(:kernel)
88
when 'windows'
9-
tasklist = `tasklist`.downcase
9+
if full
10+
tasklist = `wmic path win32_process get Commandline`.downcase
11+
processname = processname[6..-1].strip
12+
else
13+
tasklist = `wmic path win32_process get Caption`.downcase
14+
end
1015
when 'Linux'
11-
tasklist = `ps -A`.downcase
16+
if full
17+
tasklist = `ps -Ao cmd`.downcase
18+
processname = processname[6..-1].strip
19+
else
20+
tasklist = `ps -Ao comm`.downcase
21+
end
1222
end
1323
tasklist.include? processname.downcase
1424
end
@@ -19,7 +29,11 @@ def process_running(processname)
1929
unsafe_processes = File.open(processfile, 'r').read
2030
unsafe_processes.each_line do |line|
2131
next if line.match?(%r{^#|^$})
22-
next if process_running(line.chomp) == false
32+
if line.match?(%r{^{full}})
33+
next if process_running(line.chomp, true) == false
34+
elsif process_running(line.chomp) == false
35+
next
36+
end
2337
result = true
2438
break
2539
end

manifests/init.pp

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
# List of Chocolatey updates to install on the patch schedule set by `$high_priority_patch_group`.
4747
# @param [Array] unsafe_process_list
4848
# List of processes that will cause patching to be skipped if any of the processes in the list are active on the system.
49+
# Prepend an entry with `{full}` to match against the full process arguments.
4950
# @param [Hash] pre_patch_commands
5051
# Hash of command to run before patching
5152
# @option pre_patch_commands [String] :command

metadata.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "puppetlabs-patching_as_code",
3-
"version": "1.1.3",
3+
"version": "1.1.4",
44
"author": "puppetlabs",
55
"summary": "Automated patching through desired state code",
66
"license": "Apache-2.0",

0 commit comments

Comments
 (0)