debian: adapt packaging to django switch (#6735)

This commit is contained in:
Frédéric Péters 2017-08-11 11:23:05 +02:00
parent 8491962406
commit 3e998dff21
15 changed files with 419 additions and 143 deletions

2
debian/compat vendored
View File

@ -1 +1 @@
5
9

28
debian/control vendored
View File

@ -2,16 +2,32 @@ Source: wcs
Section: web
Priority: optional
Maintainer: Frederic Peters <fpeters@debian.org>
Build-Depends: python-support (>= 0.4), python-quixote, debhelper (>= 8.0.0), gettext, python-gadjo, libjs-leaflet
Standards-Version: 3.6.7.0
Homepage: http://wcs.labs.libre-entreprise.org
Build-Depends: python-quixote, debhelper (>= 9), dh-python, dh-systemd, python-setuptools, gettext, python-gadjo, libjs-leaflet
Standards-Version: 3.9.6.0
Homepage: https://dev.entrouvert.org/projects/wcs/
X-Python-Version: 2.7
Package: wcs
Architecture: all
Depends: ${python:Depends}, python-quixote, python-scgi, graphviz, python-feedparser, python-imaging, python-vobject
Recommends: python-dns, python-xlwt, python-qrcode, libjs-leaflet, python-magic
Suggests: libapache2-mod-scgi | libapache-mod-scgi, python-libxml2, python-lasso, python-psycopg2
Depends: ${misc:Depends}, ${python:Depends},
python-django (>= 1.8),
python-quixote,
python-hobo,
python-scgi,
graphviz,
python-feedparser,
python-imaging,
python-vobject,
uwsgi,
uwsgi-plugin-python
Recommends: python-dns,
python-xlwt,
python-qrcode,
libjs-leaflet,
python-magic
Suggests: python-libxml2,
python-lasso,
python-psycopg2
Description: web application to design and set up online forms
w.c.s. is a web application which allows to design and set up online forms.
.

18
debian/debian_config.py vendored Normal file
View File

@ -0,0 +1,18 @@
# This file is sourced by "execfile" from wcs.settings
import os
PROJECT_NAME = 'wcs'
#
# hobotization
#
execfile('/usr/lib/hobo/debian_config_common.py')
#
# local settings
#
execfile(os.path.join(ETC_DIR, 'settings.py'))
# run additional settings snippets
execfile('/usr/lib/hobo/debian_config_settings_d.py')

3
debian/dirs vendored
View File

@ -1,3 +0,0 @@
etc/apache2/sites-available
usr/sbin
var/lib/wcs

42
debian/postinst vendored
View File

@ -1,42 +0,0 @@
#!/bin/sh
set -e
NAME=wcs
DAEMON=/usr/sbin/wcsctl
WCS_USER=www-data
CONFIG_FILE=/etc/wcs/wcs.cfg
# Read config file if it is present.
if [ -r /etc/default/$NAME ]
then
. /etc/default/$NAME
fi
if [ $CONFIG_FILE ]; then
COMMAND="$DAEMON -f $CONFIG_FILE"
else
COMMAND="$DAEMON"
fi
case "$1" in
configure)
;;
triggered)
su -s /bin/sh -c "$COMMAND hobo_deploy --redeploy" $WCS_USER
exit 0
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
#DEBHELPER#
exit 0

16
debian/rules vendored
View File

