Puppet Function: stop_processes

Defined in:
lib/puppet/parser/functions/dynatrace_functions.rb
Function type:
Ruby 3.x API

Overview

stop_processes()Any

Returns:

  • (Any)


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/puppet/parser/functions/dynatrace_functions.rb', line 3

newfunction(:stop_processes, :type => :rvalue) do |args|
  proc_pattern = args[0]
  proc_user = args[1]
  platform_family = args[2]
  timeout = args[4] 
  signal = args[5]
  pids = find_pids(proc_pattern, proc_user, platform_family)
  killed = false
  unless pids.empty?
    Process.kill signal, *pids
    # TODO! when process does not exit anymore exception is thrown Errno::ESRCH No such process
    begin
      Timeout.timeout(timeout, DynatraceTimeout) do
        loop do
          pids = find_pids(proc_pattern, proc_user, platform_family)
          if pids.empty?
            # puts("Process(es) #{pids} terminated")
            killed = true
            break
          end
          # puts("Waiting for process(es) #{pids} to finish")
          sleep 1
        end
      end
    rescue DynatraceTimeout
      raise "Process(es) #{pids} did not stop"
    end
  end
  killed
end