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
=== modified file 'debian/control'
--- debian/control 2015-04-15 16:48:02 +0000
+++ debian/control 2015-05-14 13:16:20 +0000
@@ -49,7 +49,6 @@
49Architecture: all49Architecture: all
50Depends: apache2,50Depends: apache2,
51 bind9utils,51 bind9utils,
52 daemontools,
53 dbconfig-common,52 dbconfig-common,
54 iproute,53 iproute,
55 libjs-angularjs,54 libjs-angularjs,
5655
=== added file 'debian/maas-region-controller-min.maas-regiond-worker.upstart'
--- debian/maas-region-controller-min.maas-regiond-worker.upstart 1970-01-01 00:00:00 +0000
+++ debian/maas-region-controller-min.maas-regiond-worker.upstart 2015-05-14 13:16:20 +0000
@@ -0,0 +1,25 @@
1description "MAAS Region Controller (Worker)"
2author "Gavin Panella <gavin.panella@canonical.com>"
3
4# This instance job is started by the parent `maas-regiond` job, and
5# stops when that job is stopped. This is differentiated from its
6# siblings by the $core instance argument.
7
8instance $core
9
10stop on stopping maas-regiond
11
12setuid maas
13setgid maas
14
15respawn
16
17kill timeout 15
18
19env DJANGO_SETTINGS_MODULE=maas.settings
20env PYTHONPATH=/usr/share/maas
21env LOGFILE=/var/log/maas/regiond.log
22
23script
24 exec /usr/bin/twistd --nodaemon --pidfile= maas-regiond >> ${LOGFILE} 2>&1
25end script
026
=== modified file 'debian/maas-region-controller-min.maas-regiond.upstart'
--- debian/maas-region-controller-min.maas-regiond.upstart 2015-04-15 21:47:48 +0000
+++ debian/maas-region-controller-min.maas-regiond.upstart 2015-05-14 13:16:20 +0000
@@ -1,87 +1,17 @@
1description "MAAS Region Controller"1description "MAAS Region Controller"
2author "Gavin Panella <gavin.panella@canonical.com>"2author "Gavin Panella <gavin.panella@canonical.com>"
33
4# This starts multiple instances of `maas-regiond-worker` and does
5# nothing else itself; there is no main script so this runs "forever".
6# By default, it launches four workers.
7
4start on filesystem and net-device-up8start on filesystem and net-device-up
5stop on runlevel [016]9stop on runlevel [016]
610
7env svcdir=/var/lib/maas/regiond
8
9setuid maas
10setgid maas
11
12respawn11respawn
1312
14# Give `supervise` time to exit in post-stop. It's not clear that this
15# time applies to pre/post scripts, so this may be for naught.
16kill timeout 15
17
18pre-start script13pre-start script
19 set -eu14 for core in $(seq 4); do
20 # Create the service directory.15 start maas-regiond-worker core=${core}
21 mkdir -p "${svcdir}"16 done
22 # Create a `run` script in the service directory.
23 svcrun="${svcdir}/run"
24 echo "#!/bin/sh" > "${svcrun}"
25 echo "exec >> /var/log/maas/regiond.log 2>&1" >> "${svcrun}"
26 echo "export PYTHONPATH=/usr/share/maas" >> "${svcrun}"
27 echo "export DJANGO_SETTINGS_MODULE=maas.settings" >> "${svcrun}"
28 echo "exec /usr/bin/twistd --nodaemon --pidfile= maas-regiond" >> "${svcrun}"
29 chmod a+x "${svcrun}"
30 # We're going to create between 2 and 5 daemons, depending on core count.
31 daemons="$(nproc)"
32 if [ "${daemons}" -lt 2 ]
33 then
34 daemons=2
35 elif [ "${daemons}" -gt 5 ]
36 then
37 daemons=5
38 fi
39 # Create the run directories and link to the shared `run` script.
40 for daemon in $(seq "${daemons}")
41 do
42 rundir="${svcdir}/${daemon}"
43 mkdir -p "${rundir}"
44 runfile="${rundir}/run"
45 ln -snf "${svcrun}" "${runfile}"
46 done
47end script
48
49script
50 # In the case where this service has been restarted, we may have
51 # running `supervise` daemons. Bring each service up.
52 find "${svcdir}" -name run -executable \
53 -execdir svok . \; -execdir svc -u . \;
54 # In the case where this service has been restarted, we may also
55 # have leftover `down` markers. To remove these, we remove the
56 # `supervise` directories.
57 find "${svcdir}" -name supervise -type d \
58 -not -execdir svok . \; -execdir rm -rf {} \;
59 # Exec the `svscan` daemon, as the meta-supervisor.
60 exec svscan "${svcdir}"
61end script
62
63pre-stop script
64 # Bring each service down. We must *not* exit the `supervise` daemon
65 # because `svscan` may then have time in which to respawn it before
66 # it's stopped.
67 find "${svcdir}" -name run -executable -execdir svok . \; \
68 -printf "Bringing %h down.\n" -execdir svc -d . \;
69end script
70
71post-stop script
72 set -eu
73 # Bring each service down (belt-n-braces) and quit supervise; it's
74 # safe to do so now because `svscan` is guaranteed to have stopped.
75 find "${svcdir}" -name run -executable -execdir svok . \; \
76 -printf "Bringing %h down.\n" -execdir svc -dx . \;
77 # For up to 10 seconds -- less than the `kill timeout` -- check if
78 # any supervise daemons are still running every 0.1 seconds.
79 for attempt in $(seq 100)
80 do
81 # If one or more `supervise` daemons are still running, sleep.
82 find "${svcdir}" -name run -execdir svok . \; -exec sleep 0.1 \; -quit
83 done
84 # Kill with fire any remaining supervise daemons.
85 find "${svcdir}" -name run -executable -execdir svok . \; \
86 -printf "Killing %h; timed-out.\n" -execdir svc -k . \;
87end script17end script
8818
=== modified file 'debian/rules'
--- debian/rules 2015-04-15 16:48:02 +0000
+++ debian/rules 2015-05-14 13:16:20 +0000
@@ -17,6 +17,8 @@
17 dh_systemd_enable --name maas-regiond17 dh_systemd_enable --name maas-regiond
18 dh_installinit --name maas-regiond18 dh_installinit --name maas-regiond
19 dh_systemd_start --name maas-regiond19 dh_systemd_start --name maas-regiond
20 # maas-regiond-worker
21 dh_installinit --name maas-regiond-worker
20 # maas-dhcpd22 # maas-dhcpd
21 dh_systemd_enable --name maas-dhcpd23 dh_systemd_enable --name maas-dhcpd
22 dh_installinit --name maas-dhcpd24 dh_installinit --name maas-dhcpd

Subscribers

People subscribed via source and target branches