@ -5,21 +5,13 @@
#export DH_VERBOSE=1
%:
dh $@ --with python2
override_dh_clean:
dh_clean
rm -rf po/*.mo
dh $@ --with python2,systemd
override_dh_install:
dh_install
mv $(CURDIR)/debian/wcs/usr/bin/wcsctl.py \
$(CURDIR)/debian/wcs/usr/sbin/wcsctl
rmdir $(CURDIR)/debian/wcs/usr/bin/
cd po && make install prefix=$(CURDIR)/debian/wcs/
chown www-data.www-data $(CURDIR)/debian/wcs/var/lib/wcs/
$(CURDIR)/debian/wcs/usr/bin/wcsctl
mv $(CURDIR)/debian/wcs/usr/bin/manage.py \
$(CURDIR)/debian/wcs/usr/lib/wcs/
install -d $(CURDIR)/debian/wcs/etc/wcs
install -m 644 wcs.cfg-sample $(CURDIR)/debian/wcs/etc/wcs/wcs.cfg
override_dh_fixperms:
dh_fixperms -X /var/lib/wcs

73
debian/settings.py vendored Normal file
View File

@ -0,0 +1,73 @@
# Configuration for w.c.s.
# You can override default settings here
# w.c.s. is a Django application: for the full list of settings and their
# values, see https://docs.djangoproject.com/en/1.8/ref/settings/
# For more information on settings see
# https://docs.djangoproject.com/en/1.8/topics/settings/
# WARNING! Check settings before production use:
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
# This file is sourced by "execfile" from /usr/lib/combo/debian_config.py
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
TEMPLATE_DEBUG = False
#ADMINS = (
# # ('User 1', 'watchdog@example.net'),
# # ('User 2', 'janitor@example.net'),
#)
# ALLOWED_HOSTS must be correct in production!
# See https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts
ALLOWED_HOSTS = [
'*',
]
# Databases
# Default: a local database named "combo"
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
# Warning: don't change ENGINE
# DATABASES['default']['NAME'] = 'combo'
# DATABASES['default']['USER'] = 'combo'
# DATABASES['default']['PASSWORD'] = '******'
# DATABASES['default']['HOST'] = 'localhost'
# DATABASES['default']['PORT'] = '5432'
LANGUAGE_CODE = 'fr-fr'
TIME_ZONE = 'Europe/Paris'
# Email configuration
# EMAIL_SUBJECT_PREFIX = '[combo] '
# SERVER_EMAIL = 'root@combo.example.org'
# DEFAULT_FROM_EMAIL = 'webmaster@combo.example.org'
# SMTP configuration
# EMAIL_HOST = 'localhost'
# EMAIL_HOST_USER = ''
# EMAIL_HOST_PASSWORD = ''
# EMAIL_PORT = 25
# HTTPS Security
# CSRF_COOKIE_SECURE = True
# SESSION_COOKIE_SECURE = True
TEMPLATE_CONTEXT_PROCESSORS = ('django.core.context_processors.request',
'hobo.context_processors.template_vars',
'hobo.context_processors.theme_base') + TEMPLATE_CONTEXT_PROCESSORS
if not 'MIDDLEWARE_CLASSES' in globals():
MIDDLEWARE_CLASSES = global_settings.MIDDLEWARE_CLASSES
MIDDLEWARE_CLASSES = (
'hobo.middleware.utils.StoreRequestMiddleware',
'hobo.middleware.xforwardedfor.XForwardedForMiddleware',
'hobo.middleware.VersionMiddleware', # /__version__
'hobo.middleware.cors.CORSMiddleware',
) + MIDDLEWARE_CLASSES
WCS_LEGACY_CONFIG_FILE = '/etc/wcs/wcs.cfg'
WCS_EXTRA_MODULES = []

25
debian/wcs-manage vendored Executable file
View File

@ -0,0 +1,25 @@
#!/bin/sh
NAME=wcs
MANAGE=/usr/lib/$NAME/manage.py
# load Debian default configuration
export WCS_SETTINGS_FILE=/usr/lib/$NAME/debian_config.py
# check user
if test x$1 = x"--forceuser"
then
shift
elif test $(id -un) != "$NAME"
then
echo "error: must use $0 with user ${NAME}"
exit 1
fi
if test $# -eq 0
then
python ${MANAGE} help
exit 1
fi
python ${MANAGE} "$@"

6
debian/wcs.dirs vendored Normal file
View File

@ -0,0 +1,6 @@
etc/wcs
usr/sbin
usr/lib/wcs
var/lib/wcs
var/lib/wcs/collectstatic
var/log/wcs

239
debian/wcs.init vendored
View File

@ -3,106 +3,199 @@
# Provides: wcs
# Required-Start: $network $local_fs $remote_fs $syslog
# Required-Stop: $network $local_fs $remote_fs $syslog
# Should-Start: postgresql
# Should-Stop: postgresql
# Should-start: postgresql
# Should-stop: postgresql
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start w.c.s. web form manager
# Description: Start w.c.s. web form manager
# Short-Description: Web Forms Manager
# Description: Web Forms Manager
### END INIT INFO
# Author: Entr'ouvert <info@entrouvert.com>
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="wcs"
DESC="Web Forms Manager"
NAME=wcs
DAEMON=/usr/sbin/wcsctl
PIDFILE=/var/run/$NAME.pid
WCSCTL=/usr/bin/wcsctl
DAEMON=/usr/bin/uwsgi
RUN_DIR=/run/$NAME
PIDFILE=$RUN_DIR/$NAME.pid
LOG_DIR=/var/log/$NAME
SCRIPTNAME=/etc/init.d/$NAME
WCS_USER=www-data
WCS_GROUP=www-data
BIND=$RUN_DIR/$NAME.sock
WORKERS=5
TIMEOUT=30
CONFIG_FILE=/etc/wcs/wcs.cfg
WCS_SETTINGS_FILE=/usr/lib/$NAME/debian_config.py
MANAGE_SCRIPT="/usr/bin/$NAME-manage"
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
USER=$NAME
GROUP=$NAME
# Read config file if it is present.
if [ -r /etc/default/$NAME ]
then
. /etc/default/$NAME
# Exit if the package is not installed
[ -x $MANAGE_SCRIPT ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
DAEMON_ARGS=${DAEMON_ARGS:-"--pidfile=$PIDFILE \
--uid $USER \
--gid $GROUP \
--http-socket $BIND \
--chmod-socket=666 \
--processes $WORKERS \
--harakiri $TIMEOUT \
--enable-threads \
--plugin python \
--buffer-size 32768 \
--vacuum \
--master \
--module $NAME.wsgi:application \
--daemonize /var/log/uwsgi.wss.log
"}
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
# Create /run directory
if [ ! -d $RUN_DIR ]; then
install -d -m 775 -o $USER -g $GROUP $RUN_DIR
fi
# environment for wsgi
export WCS_SETTINGS_FILE
#
# Function that starts the daemon/service.
# Function that starts the daemon/service
#
d_start() {
if [ $CONFIG_FILE ]; then
$DAEMON -f $CONFIG_FILE collectstatic
start-stop-daemon --start --quiet --pidfile $PIDFILE \
--chuid $WCS_USER:$WCS_GROUP --make-pidfile --background \
--exec $DAEMON -- -f $CONFIG_FILE start $OPTIONS
else
$DAEMON collectstatic
start-stop-daemon --start --quiet --pidfile $pidfile \
--chuid $WCS_USER:$WCS_GROUP --make-pidfile --background \
--exec $DAEMON -- start $OPTIONS
fi
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --exec $DAEMON -- \
$DAEMON_ARGS \
|| return 2
}
#
# Function that stops the daemon/service.
# Function that stops the daemon/service
#
d_stop() {
start-stop-daemon --stop --quiet --pidfile $PIDFILE
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
# and if the daemon is only ever run from this initscript.
# If the above conditions are not satisfied then add some other code
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
}
#
# Function that sends a SIGHUP to the daemon/service.
# Function that sends a SIGHUP to the daemon/service
#
d_reload() {
start-stop-daemon --stop --quiet --pidfile $PIDFILE \
--make-pidfile --background --signal 1
do_reload() {
#
# If the daemon can reload its configuration without
# restarting (for example, when it is sent a SIGHUP),
# then implement that here.
#
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name `basename $DAEMON`
return 0
}
do_migrate() {
log_action_msg "Applying migrations.."
su $USER -s /bin/sh -p -c "$MANAGE_SCRIPT migrate"
log_action_msg "done"
}
do_collectstatic() {
log_action_msg "Collect static files (collectstatic).."
su $USER -s /bin/sh -p -c "$MANAGE_SCRIPT collectstatic"
log_action_msg "done"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
log_daemon_msg "Starting $DESC " "$NAME"
do_migrate
do_collectstatic
do_start
case "$?" in
0|1) log_end_msg 0 ;;
2) log_end_msg 1 ;;
esac
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
#reload)
#
# If the daemon can reload its configuration without
# restarting (for example, when it is sent a SIGHUP),
# then implement that here.
#
# If the daemon responds to changes in its config file
# directly anyway, make this an "exit 0".
#
# echo -n "Reloading $DESC configuration..."
# d_reload
# echo "done."
#;;
log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) log_end_msg 0 ;;
2) log_end_msg 1 ;;
esac
;;
status)
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
;;
reload|force-reload)
#
# If do_reload() is not implemented then leave this commented out
# and leave 'force-reload' as an alias for 'restart'.
#
log_daemon_msg "Reloading $DESC" "$NAME"
do_reload
log_end_msg $?
;;
restart|force-reload)
#
# If the "reload" option is implemented, move the "force-reload"
# option to the "reload" entry above. If not, "force-reload" is
# just the same as "restart".
#
echo -n "Restarting $DESC: $NAME"
d_stop
sleep 1
d_start
echo "."
;;
#
# If the "reload" option is implemented then remove the
# 'force-reload' alias
#
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_migrate
do_collectstatic
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
# echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 1
;;
echo "Usage: $SCRIPTNAME {start|stop|status|restart|reload|force-reload}" >&2
exit 3
;;
esac
exit 0

3
debian/wcs.install vendored Normal file
View File

@ -0,0 +1,3 @@
debian/wcs-manage /usr/bin
debian/settings.py /etc/wcs
debian/debian_config.py /usr/lib/wcs

65
debian/wcs.postinst vendored Normal file
View File

@ -0,0 +1,65 @@
#!/bin/sh
set -e
NAME=wcs
DAEMON=/usr/bin/wcsctl
USER=$NAME
GROUP=$NAME
CONFIG_DIR=/etc/wcs
CONFIG_FILE=/etc/wcs/wcs.cfg
# Read config file if it is present.
if [ -r /etc/default/$NAME ]
then
. /etc/default/$NAME
fi
if [ $CONFIG_FILE ]; then
COMMAND="$DAEMON -f $CONFIG_FILE"
else
COMMAND="$DAEMON"
fi
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/log/$NAME
chown $USER:$GROUP /var/lib/$NAME
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
;;
triggered)
su -s /bin/sh -c "$COMMAND hobo_deploy --redeploy" $USER
exit 0
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
#DEBHELPER#
exit 0

33
debian/wcs.service vendored Normal file
View File

@ -0,0 +1,33 @@
[Unit]
Description=w.c.s.
After=network.target syslog.target postgresql.service
Wants=postgresql.service
[Service]
Environment=WCS_SETTINGS_FILE=/usr/lib/%p/debian_config.py
User=%p
Group=%p
ExecStartPre=/usr/bin/wcs-manage migrate
ExecStartPre=/usr/bin/wcs-manage collectstatic
ExecStart=/usr/bin/uwsgi \
--http-socket /run/%p/%p.sock \
--chmod-socket=666 \
--processes 5 \
--harakiri 30 \
--enable-threads \
--plugin python \
--buffer-size 32768 \
--vacuum \
--master \
--module %p.wsgi:application
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGQUIT
PrivateTmp=true
Restart=on-failure
RuntimeDirectory=wcs
Type=notify
StandardError=syslog
NotifyAccess=all
[Install]
WantedBy=multi-user.target

View File

@ -8,7 +8,7 @@ from distutils.cmd import Command
from distutils.command.build import build as _build
from distutils.command.sdist import sdist
from setuptools.command.install_lib import install_lib as _install_lib
from setuptools import setup
from setuptools import setup, find_packages
local_cfg = None
if os.path.exists('wcs/wcs_cfg.py'):
@ -108,12 +108,9 @@ setup(
url = "http://wcs.labs.libre-entreprise.org",
install_requires=['gadjo'],
package_dir = { 'wcs': 'wcs' },
packages = ['wcs', 'wcs.admin', 'wcs.backoffice', 'wcs.ctl',
'wcs.ctl.Bouncers', 'wcs.forms', 'wcs.wf', 'wcs.qommon',
'wcs.qommon.admin', 'wcs.qommon.backoffice', 'wcs.qommon.ident',
'wcs.qommon.vendor'],
packages = find_packages(),
cmdclass = cmdclass,
scripts = ['wcsctl.py'],
scripts = ['wcsctl.py', 'manage.py'],
include_package_data=True,
data_files = data_tree('share/wcs/web/', 'data/web/') + \
data_tree('share/wcs/themes/', 'data/themes/') + \