Merge ~cjwatson/launchpad-buildd:systemd-service into launchpad-buildd:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 1f96833fb1608fd2d497d5c3447077c836a8f7c1
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad-buildd:systemd-service
Merge into: launchpad-buildd:master
Diff against target: 311 lines (+74/-152)
10 files modified
debian/changelog (+1/-0)
debian/control (+1/-1)
debian/launchpad-buildd-generator (+19/-0)
debian/launchpad-buildd.install (+1/-0)
debian/launchpad-buildd.maintscript (+1/-0)
debian/launchpad-buildd.service (+15/-0)
debian/launchpad-buildd@.service (+26/-0)
debian/postrm (+4/-0)
debian/rules (+6/-1)
dev/null (+0/-150)
Reviewer Review Type Date Requested Status
Ioana Lasc (community) Approve
Review via email: mp+416757@code.launchpad.net

Commit message

Convert daemon startup to systemd

Description of the change

As well as simplifying away 150 lines of shell script, this avoids relying on su(1) to run the daemon as the `buildd` user, which in turn avoids accidental pollution of the daemon's environment by whatever su(1) thinks is appropriate in interactive environments.

There's a bit of extra complexity due to supporting multiple daemon instances, which is mostly historical at this point, but it was easy enough to handle using a template unit and a generator.

I dropped the explicit hostname condition, since all our builders already have `RUN_NETWORK_REQUESTS_AS_ROOT=yes` set in `/etc/default/launchpad-buildd`.

