File: systemd_units.cf

package info (click to toggle)
cfengine3 3.24.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,552 kB
  • sloc: ansic: 163,161; sh: 10,296; python: 2,950; makefile: 1,744; lex: 784; yacc: 633; perl: 211; pascal: 157; xml: 21; sed: 13
file content (85 lines) | stat: -rw-r--r-- 3,321 bytes parent folder | download | duplicates (2)
1
2
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
bundle agent cfe_internal_systemd_unit_files
# @brief This bundle is responsible for ensuring the systemd units are in place
# with the proper content and permissions. Any time a unit is repaired systemd
# is reloaded and the repaired unit(s) are restarted. the
# cfe_internal_systemd_unit_state bundle is responsible for making sure the
# service units are in the appropriate state. So a service may be restarted
# because of a change, and subsequently stopped if the desired state was for it
# to not be running.
{
  vars:

    systemd::
      "systemctl" string => "/bin/systemctl";

      "unit_dir"
        string => "/etc/systemd/system",
        comment => "This is the directory where the systemd units should be
                    placed.";

      "unit_template_dir"
        string => "$(this.promise_dirname)/../../templates",
        comment => "This is where the templates for the units exist. In the
                    templates dir in the root of masterfiles.";

      "service_units"
        slist => { @(cfe_internal_update_processes.all_agents) },
        handle => "systemd_core_units",
        comment => "These are the services which should have systemd units on all systems.";

  files:

    systemd::

      "$(unit_dir)/$(service_units).service"
        create => "true",
        edit_template => "$(unit_template_dir)/$(service_units).service.mustache",
        template_method => "mustache",
        classes => u_results( "bundle", "cfe_systemd_service_unit_$(service_units)" ),
        perms => u_mog("644", "root", "root"),
        comment => "We need to make each service units content is correct.";

  commands:

    systemd::

      "$(systemctl)"
        args => "daemon-reload --no-ask-password",
        handle => "cfe_internal_systemd_unit_files_reload_when_changed",
        if => classmatch("cfe_systemd_service_unit_.*_repaired"),
        comment => "We need to reload the systemd configuration after any unit
                    is changed in order for systemd to recognize the change.";

      "$(systemctl)"
        args => "restart $(service_units).service --no-ask-password",
        handle => "cfe_internal_systemd_unit_restart_when_changed",
        if => and(classify("cfe_systemd_service_unit_$(service_units)_repaired"),
                  returnszero("$(systemctl) --quiet is-active $(service_units)", noshell)),
        comment => "We need to restart any units which have been changed in
                    order for the new configuration to be in effect. But we only
                    want to restart them if they are currently running.";

}

bundle agent cfe_internal_systemd_service_unit_state
# @brief This bundle is responsible for managing the various cfengine components
# units state. It uses information from
# cfe_internal_update_processes.agents_to_be_enabled,
# cfe_internal_update_processes.agents_to_be_disabled to determine which units
# should be running or not.
{
  vars:

      "enabled" slist => { @(cfe_internal_update_processes.agents_to_be_enabled) };

      "disabled"
        slist => { @(cfe_internal_update_processes.agents_to_be_disabled) };


  methods:
      "Disabled Components"
        usebundle => u_systemd_services( $(disabled), "stop");

      "Enabled Components"
        usebundle => u_systemd_services( $(enabled), "start" );
}