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
diff --git a/conf/ubuntu-debuginfod-celery.default b/conf/ubuntu-debuginfod-celery.default
0new file mode 1006440new file mode 100644
index 0000000..9f915b0
--- /dev/null
+++ b/conf/ubuntu-debuginfod-celery.default
@@ -0,0 +1,12 @@
1# App instance to use.
2CELERY_APP="debuginfod"
3
4# Extra command-line arguments to the worker.
5#
6# We chose 6 workers here because it seemed like a good compromise
7# between not hammering the network and processing as many things in
8# parallel as possible.
9CELERYD_OPTS="--concurrency=6"
10
11# Log level to use.
12CELERYD_LOG_LEVEL="INFO"
diff --git a/conf/ubuntu-debuginfod-celery.service b/conf/ubuntu-debuginfod-celery.service
0new file mode 10064413new file mode 100644
index 0000000..f9331ce
--- /dev/null
+++ b/conf/ubuntu-debuginfod-celery.service
@@ -0,0 +1,26 @@
1[Unit]
2Description=Ubuntu Debuginfod Celery
3After=network.target rabbitmq-server.service
4Requires=rabbitmq-server.service
5
6[Service]
7Type=notify
8User=mirror
9Group=mirror
10EnvironmentFile=/etc/default/ubuntu-debuginfod-celery
11WorkingDirectory=/home/mirror/ubuntu-debuginfod/
12ExecStart=/usr/bin/celery -A ${CELERY_APP} worker --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}
13Restart=always
14TimeoutStopSec=600
15PrivateDevices=true
16PrivateUsers=true
17ProtectKernelTunables=true
18ProtectControlGroups=true
19ProtectKernelLogs=true
20ProtectKernelModules=true
21MemoryDenyWriteExecute=true
22RestrictRealtime=true
23ReadWritePaths=/srv/debug-mirror/
24
25[Install]
26WantedBy=multi-user.target
diff --git a/conf/ubuntu-debuginfod-poll-lp.service b/conf/ubuntu-debuginfod-poll-lp.service
0new file mode 10064427new file mode 100644
index 0000000..5c9e13a
--- /dev/null
+++ b/conf/ubuntu-debuginfod-poll-lp.service
@@ -0,0 +1,23 @@
1[Unit]
2Description=Poll Launchpad for new ddebs
3After=network.target ubuntu-debuginfod-celery.service
4Requires=ubuntu-debuginfod-celery.service
5
6[Service]
7Type=oneshot
8User=mirror
9Group=mirror
10WorkingDirectory=/home/mirror/ubuntu-debuginfod/
11ExecStart=/usr/bin/python3 /home/mirror/ubuntu-debuginfod/poll_launchpad.py
12PrivateDevices=true
13PrivateUsers=true
14ProtectKernelTunables=true
15ProtectControlGroups=true
16ProtectKernelLogs=true
17ProtectKernelModules=true
18MemoryDenyWriteExecute=true
19RestrictRealtime=true
20ReadWritePaths=/home/mirror/.config/ubuntu-debuginfod/
21
22[Install]
23WantedBy=multi-user.target
diff --git a/conf/ubuntu-debuginfod-poll-lp.timer b/conf/ubuntu-debuginfod-poll-lp.timer
0new file mode 10064424new file mode 100644
index 0000000..c61fdcb
--- /dev/null
+++ b/conf/ubuntu-debuginfod-poll-lp.timer
@@ -0,0 +1,10 @@
1[Unit]
2Description=Poll Launchpad for new ddebs
3
4[Timer]
5# Every 30 minutes
6OnCalendar=*:0/30
7Persistent=true
8
9[Install]
10WantedBy=timers.target
diff --git a/debuginfod.py b/debuginfod.py
index d64efd4..c0d0357 100644
--- a/debuginfod.py
+++ b/debuginfod.py
@@ -18,11 +18,14 @@
18# Authors: Sergio Durigan Junior <sergio.durigan@canonical.com>18# Authors: Sergio Durigan Junior <sergio.durigan@canonical.com>
1919
20from celery import Celery20from celery import Celery
21from celery.signals import worker_ready, worker_shutting_down
2122
22from debuggetter import DebugGetterTimeout, DebugGetterRetry23from debuggetter import DebugGetterTimeout, DebugGetterRetry
2324
24from ddebgetter import DdebGetter, DdebSourceCodeGetter25from ddebgetter import DdebGetter, DdebSourceCodeGetter
2526
27import sdnotify
28
26app = Celery("debuginfod", broker="pyamqp://guest@localhost//")29app = Celery("debuginfod", broker="pyamqp://guest@localhost//")
2730
28app.conf.update(31app.conf.update(
@@ -34,9 +37,13 @@ app.conf.update(
34 task_acks_late=True,37 task_acks_late=True,
35 # Only one task per worker.38 # Only one task per worker.
36 worker_prefetch_multiplier=1,39 worker_prefetch_multiplier=1,
37 worker_log_format="[%(asctime)s: %(levelname)s/%(processName)s] %(funcName)s: %(message)s",40 # Rewrite the log format. We will most likely be running under
41 # systemd, which already includes a timestamp on every log line.
42 worker_log_format="[%(levelname)s/%(processName)s] %(funcName)s: %(message)s",
38)43)
3944
45sdnotifier = sdnotify.SystemdNotifier()
46
4047
41@app.task(48@app.task(
42 name="grab_ddebs",49 name="grab_ddebs",
@@ -76,5 +83,17 @@ def grab_ddebs_sources(msg):
76 g.process_request(msg)83 g.process_request(msg)
7784
7885
86@worker_ready.connect
87def notify_worker_ready(**kwargs):
88 """Notify systemd that the worker initialization has finished."""
89 sdnotifier.notify("READY=1")
90
91
92@worker_shutting_down.connect
93def notify_worker_shutting_down(**kwargs):
94 """Notify systemd that the worker will start its process to shut down."""
95 sdnotifier.notify("STOPPING=1")
96
97
79if __name__ == "__main__":98if __name__ == "__main__":
80 app.start()99 app.start()
diff --git a/poll_launchpad.py b/poll_launchpad.py
81new file mode 100644100new file mode 100644
index 0000000..161aa77
--- /dev/null
+++ b/poll_launchpad.py
@@ -0,0 +1,34 @@
1#!/usr/bin/python3
2
3# Copyright (C) 2022 Canonical Ltd.
4
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <https://www.gnu.org/licenses/>.
17
18# Authors: Sergio Durigan Junior <sergio.durigan@canonical.com>
19
20from ddebpoller import DdebPoller
21from debuginfod import grab_ddebs, grab_ddebs_sources
22
23from celery import chain
24
25def poll_launchpad():
26 """Poll Launchpad."""
27 poller = DdebPoller()
28 for msg in poller.get_ddebs():
29 # We have to use a chain here because the ddebs need to be
30 # downloaded before we can start fetching the sources.
31 chain(grab_ddebs.si(msg), grab_ddebs_sources.si(msg))()
32
33if __name__ == '__main__':
34 poll_launchpad()

Subscribers

People subscribed via source and target branches

to all changes: