Skip to content

Commit 219c3a2

Browse files
committed
Restore non-essential systemd unit cleanup for jammy warden
bosh-docker-cpi-release#60 moved the cleanup of non-essential systemd units out of the Docker CPI and into the stemcell, on the basis that the stemcell would mask anything that can't run in a container (resolving bosh-docker-cpi-release#58 and #504). On the jammy line, only the systemd-binfmt mask landed (#500); the rest of the CPI's allow-list was never reproduced here. As a result, warden stemcells started with exec /sbin/init now boot the full stock systemd unit set. In a BOSH director the stock units contend with the monit-managed bpm jobs and the director fails to converge (e.g. the postgres role is never created). This regresses any consumer running a Docker-CPI director on a jammy warden stemcell ≥ the build that pairs with Docker CPI ≥ 0.2.9. This restores the CPI's historical allow-list in base_warden, removing the non-essential .wants entries at build time. It uses -delete (≡ systemctl disable) rather than mask, matching the CPI's original semantics: units are dropped from the boot sequence but can still start as dependencies of a kept unit. runit, ssh, dbus, journald, logrotate, systemd-tmpfiles, systemd-user-sessions, and the bosh-agent are preserved. Deriving the set at build time keeps it correct as the package set changes. Verified against ubuntu-jammy-stemcell:1.1250: 13 essential .wants entries kept, ~75 non-essential removed. This is the same prune Docker CPI 0.2.3 applied, which is green on cgroups-v1 workers. Adds a warden_spec assertion that non-essential units are removed and essential ones remain. Related: bosh-docker-cpi-release#60, bosh-docker-cpi-release#58, #500, ai-assisted=yes [TNZ-88995]
1 parent b034843 commit 219c3a2

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

bosh-stemcell/spec/stemcells/warden_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,30 @@
5858
its(:content) { should include('"UseMonitIptablesFirewall": true') }
5959
end
6060
end
61+
62+
context "systemd unit cleanup for warden containers" do
63+
# The Docker CPI runs warden stemcells with `exec /sbin/init`. base_warden
64+
# strips non-essential stock systemd units from the boot sequence so they
65+
# don't contend with the monit-managed bpm jobs in the BOSH director
66+
# container (symptom: postgres role never created, bosh/0 never converges).
67+
# Keep-list mirrors the historical Docker CPI allow-list. See
68+
# base_warden/apply.sh and cloudfoundry/bosh-docker-cpi-release#60.
69+
keep_patterns = %w[
70+
*bosh-agent* *dbus* *journald* *logrotate* *runit* *ssh*
71+
*systemd-user-sessions* *systemd-tmpfiles*
72+
]
73+
not_name = keep_patterns.map { |g| "-not -name '#{g}'" }.join(" ")
74+
wants = "find /etc/systemd/system /lib/systemd/system -path '*.wants/*'"
75+
76+
describe "non-essential units are removed from the boot sequence" do
77+
describe command("#{wants} #{not_name}") do
78+
its(:stdout) { should eq "" }
79+
end
80+
end
81+
82+
describe "essential units are preserved (guards against an over-broad prune)" do
83+
subject { command(wants).stdout.split("\n").length }
84+
it { should be > 0 }
85+
end
86+
end
6187
end

stemcell_builder/stages/base_warden/apply.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,32 @@ JSON
8585

8686
# Mask systemd-binfmt.service which fails under Rosetta emulation
8787
run_in_chroot "$chroot" "systemctl mask systemd-binfmt.service"
88+
89+
# Trim non-essential systemd units from the boot sequence.
90+
#
91+
# When the Docker CPI runs a warden stemcell with `exec /sbin/init`, full stock
92+
# systemd comes up and its units contend with the monit-managed bpm jobs in the
93+
# BOSH director container (symptom: the postgres role is never created and
94+
# bosh/0 never converges). The Docker CPI used to strip these units at
95+
# container-create time, but that allow-list prune was removed in
96+
# cloudfoundry/bosh-docker-cpi-release#60 on the assumption the stemcell would
97+
# take it over. The jammy stemcell only ever picked up the systemd-binfmt mask
98+
# above, so we reproduce the CPI's full allow-list here.
99+
#
100+
# This removes the `.wants` symlinks (equivalent to `systemctl disable`): units
101+
# are dropped from the boot sequence but can still start as dependencies of a
102+
# kept unit. The keep patterns mirror the historical CPI list exactly. Deriving
103+
# the set at build time keeps it correct as the stemcell's package set changes.
104+
run_in_chroot "$chroot" "
105+
find /etc/systemd/system /lib/systemd/system \
106+
-path '*.wants/*' \
107+
-not -name '*bosh-agent*' \
108+
-not -name '*dbus*' \
109+
-not -name '*journald*' \
110+
-not -name '*logrotate*' \
111+
-not -name '*runit*' \
112+
-not -name '*ssh*' \
113+
-not -name '*systemd-user-sessions*' \
114+
-not -name '*systemd-tmpfiles*' \
115+
-delete
116+
"

0 commit comments

Comments
 (0)