From 39153b2877889b9c90febac5a9d5eae371eee78d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 1 Jun 2021 10:33:02 +0200 Subject: [PATCH] add debian packaging --- debian/changelog | 5 ++++ debian/compat | 1 + debian/control | 15 ++++++++++ debian/debian_config.py | 18 ++++++++++++ debian/pfwb-archives-proxy.dirs | 3 ++ debian/pfwb-archives-proxy.install | 5 ++++ debian/pfwb-archives-proxy.postinst | 43 +++++++++++++++++++++++++++ debian/pfwb-archives-proxy.service | 22 ++++++++++++++ debian/rules | 12 ++++++++ debian/settings.py | 5 ++++ debian/source/format | 1 + debian/uwsgi.ini | 45 +++++++++++++++++++++++++++++ 12 files changed, 175 insertions(+) create mode 100644 debian/changelog create mode 100644 debian/compat create mode 100644 debian/control create mode 100644 debian/debian_config.py create mode 100644 debian/pfwb-archives-proxy.dirs create mode 100644 debian/pfwb-archives-proxy.install create mode 100644 debian/pfwb-archives-proxy.postinst create mode 100644 debian/pfwb-archives-proxy.service create mode 100755 debian/rules create mode 100644 debian/settings.py create mode 100644 debian/source/format create mode 100644 debian/uwsgi.ini diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..2872325 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +pfwb-archives-proxy (0-0) unstable; urgency=low + + * initial packaging. + + -- Frederic Peters Tue, 01 Jun 2021 10:31:29 +0200 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..f599e28 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +10 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..460ae6a --- /dev/null +++ b/debian/control @@ -0,0 +1,15 @@ +Source: pfwb-archives-proxy +Maintainer: Frederic Peters +Section: python +Priority: optional +Build-Depends: debhelper (>= 10), + dh-python, + python3-all, + python3-django, + python3-setuptools +Standards-Version: 3.9.1 + +Package: pfwb-archives-proxy +Architecture: all +Depends: uwsgi, uwsgi-plugin-python3, ${misc:Depends}, ${python3:Depends} +Description: Proxy to PFWB archives diff --git a/debian/debian_config.py b/debian/debian_config.py new file mode 100644 index 0000000..ea6bf69 --- /dev/null +++ b/debian/debian_config.py @@ -0,0 +1,18 @@ +import glob +import itertools +import os + +ADMINS = (('admin', 'root@localhost'),) +DEBUG = False +ALLOWED_HOSTS = ['*'] + +ETC_DIR = '/etc/pfwb-archives-proxy' + +with open(os.path.join(ETC_DIR, 'secret')) as fd: + SECRET_KEY = fd.read() + +for filename in itertools.chain( + [os.path.join(ETC_DIR, 'settings.py')], sorted(glob.glob(os.path.join(ETC_DIR, 'settings.d', '*.py'))) +): + with open(filename) as fd: + exec(fd.read()) diff --git a/debian/pfwb-archives-proxy.dirs b/debian/pfwb-archives-proxy.dirs new file mode 100644 index 0000000..945c51b --- /dev/null +++ b/debian/pfwb-archives-proxy.dirs @@ -0,0 +1,3 @@ +/etc/pfwb-archives-proxy +/etc/pfwb-archives-proxy/settings.d +/usr/lib/pfwb-archives-proxy diff --git a/debian/pfwb-archives-proxy.install b/debian/pfwb-archives-proxy.install new file mode 100644 index 0000000..dea40d6 --- /dev/null +++ b/debian/pfwb-archives-proxy.install @@ -0,0 +1,5 @@ +debian/debian_config.py /usr/lib/pfwb-archives-proxy +debian/pfwb-archives-proxy-manage /usr/bin +debian/pfwb-archives-proxy.service /lib/systemd/system +debian/settings.py /etc/pfwb-archives-proxy +debian/uwsgi.ini /etc/pfwb-archives-proxy diff --git a/debian/pfwb-archives-proxy.postinst b/debian/pfwb-archives-proxy.postinst new file mode 100644 index 0000000..8c14304 --- /dev/null +++ b/debian/pfwb-archives-proxy.postinst @@ -0,0 +1,43 @@ +#! /bin/sh + +set -e + +NAME="pfwb-archives-proxy" +USER=$NAME +GROUP=$NAME +CONFIG_DIR="/etc/$NAME" +MANAGE_SCRIPT="/usr/bin/$NAME-manage" + +case "$1" in + configure) + + # make sure the administrative user exists + if ! getent passwd $USER >/dev/null; then + adduser --disabled-password --quiet --system \ + --no-create-home --home /var/lib/$NAME \ + --gecos "$NAME user" --group $USER + fi + # ensure dirs ownership + chown $USER:$GROUP /var/lib/$NAME/collectstatic + # create a secret file + SECRET_FILE=$CONFIG_DIR/secret + if [ ! -f $SECRET_FILE ]; then + echo -n "Generating Django secret..." >&2 + cat /dev/urandom | tr -dc [:alnum:]-_\!\%\^:\; | head -c70 > $SECRET_FILE + chown root:$GROUP $SECRET_FILE + chmod 0440 $SECRET_FILE + fi + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +#DEBHELPER# + +exit 0 diff --git a/debian/pfwb-archives-proxy.service b/debian/pfwb-archives-proxy.service new file mode 100644 index 0000000..95192b3 --- /dev/null +++ b/debian/pfwb-archives-proxy.service @@ -0,0 +1,22 @@ +[Unit] +Description=PFWB Archives Proxy +After=network.target syslog.target + +[Service] +Environment=PFWB_ARCHIVES_PROXY_SETTINGS_FILE=/usr/lib/%p/debian_config.py +Environment=LANG=C.UTF-8 +User=%p +Group=%p +ExecStart=/usr/bin/uwsgi --ini /etc/%p/uwsgi.ini +ExecReload=/bin/kill -HUP $MAINPID +KillSignal=SIGQUIT +TimeoutStartSec=0 +PrivateTmp=true +Restart=on-failure +RuntimeDirectory=pfwb-archives-proxy +Type=notify +StandardError=syslog +NotifyAccess=all + +[Install] +WantedBy=multi-user.target diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..1476654 --- /dev/null +++ b/debian/rules @@ -0,0 +1,12 @@ +#!/usr/bin/make -f + +export PYBUILD_NAME=pfwb-archives-proxy + +%: + dh $@ --with python3 --buildsystem=pybuild + +override_dh_install: + dh_install + mv $(CURDIR)/debian/pfwb-archives-proxy/usr/bin/manage.py $(CURDIR)/debian/pfwb-archives-proxy/usr/lib/pfwb-archives-proxy/manage.py + +override_dh_auto_test: diff --git a/debian/settings.py b/debian/settings.py new file mode 100644 index 0000000..a0b1587 --- /dev/null +++ b/debian/settings.py @@ -0,0 +1,5 @@ +# Configuration for pfwb-archives-proxy +# additional snippets can be dropped in /etc/pfwb-archives-proxy/settings.d/ + +LANGUAGE_CODE = 'fr-fr' +TIME_ZONE = 'Europe/Brussels' diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..163aaf8 --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/debian/uwsgi.ini b/debian/uwsgi.ini new file mode 100644 index 0000000..9a0e4ac --- /dev/null +++ b/debian/uwsgi.ini @@ -0,0 +1,45 @@ +[uwsgi] +auto-procname = true +procname-prefix-spaced = pfwb-archives-proxy +strict = true + +plugin = python3 +single-interpreter = true +module = pfwb_archives_proxy.wsgi:application +need-app = true + +http-socket = /run/pfwb-archives-proxy/pfwb-archives-proxy.sock +chmod-socket = 666 +vacuum = true + +master = true +enable-threads = true +harakiri = 120 + +processes = 500 + +plugin = cheaper_busyness +cheaper-algo = busyness +cheaper = 5 +cheaper-initial = 10 +cheaper-overload = 5 +cheaper-step = 10 +cheaper-busyness-multiplier = 30 +cheaper-busyness-min = 20 +cheaper-busyness-max = 70 +cheaper-busyness-backlog-alert = 16 +cheaper-busyness-backlog-step = 2 + +max-requests = 500 +max-worker-lifetime = 7200 + +buffer-size = 32768 + +py-tracebacker = /run/pfwb-archives-proxy/py-tracebacker.sock. +stats = /run/pfwb-archives-proxy/stats.sock + +ignore-sigpipe = true + +if-file = /etc/pfwb-archives-proxy/uwsgi-local.ini + include = /etc/pfwb-archives-proxy/uwsgi-local.ini +endif =