From f34ed99a4f896d6dfc39220e49ece6b2bfb1ada9 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 1 May 2020 22:31:33 +0200 Subject: [PATCH] debian: converge packaging between authentic2 and -multitenant packages (#42305) --- debian/{authentic2-ctl => authentic2-manage} | 7 +++- debian/authentic2-multitenant.dirs | 1 - debian/authentic2-multitenant.init | 2 +- debian/authentic2-multitenant.postinst | 1 - debian/authentic2-multitenant.service | 2 +- debian/authentic2.dirs | 5 ++- debian/authentic2.init | 40 ++++++++++---------- debian/authentic2.install | 2 +- debian/authentic2.postinst | 17 ++------- debian/authentic2.service | 27 +++++++++++++ debian/compat | 2 +- debian/control | 9 ++--- debian/debian_config.py | 6 ++- debian/python-authentic2.install | 1 - debian/rules | 9 ++--- rules | 9 ----- 16 files changed, 77 insertions(+), 63 deletions(-) rename debian/{authentic2-ctl => authentic2-manage} (80%) create mode 100644 debian/authentic2.service delete mode 100644 debian/python-authentic2.install delete mode 100755 rules diff --git debian/authentic2-ctl debian/authentic2-manage similarity index 80% rename from debian/authentic2-ctl rename to debian/authentic2-manage index 0143c13c..fcb6984a 100644 --- debian/authentic2-ctl +++ debian/authentic2-manage @@ -1,11 +1,14 @@ #!/bin/sh +NAME="authentic2" +MANAGE="/usr/lib/authentic2/manage.py" + export AUTHENTIC2_SETTINGS_FILE=/usr/share/authentic2/debian_config.py if [ "$(whoami)" != "authentic" ]; then if which sudo >/dev/null; then if sudo -v -u authentic; then - sudo -u authentic authentic2-ctl "$@" + sudo -u authentic authentic2-manage "$@" exit $? fi echo "You must run this script with authentic user" @@ -24,4 +27,4 @@ if [ -f /etc/authentic2/authentic.conf ]; then . /etc/authentic2/authentic.conf fi -/usr/lib/authentic2/manage.py "$@" +python ${MANAGE} "$@" diff --git debian/authentic2-multitenant.dirs debian/authentic2-multitenant.dirs index c05b015b..698fe6e1 100644 --- debian/authentic2-multitenant.dirs +++ debian/authentic2-multitenant.dirs @@ -6,5 +6,4 @@ var/lib/authentic2-multitenant/static var/lib/authentic2-multitenant/collectstatic var/lib/authentic2-multitenant/locale var/lib/authentic2-multitenant/templates -var/run/authentic2-multitenant var/log/authentic2-multitenant diff --git debian/authentic2-multitenant.init debian/authentic2-multitenant.init index 9c6b7b74..d62fd49e 100644 --- debian/authentic2-multitenant.init +++ debian/authentic2-multitenant.init @@ -163,7 +163,7 @@ case "$1" in do_migrate && do_collectstatic log_end_msg $? ;; - restart) + restart|force-reload) # # If the "reload" option is implemented then remove the # 'force-reload' alias diff --git debian/authentic2-multitenant.postinst debian/authentic2-multitenant.postinst index 7fa6e6b4..44509a9b 100644 --- debian/authentic2-multitenant.postinst +++ debian/authentic2-multitenant.postinst @@ -36,7 +36,6 @@ case "$1" in fi chown $AUTHENTIC_USER:$AUTHENTIC_GROUP $AUTHENTIC_HOME/tenants \ /var/lib/$NAME/collectstatic \ - /var/run/$NAME \ /var/log/$NAME /etc/init.d/$NAME update ;; diff --git debian/authentic2-multitenant.service debian/authentic2-multitenant.service index 723e8240..1d274612 100644 --- debian/authentic2-multitenant.service +++ debian/authentic2-multitenant.service @@ -21,7 +21,7 @@ ExecReload=/bin/kill -HUP $MAINPID TimeoutStartSec=0 PrivateTmp=true Restart=on-failure -RuntimeDirectory=authentic2-multitenant +RuntimeDirectory=%p [Install] WantedBy=multi-user.target diff --git debian/authentic2.dirs debian/authentic2.dirs index 9430e6b4..31134cff 100644 --- debian/authentic2.dirs +++ debian/authentic2.dirs @@ -1,8 +1,9 @@ etc/authentic2 -usr/share/dbconfig-common/scripts/authentic2/install +etc/authentic2/settings.d +usr/lib/authentic2 var/lib/authentic2/media var/lib/authentic2/static var/lib/authentic2/collectstatic +var/lib/authentic2/locale var/lib/authentic2/templates -var/run/authentic2 var/log/authentic2 diff --git debian/authentic2.init debian/authentic2.init index cd7645ee..7ac4bbbb 100644 --- debian/authentic2.init +++ debian/authentic2.init @@ -22,9 +22,11 @@ CACHE_DIR=/var/cache/$NAME LOG_DIR=/var/log/$NAME PIDFILE=$PID_DIR/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME -MANAGE_SCRIPT=/usr/bin/$NAME-ctl BIND=unix:$PID_DIR/$NAME.sock -AUTHENTIC2_SETTINGS_FILE=/usr/share/$NAME/debian_config.py +WORKERS=4 + +export AUTHENTIC2_SETTINGS_FILE=/usr/share/$NAME/debian_config.py +MANAGE_SCRIPT=/usr/bin/$NAME-manage USER=authentic GROUP=authentic @@ -41,19 +43,11 @@ DAEMON_ARGS="--pid $PIDFILE \ --access-logfile $LOG_DIR/gunicorn-access.log \ --log-file $LOG_DIR/gunicorn-error.log \ --bind=$BIND \ ---workers=10 \ +--workers=$WORKERS \ --worker-class=sync \ --timeout=60 \ authentic2.wsgi:application" -# Load config -if [ -f /etc/authentic2/db.conf ]; then - . /etc/authentic2/db.conf -fi -if [ -f /etc/authentic2/authentic.conf ]; then - . /etc/authentic2/authentic.conf -fi - # Load the VERBOSE setting and other rcS variables . /lib/init/vars.sh @@ -71,6 +65,21 @@ if [ ! -d $CACHE_DIR ]; then install -d -m 755 -o $USER -g $GROUP $CACHE_DIR fi +# Load old authentic configuration +if [ -f /etc/authentic2/db.conf ]; then + . /etc/authentic2/db.conf +fi +if [ -f /etc/authentic2/authentic.conf ]; then + . /etc/authentic2/authentic.conf +fi + +# Function collecting static files +do_collectstatic() { + log_action_msg "Collect static files.." + su $USER -s /bin/sh -p -c "$MANAGE_SCRIPT collectstatic -l --noinput" + log_action_msg ".. done" +} + # # Function that starts the daemon/service # @@ -138,13 +147,6 @@ do_migrate() { log_action_msg ".. done" } -do_collectstatic() { - log_action_msg "Collecting static files .." - su $USER -p -c "$MANAGE_SCRIPT collectstatic -l --noinput" - log_action_msg ".. done" -} - - case "$1" in start) log_daemon_msg "Starting $DESC " "$NAME" @@ -177,7 +179,7 @@ case "$1" in do_migrate && do_collectstatic log_end_msg $? ;; - restart) + restart|force-reload) log_daemon_msg "Restarting $DESC" "$NAME" do_stop case "$?" in diff --git debian/authentic2.install debian/authentic2.install index a4d2c116..d375daa4 100644 --- debian/authentic2.install +++ debian/authentic2.install @@ -1,5 +1,5 @@ debian/conf/authentic.conf /etc/authentic2 debian/conf/nginx-example.conf /etc/authentic2 debian/sql/db.conf /usr/share/authentic2/templates -debian/authentic2-ctl /usr/bin +debian/authentic2-manage /usr/bin debian/debian_config.py /usr/share/authentic2 diff --git debian/authentic2.postinst debian/authentic2.postinst index ecb33cab..853b4b6e 100644 --- debian/authentic2.postinst +++ debian/authentic2.postinst @@ -65,19 +65,6 @@ case "$1" in /etc/authentic2/authentic.conf >&2 fi - chown -R $AUTHENTIC_USER:$AUTHENTIC_GROUP /var/lib/authentic2/ - - # source dbconfig-common shell library, and call the hook function - if [ -f /usr/share/dbconfig-common/dpkg/postinst.pgsql ]; then - . /usr/share/dbconfig-common/dpkg/postinst.pgsql - dbc_generate_include="template:/etc/authentic2/db.conf" - dbc_generate_include_args="-o template_infile=/usr/share/authentic2/templates/db.conf -U" - dbc_generate_include_owner="root:authentic" - dbc_generate_include_perms="640" - dbc_pgsql_createdb_encoding="UTF8" - dbc_go authentic2 $@ - fi - if [ ! -f /etc/authentic2/cert.pem -a ! -f /etc/authentic2/key.pem ]; then echo -n "Generating key material..." >&2 openssl genpkey -algorithm rsa -pkeyopt rsa_keygen_bits:2048 -out /etc/authentic2/key.pem >&2 @@ -86,6 +73,10 @@ case "$1" in chmod 640 /etc/authentic2/cert.pem /etc/authentic2/key.pem echo "..done" >&2 fi + + chown $AUTHENTIC_USER:$AUTHENTIC_GROUP /var/lib/authentic2/ \ + /var/log/$NAME + /etc/init.d/$NAME update ;; diff --git debian/authentic2.service debian/authentic2.service new file mode 100644 index 00000000..1e491130 --- /dev/null +++ debian/authentic2.service @@ -0,0 +1,27 @@ +[Unit] +Description=Authentic 2 +After=network.target postgresql.service +Wants=postgresql.service + +[Service] +Environment=AUTHENTIC2_SETTINGS_FILE=/usr/lib/%p/debian_config.py +Environment=LANG=C.UTF-8 +User=authentic +Group=authentic +ExecStartPre=/usr/bin/authentic2-manage migrate_schemas --noinput +ExecStartPre=/usr/bin/authentic2-manage collectstatic --noinput +ExecStart=/usr/bin/gunicorn \ + --bind unix:/run/%p/%p.sock \ + --worker-class=sync \ + --workers 5 \ + --timeout=60 \ + --name %p \ + authentic2.wsgi:application +ExecReload=/bin/kill -HUP $MAINPID +TimeoutStartSec=0 +PrivateTmp=true +Restart=on-failure +RuntimeDirectory=%p + +[Install] +WantedBy=multi-user.target diff --git debian/compat debian/compat index ec635144..f599e28b 100644 --- debian/compat +++ debian/compat @@ -1 +1 @@ -9 +10 diff --git debian/control debian/control index cc32bd0b..3e39642e 100644 --- debian/control +++ debian/control @@ -1,12 +1,11 @@ Source: authentic2 Section: python Priority: optional -Maintainer: Jerome Schneider +Maintainer: Benjamin Dauvergne Build-Depends-Indep: python-all-dev (>= 2.6) -Build-Depends: debhelper (>= 9.0), python-setuptools, python-django (>= 1.5), dh-python, dh-systemd -Standards-Version: 3.8.3 -Homepage: http://authentic.labs.libre-entreprise.org -X-Python-Version: >= 2.7 +Build-Depends: debhelper (>= 9.0), python-setuptools, python-django (>= 1:1.11), dh-python, dh-systemd +Standards-Version: 3.9.6 +Homepage: http://dev.entrouvert.org/projects/authentic/ Package: python-authentic2 Architecture: all diff --git debian/debian_config.py debian/debian_config.py index a71d7f57..13a4969d 100644 --- debian/debian_config.py +++ debian/debian_config.py @@ -1,7 +1,9 @@ +import glob import os import warnings from authentic2 import logger +ETC_DIR = '/etc/authentic2/' # Add the XForwardedForMiddleware MIDDLEWARE = ('authentic2.middleware.XForwardedForMiddleware',) + MIDDLEWARE @@ -118,7 +120,6 @@ LOGGING = { # Old settings method def extract_settings_from_environ(): - import os import json from django.core.exceptions import ImproperlyConfigured global MANAGERS, DATABASES, SENTRY_TRANSPORT, SENTRY_DSN, INSTALLED_APPS, \ @@ -299,3 +300,6 @@ if os.path.exists(CONFIG_FILE): # Warn if DEFAULT_FROM_EMAIL is the default value if DEFAULT_FROM_EMAIL == 'webmaster@localhost': warnings.warn('DEFAULT_FROM_EMAIL must be customized') + +for filename in sorted(glob.glob(os.path.join(ETC_DIR, 'settings.d', '*.py'))): + exec(open(filename).read()) diff --git debian/python-authentic2.install debian/python-authentic2.install deleted file mode 100644 index 2964de61..00000000 --- debian/python-authentic2.install +++ /dev/null @@ -1 +0,0 @@ -usr/lib/ diff --git debian/rules debian/rules index be98d884..50a78616 100755 --- debian/rules +++ debian/rules @@ -1,12 +1,11 @@ #!/usr/bin/make -f -authentic2=$(CURDIR)/debian/authentic2 -pythonauthentic2=$(CURDIR)/debian/python-authentic2 +export PYBUILD_NAME=authentic2 +export PYBUILD_DISABLE=test %: - dh $@ --with python2,systemd + dh $@ --with python2,systemd --buildsystem=pybuild override_dh_install: dh_install - mv $(CURDIR)/debian/tmp/usr/bin/authentic2-ctl $(pythonauthentic2)/usr/lib/authentic2/manage.py - + mv $(CURDIR)/debian/python-authentic2/usr/bin/authentic2-ctl $(CURDIR)/debian/python-authentic2/usr/lib/authentic2/manage.py diff --git rules rules deleted file mode 100755 index 447dee0c..00000000 --- rules +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/make -f - -# This file was automatically generated by stdeb 0.6.0+git at -# Fri, 14 Jun 2013 17:33:52 +0200 - -%: - dh $@ --with python2 --buildsystem=python_distutils - - -- 2.26.0