Skip to content

Commit da205b3

Browse files
committed
Ensure Agent service is not running if experiment is running
1 parent fd56925 commit da205b3

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Facter.add(:datadog_agent_exp_active) do
2+
confine kernel: 'Linux'
3+
setcode do
4+
active = false
5+
6+
# Determine via service manager when available
7+
if Facter::Util::Resolution.which('systemctl')
8+
active = system('systemctl is-active --quiet datadog-agent-exp')
9+
elsif Facter::Util::Resolution.which('service')
10+
active = system('service datadog-agent-exp status >/dev/null 2>&1')
11+
elsif Facter::Util::Resolution.which('pgrep')
12+
# Fallback: look for the experiment agent binary as the running command (exact path prefix)
13+
active = system('pgrep -f "^/opt/datadog-packages/datadog-agent/experiment/bin/agent/agent( |$)" >/dev/null 2>&1')
14+
end
15+
16+
active
17+
end
18+
end

manifests/init.pp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,15 @@
507507
}
508508

509509
# Declare service
510+
if ($facts['os']['name'] != 'Windows' and $facts['datadog_agent_exp_active'] == true) {
511+
$_service_ensure = 'stopped'
512+
} else {
513+
$_service_ensure = $service_ensure
514+
}
515+
510516
class { 'datadog_agent::service' :
511517
agent_flavor => $agent_flavor,
512-
service_ensure => $service_ensure,
518+
service_ensure => $_service_ensure,
513519
service_enable => $service_enable,
514520
service_provider => $service_provider,
515521
}

0 commit comments

Comments
 (0)