To post a comment you must log in.
Revision history for this message
Ioana Lasc (ilasc) :
review: Approve
Revision history for this message
Otto Co-Pilot (otto-copilot) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index 3b85725..27d5603 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -5,6 +5,7 @@ launchpad-buildd (210) UNRELEASED; urgency=medium
6 * Make more loop device nodes available in LXD containers (LP: #1963706).
7 * Drop pre-Python-3.6 code using pyupgrade.
8 * Fix gathering the output of charm recipe builds that use --build-path.
9+ * Convert daemon startup to systemd (LP: #1964615).
10
11 -- Colin Watson <cjwatson@ubuntu.com> Mon, 28 Feb 2022 11:27:20 +0000
12
13diff --git a/debian/control b/debian/control
14index 6bbe218..5938781 100644
15--- a/debian/control
16+++ b/debian/control
17@@ -8,7 +8,7 @@ Standards-Version: 3.9.5
18 Build-Depends: apt-utils,
19 bzr,
20 curl,
21- debhelper (>= 9~),
22+ debhelper (>= 9.20160709~),
23 dh-exec,
24 dh-python,
25 git,
26diff --git a/debian/launchpad-buildd-generator b/debian/launchpad-buildd-generator
27new file mode 100755
28index 0000000..797f453
29--- /dev/null
30+++ b/debian/launchpad-buildd-generator
31@@ -0,0 +1,19 @@
32+#! /bin/sh
33+set -e
34+
35+# Generate systemd unit dependency symlinks for all configured
36+# launchpad-buildd instances.
37+
38+wantdir="$1/launchpad-buildd.service.wants"
39+template=/lib/systemd/system/launchpad-buildd@.service
40+
41+mkdir -p "$wantdir"
42+
43+for conf in /etc/launchpad-buildd/*; do
44+ # Skip nonexistent files (perhaps due to the glob matching no files).
45+ [ -e "$conf" ] || continue
46+ # Skip backup files.
47+ case $conf in -*|*~) continue ;; esac
48+
49+ ln -s "$template" "$wantdir/launchpad-buildd@${conf##*/}.service"
50+done
51diff --git a/debian/launchpad-buildd.init b/debian/launchpad-buildd.init
52deleted file mode 100755
53index b92d911..0000000
54--- a/debian/launchpad-buildd.init
55+++ /dev/null
56@@ -1,150 +0,0 @@
57-#!/bin/sh
58-#
59-# Copyright 2009,2011 Canonical Ltd. This software is licensed under the
60-# GNU Affero General Public License version 3 (see the file LICENSE).
61-#
62-# launchpad-buildd
63-# This file is used to start and stop launchpad buildds
64-
65-### BEGIN INIT INFO
66-# Provides: launchpad_buildd
67-# Required-Start: $local_fs $network $syslog $time $remote_fs
68-# Required-Stop: $local_fs $network $syslog $time $remote_fs
69-# Should-Start: cloud-init
70-# Default-Start: 2 3 4 5
71-# Default-Stop: 0 1 6
72-# X-Interactive: false
73-# Short-Description: Start/stop launchpad buildds
74-### END INIT INFO
75-
76-set -e
77-
78-PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
79-DESC="launchpad build slaves"
80-
81-TACFILE="/usr/lib/launchpad-buildd/buildd-slave.tac"
82-
83-PIDROOT="/var/run/launchpad-buildd"
84-LOGROOT="/var/log/launchpad-buildd"
85-CONFROOT="/etc/launchpad-buildd"
86-
87-# Gracefully exit if the package has been removed.
88-test -e $TACFILE || exit 0
89-
90-
91-d_check_enabled() {
92-RUN_NETWORK_REQUESTS_AS_ROOT=no # Good idea generally
93-
94-[ -f /etc/default/launchpad-buildd ] && . /etc/default/launchpad-buildd
95-
96-hostname="`hostname -f`"
97-case "$hostname" in
98-*.ppa|*.buildd)
99- cat <<END
100-
101-launchpad-buildd: starting automatically because $hostname seems to be a buildd machine.
102-
103-CAUTION: this service accepts network commands and runs them as root.
104-END
105- return
106- ;;
107-*)
108- echo "launchpad-buildd: not starting automatically on $hostname"
109- ;;
110-esac
111-
112-if [ "$RUN_NETWORK_REQUESTS_AS_ROOT" != yes ]
113-then
114- cat <<END
115-
116-launchpad-buildd is disabled.
117-When enabled, launchpad-buildd accepts network commands and runs them as root.
118-If you are sure this server will only be reachable by trusted machines, edit
119-/etc/default/launchpad-buildd.
120-
121-END
122- exit 0
123-fi
124-}
125-
126-
127-#
128-# Function that starts a buildd slave
129-#
130-d_start() {
131- CONF=$1
132- PIDFILE="$PIDROOT"/"$CONF".pid
133- LOGFILE="$LOGROOT"/"$CONF".log
134-
135- # Useful for certain kinds of image builds.
136- modprobe nbd || true
137-
138- su - buildd -c "BUILDD_CONFIG=$CONFROOT/$CONF twistd3 --no_save --pidfile $PIDFILE --python $TACFILE --logfile $LOGFILE --umask 022"
139-}
140-
141-#
142-# Function that stops a buildd slave
143-#
144-d_stop() {
145- CONF=$1
146- PIDFILE="$PIDROOT"/"$CONF".pid
147- test -r $PIDFILE && kill -TERM $(cat $PIDFILE) || true
148-}
149-
150-#
151-# Function that reloads a buildd slave
152-#
153-d_reload() {
154- CONF=$1
155- PIDFILE="$PIDROOT"/"$CONF".pid
156- test -r $PIDFILE && kill -HUP $(cat $PIDFILE) || true
157-}
158-
159-CONFS=$(cd $CONFROOT; ls|grep -v "^-"|grep -v "~$")
160-
161-case "$1" in
162- start)
163- d_check_enabled
164-
165- echo -n "Starting $DESC:"
166- install -m 755 -o buildd -g buildd -d $PIDROOT
167-
168- # Create any missing directories and chown them appropriately
169- install -d -o buildd -g buildd /home/buildd/filecache-default
170-
171- for conf in $CONFS; do
172- echo -n " $conf"
173- d_start $conf
174- done
175- echo "."
176- ;;
177- stop)
178- echo -n "Stopping $DESC:"
179- for conf in $CONFS; do
180- echo -n " $conf"
181- d_stop $conf
182- done
183- echo "."
184- ;;
185- restart|force-reload)
186- #
187- # If the "reload" option is implemented, move the "force-reload"
188- # option to the "reload" entry above. If not, "force-reload" is
189- # just the same as "restart".
190- #
191- $0 stop
192- sleep 1
193- $0 start
194- ;;
195- reload)
196- for conf in $CONFS; do
197- d_reload $conf
198- done
199- ;;
200- *)
201- echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|reload}" >&2
202- exit 1
203- ;;
204-esac
205-
206-exit 0
207diff --git a/debian/launchpad-buildd.install b/debian/launchpad-buildd.install
208index 95db295..208bfde 100644
209--- a/debian/launchpad-buildd.install
210+++ b/debian/launchpad-buildd.install
211@@ -5,6 +5,7 @@ bin/in-target usr/share/launchpad-buildd/bin
212 bin/lpbuildd-git-proxy usr/share/launchpad-buildd/bin
213 bin/sbuild-package usr/share/launchpad-buildd/bin
214 buildd-genconfig usr/share/launchpad-buildd
215+debian/launchpad-buildd-generator lib/systemd/system-generators
216 debian/upgrade-config usr/share/launchpad-buildd
217 default/launchpad-buildd etc/default
218 sbuildrc usr/share/launchpad-buildd
219diff --git a/debian/launchpad-buildd.maintscript b/debian/launchpad-buildd.maintscript
220new file mode 100644
221index 0000000..cfeedce
222--- /dev/null
223+++ b/debian/launchpad-buildd.maintscript
224@@ -0,0 +1 @@
225+rm_conffile /etc/init.d/launchpad-buildd 210~
226diff --git a/debian/launchpad-buildd.service b/debian/launchpad-buildd.service
227new file mode 100644
228index 0000000..ca425b3
229--- /dev/null
230+++ b/debian/launchpad-buildd.service
231@@ -0,0 +1,15 @@
232+# This service is really a systemd target, but we use a service since
233+# targets cannot be reloaded. See launchpad-buildd@.service for instance
234+# configuration.
235+
236+[Unit]
237+Description=Launchpad build daemon
238+
239+[Service]
240+Type=oneshot
241+RemainAfterExit=yes
242+ExecStart=/bin/true
243+ExecReload=/bin/true
244+
245+[Install]
246+WantedBy=multi-user.target
247diff --git a/debian/launchpad-buildd@.service b/debian/launchpad-buildd@.service
248new file mode 100644
249index 0000000..690e0fd
250--- /dev/null
251+++ b/debian/launchpad-buildd@.service
252@@ -0,0 +1,26 @@
253+[Unit]
254+Description=Launchpad build daemon (%i)
255+PartOf=launchpad-buildd.service
256+Before=launchpad-buildd.service
257+ReloadPropagatedFrom=launchpad-buildd.service
258+After=network.target time-sync.target cloud-init.service
259+# Useful for certain kinds of image builds.
260+After=modprobe@nbd.service
261+Requires=modprobe@nbd.service
262+
263+[Service]
264+Type=simple
265+RuntimeDirectory=launchpad-buildd
266+LogsDirectory=launchpad-buildd
267+User=buildd
268+EnvironmentFile=-/etc/default/launchpad-buildd
269+Environment=BUILDD_CONFIG=/etc/launchpad-buildd/%i
270+# When enabled, launchpad-buildd accepts network commands and runs them as
271+# root. If you are sure this server will only be reachable by trusted
272+# machines, edit /etc/default/launchpad-buildd.
273+ExecStartPre=/usr/bin/test ${RUN_NETWORK_REQUESTS_AS_ROOT} = yes
274+ExecStartPre=/usr/bin/install -d /home/buildd/filecache-default
275+ExecStart=/usr/bin/twistd3 --no_save --pidfile /run/launchpad-buildd/%i.pid --python /usr/lib/launchpad-buildd/buildd-slave.tac --logfile /var/log/launchpad-buildd/%i.log --umask 022 --nodaemon
276+
277+[Install]
278+WantedBy=multi-user.target
279diff --git a/debian/postrm b/debian/postrm
280index 7d847de..a331fa2 100644
281--- a/debian/postrm
282+++ b/debian/postrm
283@@ -9,3 +9,7 @@ if [ "$1" = purge ]; then
284 rmdir -p --ignore-fail-on-non-empty /etc/systemd/timesyncd.conf.d
285 fi
286 fi
287+
288+#DEBHELPER#
289+
290+exit 0
291diff --git a/debian/rules b/debian/rules
292index ebf0618..be006d8 100755
293--- a/debian/rules
294+++ b/debian/rules
295@@ -9,10 +9,15 @@ export PYBUILD_NAME := lpbuildd
296 export LIBDIR := $(shell python3 -c 'import distutils.sysconfig; print(distutils.sysconfig.get_python_lib())')
297
298 %:
299- dh $@ --with=python3 --buildsystem=pybuild
300+ dh $@ --with=python3,systemd --buildsystem=pybuild
301
302 override_dh_auto_build:
303 dh_auto_build
304 python3 buildd-genconfig --template=template-buildd-slave.conf \
305 --arch=i386 --port=8221 --name=default --host=buildd.buildd \
306 > buildd-slave-example.conf
307+
308+# Required in debhelper compatibility level <=10 to avoid generating
309+# postinst fragments to register a nonexistent init.d script.
310+override_dh_installinit:
311+ dh_installinit -n

Subscribers

People subscribed via source and target branches