Merge ubuntu-debuginfod:systemd into ubuntu-debuginfod:master

Proposed by Sergio Durigan Junior
Status: Merged
Merged at revision: 0dcee21c98ff9a9b597af79d32647d924d10a9fb
Proposed branch: ubuntu-debuginfod:systemd
Merge into: ubuntu-debuginfod:master
Diff against target: 187 lines (+125/-1)
6 files modified
conf/ubuntu-debuginfod-celery.default (+12/-0)
conf/ubuntu-debuginfod-celery.service (+26/-0)
conf/ubuntu-debuginfod-poll-lp.service (+23/-0)
conf/ubuntu-debuginfod-poll-lp.timer (+10/-0)
debuginfod.py (+20/-1)
poll_launchpad.py (+34/-0)
Reviewer Review Type Date Requested Status
Lena Voytek (community) Approve
Canonical Server packageset reviewers Pending
Bryce Harrington Pending
Athos Ribeiro Pending
Canonical Server Reporter Pending
Review via email: mp+434134@code.launchpad.net

Description of the change

One more before bedtime? :-)

This should be the last one before I can fully deploy the new poller/getter. It extends the current celery application to be systemd-aware, creates new systemd services/timer, and finally creates a simple poller application that will be executed every 30 minutes to fetch new ddebs (and source code).

This should be simpler to review than the other MPs, I hope. Let me know what you think, please.

To post a comment you must log in.
Revision history for this message
Sergio Durigan Junior (sergiodj) wrote :

Note that various parameters chosen below (number of threads to spawn, $HOME directory, etc.) reflect what we have in the current deployment.

Revision history for this message
Lena Voytek (lvoytek) wrote :

Just need to make sure that sys is imported in poll_launchpad.py, then I approve. I'm not as familiar with creating systemd service files, but at least for the current deployment they look good to me!

review: Needs Fixing
Revision history for this message
Sergio Durigan Junior (sergiodj) wrote :

Thanks for the review, Lena.

I've addressed your comments and merged the branch, in preparation for the rework that I did (which will require yet another big MP).

Revision history for this message
Lena Voytek (lvoytek) wrote :

