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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
bundle agent cfe_internal_core_main
{
methods:
!mpf_auto_am_policy_hub_state_disabled::
"Verify policy hub state" -> { "CFE-3073" }
usebundle => mpf_auto_am_policy_hub_state,
if => not( fileexists( "$(sys.statedir)/am_policy_hub" ));
any::
# NB! On a container host this may kill CFEngine processes inside containers.
# See https://dev.cfengine.com/issues/6906
!mpf_disable_cfe_internal_limit_robot_agents::
"Limit concurrent agents" -> { "CFE-1799" }
usebundle => cfe_internal_limit_robot_agents,
handle => "cfe_internal_management_limit_cfe_agents",
comment => "Manage CFE processes";
any::
"any"
usebundle => cfe_internal_log_rotation,
handle => "cfe_internal_management_log_rotation",
comment => "Rotate CFEngine logs so we don't fill the disk";
cfe_internal_core_watchdog_disabled::
"Disable Core Watchdog"
usebundle => cfe_internal_core_watchdog("disabled");
cfe_internal_core_watchdog_enabled::
"Enable Core Watchdog"
usebundle => cfe_internal_core_watchdog("enabled");
mpf_augments_control_enabled::
"mpf_augments_control"
usebundle => mpf_augments_control;
}
bundle agent mpf_auto_am_policy_hub_state
# @brief Ensure that `$(sys.statedir)/am_policy_hub` file is present when expected
{
files:
# We think we are a policy hub if the policy server (the host you
# bootstrapped to) resolves to an IP found on the host. This is intended
# to prevent accidental removal of the am_policy_hub state file.
"$(sys.statedir)/am_policy_hub"
create => "true",
if => some( escape( $(sys.policy_server) ), @(sys.ipaddresses) );
}
bundle agent mpf_augments_control
# @brief Restart cfenigne components when one of the control variables has changed.
#
# While the agent itsef will reload its config upon notice of policy change
# this bundle specifically handles changes to variables used in the MPF which may
# come from external data sources which are unknown to the components themselves.
{
@if minimum_version(3.10)
# This policy leverages variablesmatching_as_data() (available since
# 3.10.0) and the -top- mustache extension (available since 3.9.0).
vars:
# Variables and their data which might necessitate a component restart
"server_controls" data => variablesmatching_as_data("default:def.control_server_.*");
"executor_controls" data => variablesmatching_as_data("default:def.control_executor_.*");
"monitor_controls" data => variablesmatching_as_data("default:def.control_monitor_.*");
"hub_controls" data => variablesmatching_as_data("default:def.control_hub_.*");
"runagent_controls" data => variablesmatching_as_data("default:def.control_runagent_.*");
"common_controls" data => variablesmatching_as_data("default:def.control_common_.*");
"agent_controls" data => variablesmatching_as_data("default:def.control_agent_.*");
# Serialized data for tracking state
"server_controls_state" string => string_mustache("{{$-top-}}", server_controls);
"executor_controls_state" string => string_mustache("{{$-top-}}", executor_controls);
"monitor_controls_state" string => string_mustache("{{$-top-}}", monitor_controls);
"hub_controls_state" string => string_mustache("{{$-top-}}", hub_controls);
"runagent_controls_state" string => string_mustache("{{$-top-}}", runagent_controls);
"common_controls_state" string => string_mustache("{{$-top-}}", common_controls);
"agent_controls_state" string => string_mustache("{{$-top-}}", agent_controls);
files:
"$(sys.workdir)$(const.dirsep)state$(const.dirsep)mpf_hub_controls"
create => "true",
edit_line => insert_lines( $(hub_controls_state) ),
edit_defaults => empty,
classes => results("bundle", "hub_controls" );
"$(sys.workdir)$(const.dirsep)state$(const.dirsep)mpf_server_controls"
create => "true",
edit_line => insert_lines( $(server_controls_state) ),
edit_defaults => empty,
classes => results("bundle", "server_controls" );
"$(sys.workdir)$(const.dirsep)state$(const.dirsep)mpf_monitor_controls"
create => "true",
edit_line => insert_lines( $(monitor_controls_state) ),
edit_defaults => empty,
classes => results("bundle", "monitor_controls" );
"$(sys.workdir)$(const.dirsep)state$(const.dirsep)mpf_executor_controls"
create => "true",
edit_line => insert_lines( $(executor_controls_state) ),
edit_defaults => empty,
classes => results("bundle", "executor_controls" );
"$(sys.workdir)$(const.dirsep)state$(const.dirsep)mpf_runagent_controls"
create => "true",
edit_line => insert_lines( $(runagent_controls_state) ),
edit_defaults => empty,
classes => results("bundle", "runagent_controls" );
# Note a change in common controls is not expected to trigger any
# component restart, its simply tracked for completeness.
"$(sys.workdir)$(const.dirsep)state$(const.dirsep)mpf_common_controls"
create => "true",
edit_line => insert_lines( $(common_controls_state) ),
edit_defaults => empty,
classes => results("bundle", "common_controls" );
# No need to restart cf-agent it as its not long running. We simply track the details for completeness.
"$(sys.workdir)$(const.dirsep)state$(const.dirsep)mpf_agent_controls"
create => "true",
edit_line => insert_lines( $(agent_controls_state) ),
edit_defaults => empty,
classes => results("bundle", "agent_controls" );
services:
systemd::
"cf-serverd"
service_policy => "restart",
if => "(server_controls_repaired|runagent_controls_repaired)";
"cf-monitord"
service_policy => "restart",
if => "monitor_controls_repaired";
systemd.enterprise_edition.(am_policy_hub|policy_server)::
"cf-hub"
service_policy => "restart",
if => "hub_controls_repaired";
# Well, this is dangerous we might kill our own agent
# "cf-execd"
# service_policy => "restart",
# if => "(execd_controls_repaired|runagent_controls_repaired)";
processes:
!systemd::
"cf-serverd"
signals => { "term" },
if => "(server_controls_repaired|runagent_controls_repaired)";
"cf-monitord"
signals => { "term" },
if => "monitor_controls_repaired";
systemd.enterprise_edition.(am_policy_hub|policy_server)::
"cf-hub"
signals => { "term" },
if => "hub_controls_repaired";
# Well, this is dangerous we might kill our own agent
# "cf-execd"
# signals => { "term" },
# if => "(execd_controls_repaired|runagent_controls_repaired)";
@endif
}
|