debian: use uwsgi (#38507)
This commit is contained in:
parent
e49e51a9e5
commit
5d1aaaa357
|
@ -18,8 +18,8 @@ fi
|
|||
|
||||
if test $# -eq 0
|
||||
then
|
||||
python ${MANAGE} help
|
||||
python3 ${MANAGE} help
|
||||
exit 1
|
||||
fi
|
||||
|
||||
python ${MANAGE} "$@"
|
||||
python3 ${MANAGE} "$@"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/etc/default
|
||||
/etc/barbacompta
|
||||
/etc/barbacompta/settings.d
|
||||
/usr/lib/barbacompta
|
||||
/var/lib/barbacompta
|
||||
/var/lib/barbacompta/collected-static
|
|
@ -0,0 +1,4 @@
|
|||
debian/barbacompta-manage /usr/bin
|
||||
debian/config.py /etc/barbacompta
|
||||
debian/uwsgi.ini /etc/barbacompta
|
||||
debian/barbacompta.service /lib/systemd/system
|
|
@ -11,18 +11,16 @@ User=%p
|
|||
Group=%p
|
||||
ExecStartPre=/usr/bin/barbacompta-manage migrate --noinput
|
||||
ExecStartPre=/usr/bin/barbacompta-manage collectstatic --noinput
|
||||
ExecStart=/usr/bin/gunicorn \
|
||||
--bind unix:/run/%p/%p.sock \
|
||||
--worker-class=sync \
|
||||
--workers 5 \
|
||||
--timeout=30 \
|
||||
--name %p \
|
||||
eo_gestion.wsgi:application
|
||||
ExecStart=/usr/bin/uwsgi --ini /etc/%p/uwsgi.ini
|
||||
ExecReload=/bin/kill -HUP $MAINPID
|
||||
KillSignal=SIGQUIT
|
||||
TimeoutStartSec=0
|
||||
PrivateTmp=true
|
||||
Restart=on-failure
|
||||
RuntimeDirectory=barbacompta
|
||||
Type=notify
|
||||
StandardError=syslog
|
||||
NotifyAccess=all
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
|
|
@ -5,70 +5,35 @@
|
|||
# WARNING! Quick-start development settings unsuitable for production!
|
||||
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
|
||||
|
||||
# Set default path
|
||||
import glob
|
||||
import os
|
||||
|
||||
# Set default path
|
||||
VAR_DIR = '/var/lib/barbacompta'
|
||||
STATIC_ROOT = os.path.join(VAR_DIR, 'collected-static')
|
||||
MEDIA_ROOT = os.path.join(VAR_DIR, 'media')
|
||||
ETC_DIR = '/etc/barbacompta/'
|
||||
|
||||
SECRET_KEY = file('/etc/barbacompta/secret').read()
|
||||
with open("/etc/barbacompta/secret") as fd:
|
||||
SECRET_KEY = fd.read()
|
||||
|
||||
DEBUG = False
|
||||
|
||||
ADMINS = (('Benjamin Dauvergne', 'bdauvergne@entrouvert.com'),)
|
||||
|
||||
# ALLOWED_HOSTS must be correct in production!
|
||||
# See https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts
|
||||
ALLOWED_HOSTS = [
|
||||
'gestion.entrouvert.org',
|
||||
]
|
||||
|
||||
# Databases configuration
|
||||
# Default: a postgresql local database named "barbacompta"
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
|
||||
'NAME': 'barbacompta', # Or path to database file if using sqlite3.
|
||||
'USER': 'barbacompta', # Not used with sqlite3.
|
||||
'PASSWORD': '', # Not used with sqlite3.
|
||||
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
|
||||
'PORT': '', # Set to empty string for default. Not used with sqlite3.
|
||||
}
|
||||
}
|
||||
|
||||
LANGUAGE_CODE = 'fr-fr'
|
||||
TIME_ZONE = 'Europe/Paris'
|
||||
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': False,
|
||||
'filters': {'require_debug_false': {'()': 'django.utils.log.RequireDebugFalse'},},
|
||||
'formatters': {
|
||||
'verbose': {
|
||||
'format': '[%(asctime)s] %(levelname)s %(name)s.%(funcName)s: %(message)s',
|
||||
'datefmt': '%Y-%m-%d %a %H:%M:%S',
|
||||
},
|
||||
'syslog': {'format': '%(levelname)s %(name)s.%(funcName)s: %(message)s',},
|
||||
},
|
||||
'handlers': {
|
||||
'console': {'level': 'DEBUG', 'class': 'logging.StreamHandler', 'formatter': 'verbose',},
|
||||
'syslog': {
|
||||
'level': 'DEBUG',
|
||||
'address': '/dev/log',
|
||||
'class': 'logging.handlers.SysLogHandler',
|
||||
'formatter': 'syslog',
|
||||
},
|
||||
'mail_admins': {
|
||||
'level': 'ERROR',
|
||||
'filters': ['require_debug_false'],
|
||||
'class': 'django.utils.log.AdminEmailHandler',
|
||||
},
|
||||
},
|
||||
'loggers': {'': {'handlers': ['mail_admins', 'syslog'], 'level': 'INFO',},},
|
||||
}
|
||||
|
||||
if os.path.exists('/etc/barbacompta/idp-metadata.xml'):
|
||||
INSTALLED_APPS += ('mellon',)
|
||||
AUTHENTICATION_BACKENDS += ('mellon.backends.SAMLBackend',)
|
||||
|
||||
MELLON_ATTRIBUTE_MAPPING = {
|
||||
'username': '{attributes[username][0]}',
|
||||
'email': '{attributes[email][0]}',
|
||||
'first_name': '{attributes[first_name][0]}',
|
||||
'last_name': '{attributes[last_name][0]}',
|
||||
}
|
||||
MELLON_SUPERUSER_MAPPING = {"is_superuser": (u"true",)}
|
||||
MELLON_USERNAME_TEMPLATE = "{attributes[username][0]}"
|
||||
MELLON_PUBLIC_KEYS = ['/etc/barbacompta/saml.crt']
|
||||
MELLON_PRIVATE_KEY = '/etc/barbacompta/saml.key'
|
||||
MELLON_IDENTITY_PROVIDERS = [{'METADATA': '/etc/barbacompta/idp-metadata.xml'}]
|
||||
|
||||
for filename in sorted(glob.glob(os.path.join(ETC_DIR, 'settings.d', '*.py'))):
|
||||
exec(open(filename).read())
|
||||
|
|
|
@ -1,27 +1,25 @@
|
|||
Source: barbacompta
|
||||
Section: python
|
||||
Priority: optional
|
||||
Maintainer: Jérôme Schneider <jschneider@entrouvert.com>
|
||||
Build-Depends: debhelper (>= 8.0.0),
|
||||
dh-python,
|
||||
dh-systemd,
|
||||
python-setuptools (>= 0.6b3),
|
||||
python-all (>= 2.6.6-3),
|
||||
python-django,
|
||||
python-setuptools
|
||||
Standards-Version: 3.9.4
|
||||
Maintainer: Benjamin Dauvergne <bdauvergne@entrouvert.com>
|
||||
Build-Depends: python3-setuptools, python3-all, python3-django, debhelper (>= 9), dh-python, dh-systemd, sassc
|
||||
Standards-Version: 3.9.6
|
||||
Homepage: https://dev.entrouvert.org/projects/barbacompta
|
||||
X-Python-Version: >= 2.7
|
||||
|
||||
Package: python3-barbacompta
|
||||
Architecture: all
|
||||
Depends: ${misc:Depends}, ${python3:Depends},
|
||||
python3-django (>= 1:1.11),
|
||||
python3-django (<< 1:1.12),
|
||||
python3-weasyprint,
|
||||
python3-cairosvg
|
||||
Description: Logiciel de compta/facturation interne
|
||||
|
||||
Package: barbacompta
|
||||
Architecture: all
|
||||
Depends: ${python:Depends},
|
||||
${misc:Depends},
|
||||
gunicorn,
|
||||
python-django (>= 1.11),
|
||||
python-django (<< 1:1.12),
|
||||
python-setuptools,
|
||||
python-psycopg2,
|
||||
python-weasyprint
|
||||
Suggests: python-django-debug-toolbar
|
||||
Depends: ${misc:Depends},
|
||||
python3-barbacompta (= ${binary:Version}),
|
||||
python3-psycopg2
|
||||
Description: Logiciel de compta/facturation interne
|
||||
Recommends: nginx, uwsgi, uwsgi-plugin-python3, python3-uwsgidecorators
|
||||
Suggests: postgresql
|
||||
|
|
|
@ -1,195 +0,0 @@
|
|||
#!/bin/sh
|
||||
### BEGIN INIT INFO
|
||||
# Provides: barbacompta
|
||||
# Required-Start: $network $local_fs
|
||||
# Required-Stop:
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Barbacompta logiciel de compta/facturation
|
||||
# Description: Barbacompta logiciel de compta/facturation d'EO
|
||||
### END INIT INFO
|
||||
|
||||
# Author: Jérôme Schneider <jschneider@entrouvert.com>
|
||||
|
||||
PATH=/sbin:/usr/sbin:/bin:/usr/bin
|
||||
DESC=Barbacompta
|
||||
NAME=barbacompta
|
||||
DAEMON=/usr/bin/gunicorn
|
||||
RUN_DIR=/run/$NAME
|
||||
PIDFILE=$RUN_DIR/$NAME.pid
|
||||
LOG_DIR=/var/log/$NAME
|
||||
SCRIPTNAME=/etc/init.d/$NAME
|
||||
BIND=unix:$RUN_DIR/$NAME.sock
|
||||
WORKERS=5
|
||||
TIMEOUT=10
|
||||
|
||||
export DJANGO_SETTINGS_MODULE=eo_gestion.settings
|
||||
BARBACOMPTA_SETTINGS_FILE=/etc/$NAME/config.py
|
||||
MANAGE_SCRIPT="/usr/bin/$NAME-manage"
|
||||
|
||||
USER=$NAME
|
||||
GROUP=$NAME
|
||||
|
||||
# Exit if the package is not installed
|
||||
[ -x $DAEMON ] || exit 0
|
||||
|
||||
# Read configuration variable file if it is present
|
||||
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
|
||||
|
||||
DAEMON_ARGS=${DAEMON_ARGS:-"--pid $PIDFILE \
|
||||
--user $USER --group $GROUP \
|
||||
--daemon \
|
||||
--access-logfile $LOG_DIR/gunicorn-access.log \
|
||||
--log-file $LOG_DIR/gunicorn-error.log \
|
||||
--bind=$BIND \
|
||||
--workers=$WORKERS \
|
||||
--worker-class=sync \
|
||||
--timeout=$TIMEOUT \
|
||||
--name $NAME \
|
||||
eo_gestion.wsgi:application"}
|
||||
|
||||
# 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 755 -o $USER -g $GROUP $RUN_DIR
|
||||
fi
|
||||
|
||||
# environment for wsgi & settings
|
||||
export BARBACOMPTA_SETTINGS_FILE
|
||||
|
||||
#
|
||||
# Function that starts the daemon/service
|
||||
#
|
||||
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
|
||||
#
|
||||
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
|
||||
#
|
||||
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 $NAME
|
||||
return 0
|
||||
}
|
||||
|
||||
do_migrate() {
|
||||
log_action_msg "Applying new migrations .."
|
||||
su $USER -p -c "$MANAGE_SCRIPT migrate"
|
||||
log_action_msg ".. done"
|
||||
}
|
||||
|
||||
do_collectstatic() {
|
||||
log_action_msg "Collect static files.."
|
||||
su $USER -p -c "$MANAGE_SCRIPT collectstatic --noinput --link"
|
||||
log_action_msg ".. done"
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
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)
|
||||
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_collectstatic
|
||||
do_migrate
|
||||
do_reload
|
||||
log_end_msg $?
|
||||
;;
|
||||
restart|force-reload)
|
||||
#
|
||||
# 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|status|restart|reload|force-reload}" >&2
|
||||
exit 3
|
||||
;;
|
||||
esac
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
debian/barbacompta-manage /usr/bin
|
||||
debian/config.py /etc/barbacompta
|
|
@ -1,3 +1,3 @@
|
|||
django-mellon python-django-mellon
|
||||
django-model-utils python-django-model-utils
|
||||
weasyprint python-weasyprint
|
||||
django-mellon python3-django-mellon
|
||||
django-model-utils python3-django-model-utils
|
||||
weasyprint python3-weasyprint
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
#!/usr/bin/make -f
|
||||
# -*- makefile -*-
|
||||
|
||||
# Uncomment this to turn on verbose mode.
|
||||
#export DH_VERBOSE=1
|
||||
|
||||
BUILD_DIR := 'debian/barbacompta'
|
||||
export PYBUILD_NAME=barbacompta
|
||||
|
||||
%:
|
||||
dh $@ --with python2,systemd --buildsystem=pybuild
|
||||
dh $@ --with python3,systemd --buildsystem=pybuild
|
||||
|
||||
override_dh_install:
|
||||
dh_install
|
||||
mv $(BUILD_DIR)/usr/bin/manage.py $(BUILD_DIR)/usr/lib/barbacompta/manage.py
|
||||
mv $(CURDIR)/debian/python3-barbacompta/usr/bin/manage.py $(CURDIR)/debian/barbacompta/usr/lib/barbacompta/manage.py
|
||||
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
[uwsgi]
|
||||
auto-procname = true
|
||||
procname-prefix-spaced = barbacompta
|
||||
|
||||
plugin = python3
|
||||
env=DJANGO_SETTINGS_MODULE=eo_gestion.settings
|
||||
env=BARBACOMPTA_SETTINGS_FILE=/etc/barbacompta/config.py
|
||||
module = django.core.wsgi:get_wsgi_application()
|
||||
|
||||
py-autoreload = 1
|
||||
|
||||
http-socket = /run/barbacompta/barbacompta.sock
|
||||
chmod-socket = 666
|
||||
vacuum = true
|
||||
|
||||
master = true
|
||||
processes = 5
|
||||
harakiri = 120
|
||||
enable-threads = true
|
||||
max-requests = 500
|
||||
max-worker-lifetime = 7200
|
||||
|
||||
buffer-size = 32768
|
||||
|
||||
py-tracebacker = /run/barbacompta/py-tracebacker.sock.
|
||||
stats = /run/barbacompta/stats.sock
|
||||
|
||||
ignore-sigpipe = true
|
||||
|
||||
if-file = /etc/barbacompta/uwsgi-local.ini
|
||||
include = /etc/barbacompta/uwsgi-local.ini
|
||||
endif =
|
Loading…
Reference in New Issue