Skip to content

Commit f05546d

Browse files
committed
Use systemd service overrides instead of systemctl set-env
The latter affects every subsequently started service (at least). The former only affects the service that needs the env variable.
1 parent cee477c commit f05546d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

packer/linux/conf/bin/bk-install-elastic-stack.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,17 @@ done
361361
echo "Waited $next_wait_time times for docker to start. We will exit if it still has not started."
362362
check_docker
363363

364-
# also set in /var/lib/buildkite-agent/cfn-env so that its shown in the job logs
365-
systemctl set-environment "BUILDKITE_TERMINATE_INSTANCE_AFTER_JOB=${BUILDKITE_TERMINATE_INSTANCE_AFTER_JOB}"
364+
echo Writing buildkite-agent systemd environment override...
365+
# also set in /var/lib/buildkite-agent/cfn-env so that it's shown in the job logs
366+
mkdir -p /etc/systemd/system/buildkite-agent.service.d
367+
cat <<EOF | tee /etc/systemd/system/buildkite-agent.service.d/environment.conf
368+
[Service]
369+
Environment="BUILDKITE_TERMINATE_INSTANCE_AFTER_JOB=${BUILDKITE_TERMINATE_INSTANCE_AFTER_JOB}"
370+
EOF
371+
372+
echo Reloading systemctl services...
373+
systemctl daemon-reload
374+
366375
echo Starting buildkite-agent...
367376
systemctl enable --now buildkite-agent
368377

0 commit comments

Comments
 (0)