Puppet Plan: cd4peadm::ctl

Defined in:
plans/ctl.pp

Summary

Run systemctl subcommands for the specified service

Overview

Parameters:

  • service (Optional[Enum['pipelinesinfra', 'query', 'ui', 'postgres', 'all']]) (defaults to: 'all')

    The name of the target service

  • action (Optional[Enum['status', 'start', 'stop', 'restart']]) (defaults to: 'status')

    What action to perform on the service



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
33
34
35
36
37
38
39
40
41
42
43
44
# File 'plans/ctl.pp', line 5

plan cd4peadm::ctl(
  Optional[Enum['status', 'start', 'stop', 'restart']] $action = 'status',
  Optional[Enum['pipelinesinfra', 'query', 'ui', 'postgres', 'all']] $service = 'all',
) {
  $config = cd4peadm::config()
  $opts = { '_run_as' => 'root', '_catch_errors' => true, }

  $roles = $config['roles']
  $role_map = {
    'pipelinesinfra' => 'backend',
    'query'          => 'backend',
    'postgres'       => 'database',
    'ui'             => 'ui',
  }

  $services = $service ? {
    'all'   => ['pipelinesinfra', 'query', 'ui', 'postgres'],
    default => [$service],
  }

  $services.each |$svc| {
    $results = run_command("systemctl ${action} ${config['runtime']}-${svc}",
      $roles[$role_map[$svc]]['targets'],
      $opts)

    $results.each |$result| {
      if(!$result['stdout'].empty) {
        out::message("Result from ${result.target}")
        out::message($result['stdout'])
      }
      if(!$result.ok) {
        out::message($result['stderr'])
      }
    }
  }

  if($service == 'all' and $action in ['start', 'restart']) {
    run_plan('cd4peadm::install::wait_for_services', config => $config)
  }
}