Looks good, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/conf/ubuntu-debuginfod-celery.default b/conf/ubuntu-debuginfod-celery.default
2new file mode 100644
3index 0000000..9f915b0
4--- /dev/null
5+++ b/conf/ubuntu-debuginfod-celery.default
6@@ -0,0 +1,12 @@
7+# App instance to use.
8+CELERY_APP="debuginfod"
9+
10+# Extra command-line arguments to the worker.
11+#
12+# We chose 6 workers here because it seemed like a good compromise
13+# between not hammering the network and processing as many things in
14+# parallel as possible.
15+CELERYD_OPTS="--concurrency=6"
16+
17+# Log level to use.
18+CELERYD_LOG_LEVEL="INFO"
19diff --git a/conf/ubuntu-debuginfod-celery.service b/conf/ubuntu-debuginfod-celery.service
20new file mode 100644
21index 0000000..f9331ce
22--- /dev/null
23+++ b/conf/ubuntu-debuginfod-celery.service
24@@ -0,0 +1,26 @@
25+[Unit]
26+Description=Ubuntu Debuginfod Celery
27+After=network.target rabbitmq-server.service
28+Requires=rabbitmq-server.service
29+
30+[Service]
31+Type=notify
32+User=mirror
33+Group=mirror
34+EnvironmentFile=/etc/default/ubuntu-debuginfod-celery
35+WorkingDirectory=/home/mirror/ubuntu-debuginfod/
36+ExecStart=/usr/bin/celery -A ${CELERY_APP} worker --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}
37+Restart=always
38+TimeoutStopSec=600
39+PrivateDevices=true
40+PrivateUsers=true
41+ProtectKernelTunables=true
42+ProtectControlGroups=true
43+ProtectKernelLogs=true
44+ProtectKernelModules=true
45+MemoryDenyWriteExecute=true
46+RestrictRealtime=true
47+ReadWritePaths=/srv/debug-mirror/
48+
49+[Install]
50+WantedBy=multi-user.target
51diff --git a/conf/ubuntu-debuginfod-poll-lp.service b/conf/ubuntu-debuginfod-poll-lp.service
52new file mode 100644
53index 0000000..5c9e13a
54--- /dev/null
55+++ b/conf/ubuntu-debuginfod-poll-lp.service
56@@ -0,0 +1,23 @@
57+[Unit]
58+Description=Poll Launchpad for new ddebs
59+After=network.target ubuntu-debuginfod-celery.service
60+Requires=ubuntu-debuginfod-celery.service
61+
62+[Service]
63+Type=oneshot
64+User=mirror
65+Group=mirror
66+WorkingDirectory=/home/mirror/ubuntu-debuginfod/
67+ExecStart=/usr/bin/python3 /home/mirror/ubuntu-debuginfod/poll_launchpad.py
68+PrivateDevices=true
69+PrivateUsers=true
70+ProtectKernelTunables=true
71+ProtectControlGroups=true
72+ProtectKernelLogs=true
73+ProtectKernelModules=true
74+MemoryDenyWriteExecute=true
75+RestrictRealtime=true
76+ReadWritePaths=/home/mirror/.config/ubuntu-debuginfod/
77+
78+[Install]
79+WantedBy=multi-user.target
80diff --git a/conf/ubuntu-debuginfod-poll-lp.timer b/conf/ubuntu-debuginfod-poll-lp.timer
81new file mode 100644
82index 0000000..c61fdcb
83--- /dev/null
84+++ b/conf/ubuntu-debuginfod-poll-lp.timer
85@@ -0,0 +1,10 @@
86+[Unit]
87+Description=Poll Launchpad for new ddebs
88+
89+[Timer]
90+# Every 30 minutes
91+OnCalendar=*:0/30
92+Persistent=true
93+
94+[Install]
95+WantedBy=timers.target
96diff --git a/debuginfod.py b/debuginfod.py
97index d64efd4..c0d0357 100644
98--- a/debuginfod.py
99+++ b/debuginfod.py
100@@ -18,11 +18,14 @@
101 # Authors: Sergio Durigan Junior <sergio.durigan@canonical.com>
102
103 from celery import Celery
104+from celery.signals import worker_ready, worker_shutting_down
105
106 from debuggetter import DebugGetterTimeout, DebugGetterRetry
107
108 from ddebgetter import DdebGetter, DdebSourceCodeGetter
109
110+import sdnotify
111+
112 app = Celery("debuginfod", broker="pyamqp://guest@localhost//")
113
114 app.conf.update(
115@@ -34,9 +37,13 @@ app.conf.update(
116 task_acks_late=True,
117 # Only one task per worker.
118 worker_prefetch_multiplier=1,
119- worker_log_format="[%(asctime)s: %(levelname)s/%(processName)s] %(funcName)s: %(message)s",
120+ # Rewrite the log format. We will most likely be running under
121+ # systemd, which already includes a timestamp on every log line.
122+ worker_log_format="[%(levelname)s/%(processName)s] %(funcName)s: %(message)s",
123 )
124
125+sdnotifier = sdnotify.SystemdNotifier()
126+
127
128 @app.task(
129 name="grab_ddebs",
130@@ -76,5 +83,17 @@ def grab_ddebs_sources(msg):
131 g.process_request(msg)
132
133
134+@worker_ready.connect
135+def notify_worker_ready(**kwargs):
136+ """Notify systemd that the worker initialization has finished."""
137+ sdnotifier.notify("READY=1")
138+
139+
140+@worker_shutting_down.connect
141+def notify_worker_shutting_down(**kwargs):
142+ """Notify systemd that the worker will start its process to shut down."""
143+ sdnotifier.notify("STOPPING=1")
144+
145+
146 if __name__ == "__main__":
147 app.start()
148diff --git a/poll_launchpad.py b/poll_launchpad.py
149new file mode 100644
150index 0000000..161aa77
151--- /dev/null
152+++ b/poll_launchpad.py
153@@ -0,0 +1,34 @@
154+#!/usr/bin/python3
155+
156+# Copyright (C) 2022 Canonical Ltd.
157+
158+# This program is free software: you can redistribute it and/or modify
159+# it under the terms of the GNU General Public License as published by
160+# the Free Software Foundation, either version 3 of the License, or
161+# (at your option) any later version.
162+
163+# This program is distributed in the hope that it will be useful,
164+# but WITHOUT ANY WARRANTY; without even the implied warranty of
165+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
166+# GNU General Public License for more details.
167+
168+# You should have received a copy of the GNU General Public License
169+# along with this program. If not, see <https://www.gnu.org/licenses/>.
170+
171+# Authors: Sergio Durigan Junior <sergio.durigan@canonical.com>
172+
173+from ddebpoller import DdebPoller
174+from debuginfod import grab_ddebs, grab_ddebs_sources
175+
176+from celery import chain
177+
178+def poll_launchpad():
179+ """Poll Launchpad."""
180+ poller = DdebPoller()
181+ for msg in poller.get_ddebs():
182+ # We have to use a chain here because the ddebs need to be
183+ # downloaded before we can start fetching the sources.
184+ chain(grab_ddebs.si(msg), grab_ddebs_sources.si(msg))()
185+
186+if __name__ == '__main__':
187+ poll_launchpad()

Subscribers

People subscribed via source and target branches

to all changes: