Merge lp:~allenap/maas/packaging--upstart-workers--bug-1452276 into lp:~maas-maintainers/maas/packaging

Proposed by Gavin Panella
Status: Merged
Approved by: Gavin Panella
Approved revision: 392
Merged at revision: 392
Proposed branch: lp:~allenap/maas/packaging--upstart-workers--bug-1452276
Merge into: lp:~maas-maintainers/maas/packaging
Diff against target: 153 lines (+34/-78)
4 files modified
debian/control (+0/-1)
debian/maas-region-controller-min.maas-regiond-worker.upstart (+25/-0)
debian/maas-region-controller-min.maas-regiond.upstart (+7/-77)
debian/rules (+2/-0)
To merge this branch: bzr merge lp:~allenap/maas/packaging--upstart-workers--bug-1452276
Reviewer Review Type Date Requested Status
Andres Rodriguez (community) Approve
Review via email: mp+258752@code.launchpad.net

Commit message

Launch 4 maas-regiond workers using Upstart instance jobs.

To post a comment you must log in.
Revision history for this message
Andres Rodriguez (andreserl) wrote :

Hi Gavin,

My understanding is that we don't have to create a worker upstart job, but rather, do it within the same upstart job. Can you look itno that please? Otherwise reach out to infinity or someone in the foundations team to check with them.

review: Needs Information
Revision history for this message
Gavin Panella (allenap) wrote :

I can't get restarts to work when putting all the stuff in a single service definition. I've asked Adam Conrad for help. In the meantime please consider landing this. It's only a cosmetic difference, but it's costing a fortune in lost time for me. In addition, using separate service definitions is easier to reason about and understand; smooshing everything into one is somewhat hacky.

392. By Gavin Panella

Remove the 'sleep hack' on the advice of jodh.

Revision history for this message
Gavin Panella (allenap) wrote :

James Hunt has said that "2 jobs is tbh recommended - it's much clearer: a manager and a bunch of workers."

He had some other useful advice about the 'sleep hack', i.e. that it's not needed. I've removed it, and I'll give this another run locally.

Revision history for this message
Gavin Panella (allenap) wrote :

> I'll give this another run locally.

It all seems to work nicely. Let's land this!

Revision history for this message
Andres Rodriguez (andreserl) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2015-04-15 16:48:02 +0000
3+++ debian/control 2015-05-14 13:16:20 +0000
4@@ -49,7 +49,6 @@
5 Architecture: all
6 Depends: apache2,
7 bind9utils,
8- daemontools,
9 dbconfig-common,
10 iproute,
11 libjs-angularjs,
12
13=== added file 'debian/maas-region-controller-min.maas-regiond-worker.upstart'
14--- debian/maas-region-controller-min.maas-regiond-worker.upstart 1970-01-01 00:00:00 +0000
15+++ debian/maas-region-controller-min.maas-regiond-worker.upstart 2015-05-14 13:16:20 +0000
16@@ -0,0 +1,25 @@
17+description "MAAS Region Controller (Worker)"
18+author "Gavin Panella <gavin.panella@canonical.com>"
19+
20+# This instance job is started by the parent `maas-regiond` job, and
21+# stops when that job is stopped. This is differentiated from its
22+# siblings by the $core instance argument.
23+
24+instance $core
25+
26+stop on stopping maas-regiond
27+
28+setuid maas
29+setgid maas
30+
31+respawn
32+
33+kill timeout 15
34+
35+env DJANGO_SETTINGS_MODULE=maas.settings
36+env PYTHONPATH=/usr/share/maas
37+env LOGFILE=/var/log/maas/regiond.log
38+
39+script
40+ exec /usr/bin/twistd --nodaemon --pidfile= maas-regiond >> ${LOGFILE} 2>&1
41+end script
42
43=== modified file 'debian/maas-region-controller-min.maas-regiond.upstart'
44--- debian/maas-region-controller-min.maas-regiond.upstart 2015-04-15 21:47:48 +0000
45+++ debian/maas-region-controller-min.maas-regiond.upstart 2015-05-14 13:16:20 +0000
46@@ -1,87 +1,17 @@
47 description "MAAS Region Controller"
48 author "Gavin Panella <gavin.panella@canonical.com>"
49
50+# This starts multiple instances of `maas-regiond-worker` and does
51+# nothing else itself; there is no main script so this runs "forever".
52+# By default, it launches four workers.
53+
54 start on filesystem and net-device-up
55 stop on runlevel [016]
56
57-env svcdir=/var/lib/maas/regiond
58-
59-setuid maas
60-setgid maas
61-
62 respawn
63
64-# Give `supervise` time to exit in post-stop. It's not clear that this
65-# time applies to pre/post scripts, so this may be for naught.
66-kill timeout 15
67-
68 pre-start script
69- set -eu
70- # Create the service directory.
71- mkdir -p "${svcdir}"
72- # Create a `run` script in the service directory.
73- svcrun="${svcdir}/run"
74- echo "#!/bin/sh" > "${svcrun}"
75- echo "exec >> /var/log/maas/regiond.log 2>&1" >> "${svcrun}"
76- echo "export PYTHONPATH=/usr/share/maas" >> "${svcrun}"
77- echo "export DJANGO_SETTINGS_MODULE=maas.settings" >> "${svcrun}"
78- echo "exec /usr/bin/twistd --nodaemon --pidfile= maas-regiond" >> "${svcrun}"
79- chmod a+x "${svcrun}"
80- # We're going to create between 2 and 5 daemons, depending on core count.
81- daemons="$(nproc)"
82- if [ "${daemons}" -lt 2 ]
83- then
84- daemons=2
85- elif [ "${daemons}" -gt 5 ]
86- then
87- daemons=5
88- fi
89- # Create the run directories and link to the shared `run` script.
90- for daemon in $(seq "${daemons}")
91- do
92- rundir="${svcdir}/${daemon}"
93- mkdir -p "${rundir}"
94- runfile="${rundir}/run"
95- ln -snf "${svcrun}" "${runfile}"
96- done
97-end script
98-
99-script
100- # In the case where this service has been restarted, we may have
101- # running `supervise` daemons. Bring each service up.
102- find "${svcdir}" -name run -executable \
103- -execdir svok . \; -execdir svc -u . \;
104- # In the case where this service has been restarted, we may also
105- # have leftover `down` markers. To remove these, we remove the
106- # `supervise` directories.
107- find "${svcdir}" -name supervise -type d \
108- -not -execdir svok . \; -execdir rm -rf {} \;
109- # Exec the `svscan` daemon, as the meta-supervisor.
110- exec svscan "${svcdir}"
111-end script
112-
113-pre-stop script
114- # Bring each service down. We must *not* exit the `supervise` daemon
115- # because `svscan` may then have time in which to respawn it before
116- # it's stopped.
117- find "${svcdir}" -name run -executable -execdir svok . \; \
118- -printf "Bringing %h down.\n" -execdir svc -d . \;
119-end script
120-
121-post-stop script
122- set -eu
123- # Bring each service down (belt-n-braces) and quit supervise; it's
124- # safe to do so now because `svscan` is guaranteed to have stopped.
125- find "${svcdir}" -name run -executable -execdir svok . \; \
126- -printf "Bringing %h down.\n" -execdir svc -dx . \;
127- # For up to 10 seconds -- less than the `kill timeout` -- check if
128- # any supervise daemons are still running every 0.1 seconds.
129- for attempt in $(seq 100)
130- do
131- # If one or more `supervise` daemons are still running, sleep.
132- find "${svcdir}" -name run -execdir svok . \; -exec sleep 0.1 \; -quit
133- done
134- # Kill with fire any remaining supervise daemons.
135- find "${svcdir}" -name run -executable -execdir svok . \; \
136- -printf "Killing %h; timed-out.\n" -execdir svc -k . \;
137+ for core in $(seq 4); do
138+ start maas-regiond-worker core=${core}
139+ done
140 end script
141
142=== modified file 'debian/rules'
143--- debian/rules 2015-04-15 16:48:02 +0000
144+++ debian/rules 2015-05-14 13:16:20 +0000
145@@ -17,6 +17,8 @@
146 dh_systemd_enable --name maas-regiond
147 dh_installinit --name maas-regiond
148 dh_systemd_start --name maas-regiond
149+ # maas-regiond-worker
150+ dh_installinit --name maas-regiond-worker
151 # maas-dhcpd
152 dh_systemd_enable --name maas-dhcpd
153 dh_installinit --name maas-dhcpd

Subscribers

People subscribed via source and target branches