From bdc49d5dfa63b58bd2d8e899a68be2213fb100f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Schneider?= Date: Tue, 3 Jun 2014 19:13:44 +0200 Subject: [PATCH 01/11] with debian folder it's better --- changelog | 5 ++ compat | 1 + control | 20 ++++++ dirs | 3 + init.d | 164 +++++++++++++++++++++++++++++++++++++++++++++++ install | 1 + local_config.py | 42 ++++++++++++ postinst | 57 ++++++++++++++++ pydist-overrides | 2 + rules | 19 ++++++ source/format | 1 + 11 files changed, 315 insertions(+) create mode 100644 changelog create mode 100644 compat create mode 100644 control create mode 100644 dirs create mode 100755 init.d create mode 100644 install create mode 100644 local_config.py create mode 100644 postinst create mode 100644 pydist-overrides create mode 100755 rules create mode 100644 source/format diff --git a/changelog b/changelog new file mode 100644 index 0000000..83bf565 --- /dev/null +++ b/changelog @@ -0,0 +1,5 @@ +mandaye-meyzieu (0.1-1) stable; urgency=medium + + * Initial release + + -- Jérôme Schneider Tue, 03 Jun 2014 19:00:37 +0200 diff --git a/compat b/compat new file mode 100644 index 0000000..7f8f011 --- /dev/null +++ b/compat @@ -0,0 +1 @@ +7 diff --git a/control b/control new file mode 100644 index 0000000..f2b392b --- /dev/null +++ b/control @@ -0,0 +1,20 @@ +Source: mandaye-meyzieu +Maintainer: Jerome Schneider +Section: python +Priority: optional +Build-Depends: python-setuptools (>= 0.6b3), python-all (>= 2.6.6-3), debhelper (>= 7.4.3) +Standards-Version: 3.9.1 +X-Python-Version: current + +Package: mandaye-meyzieu +Architecture: all +Depends: ${misc:Depends}, ${python:Depends}, + python-mandaye (>= 0.8), + python-beautifulsoup (>= 3.1), + python-crypto (>= 2.6), + python-lasso (>= 2.4.0), + python-psycopg2, + gunicorn (>= 0.17) +Recommends: postgresql, python-raven +Description: Meyzieu Mandaye project, modular authentification reverse proxy + diff --git a/dirs b/dirs new file mode 100644 index 0000000..eebb6c3 --- /dev/null +++ b/dirs @@ -0,0 +1,3 @@ +etc/mandaye-meyzieu +etc/mandaye-meyzieu/sites-available +etc/mandaye-meyzieu/sites-enabled diff --git a/init.d b/init.d new file mode 100755 index 0000000..8fe684c --- /dev/null +++ b/init.d @@ -0,0 +1,164 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: mandaye-meyzieu +# Required-Start: $network $local_fs +# Required-Stop: +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: authentication reverse proxy for Meyzieu +# Description: authentication reverse proxy for Meyzieu +### END INIT INFO + +# Author: Jérôme Schneider + +PATH=/sbin:/usr/sbin:/bin:/usr/bin +NAME=mandaye-meyzieu +DAEMON=/usr/bin/gunicorn +PID_DIR=/var/run/mandaye-meyzieu +PIDFILE=/var/run/mandaye-meyzieu/$NAME.pid +LOG_DIR=/var/log/mandaye-meyzieu +SCRIPTNAME=/etc/init.d/$NAME + +USER=mandaye-meyzieu +GROUP=mandaye-meyzieu + +DAEMON_ARGS="--pid $PIDFILE \ +--user $USER --group $GROUP \ +--daemon \ +--access-logfile $LOG_DIR/gunicorn-access.log \ +--log-file $LOG_DIR/gunicorn-error.log \ +--bind=unix:$PID_DIR/$NAME.sock \ +--workers=5 \ +--worker-class=sync \ +--timeout=60 \ +rp_meyzieu.wsgi:application" + +# 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 + +# Create pid directory +[ ! -d $PID_DIR ] && mkdir $PID_DIR && chown $USER:$GROUP $PID_DIR + +# 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 + +# +# 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 +} + +case "$1" in + start) + log_daemon_msg "Starting $DESC " "$NAME" + 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_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_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|status|restart|force-reload}" >&2 + exit 3 + ;; +esac + diff --git a/install b/install new file mode 100644 index 0000000..e28c784 --- /dev/null +++ b/install @@ -0,0 +1 @@ +debian/local_config.py /etc/mandaye-meyzieu/ diff --git a/local_config.py b/local_config.py new file mode 100644 index 0000000..9e0d26e --- /dev/null +++ b/local_config.py @@ -0,0 +1,42 @@ +## SQL Backend config +# http://docs.sqlalchemy.org/en/rel_0_7/core/engines.html +# rfc 1738 https://tools.ietf.org/html/rfc1738 +# dialect+driver://username:password@host:port/database +db_url = 'postgresql://mandaye-meyzieu@/mandaye_meyzieu' + +## Logging configuration +debug = False + +# Configuration directory +config_root = '/etc/mandaye-meyzieu/sites-enabled' +# Static folder +static_root = '/usr/share/mandaye-meyzieu/static' +# Data directory +data_dir = '/var/lib/mandaye-meyzieu/data' + +# Raven Sentry configuration +raven_dsn = None + +## Email notification configuration +email_notification = False +smtp_host = 'localhost' +smtp_port = 25 +email_from = 'admin+mandaye-meyzieu@entrouvert.com' +email_to = ['admin+mandaye-meyzieu@entrouvert.com'] + + +## Session configuration +# http://beaker.readthedocs.org/en/latest/configuration.html#options-for-sessions-and-caching +session_opts = { + 'session.type': 'file', + 'session.cookie_expires': True, + 'session.timeout': 3600, + 'session.data_dir': '/var/lib/mandaye-meyzieu/sessions' +} + +## Encrypt service provider passwords with a secret +# You should install pycypto to use this feature +encrypt_sp_password = True +# Must be a 16, 24, or 32 bytes long +encrypt_secret = 'CHANGEME' + diff --git a/postinst b/postinst new file mode 100644 index 0000000..37c7163 --- /dev/null +++ b/postinst @@ -0,0 +1,57 @@ +#!/bin/sh +# +# Postinst script for mandaye-vincennes +# + +set -e + +NAME=mandaye-vincennes +USER=$NAME +GROUP=$NAME +HOME=/var/lib/$NAME + +case "$1" in + configure) + if ! getent group $GROUP > /dev/null 2>&1; then + echo -n "Adding group $GROUP.." + addgroup --quiet --system $GROUP + echo "..done" + fi + if ! getent passwd $USER > /dev/null 2>&1; then + echo -n "Adding user $USER.." + adduser --quiet --system --gecos "Mandaye Vincennes daemon" \ + --ingroup $GROUP \ + --no-create-home --home $HOME \ + $USER + echo "..done" + fi + + echo -n "Fixing permissions.." + chown $USER:$GROUP /var/lib/$NAME /var/run/$NAME /var/log/$NAME + chown $USER:$GROUP /var/lib/$NAME/data /var/lib/$NAME/sessions + echo "..done" + + if [ -z "$2" ]; then + echo "Please create your database :" + echo "su $USER -p -c '/usr/bin/mandaye_vincennes_manager --createdb'" + fi + ;; + + reconfigure) + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/pydist-overrides b/pydist-overrides new file mode 100644 index 0000000..d10358f --- /dev/null +++ b/pydist-overrides @@ -0,0 +1,2 @@ +mandaye python-mandaye +pycrypto python-crypto diff --git a/rules b/rules new file mode 100755 index 0000000..4cbb4db --- /dev/null +++ b/rules @@ -0,0 +1,19 @@ +#!/usr/bin/make -f + +BUILD_DIR=$(CURDIR)/debian/mandaye-meyzieu + +%: + dh $@ --with python2 + +override_dh_install: + dh_install + for ver in $(shell pyversions -vr); do \ + ln -s /etc/mandaye-meyzieu/local_config.py $(BUILD_DIR)/usr/lib/python$$ver/dist-packages/mandaye_meyzieu/; \ + done + install -d -m 0755 $(BUILD_DIR)/var/lib/mandaye-meyzieu + install -d -m 0755 $(BUILD_DIR)/var/lib/mandaye-meyzieu/data + install -d -m 0750 $(BUILD_DIR)/var/lib/mandaye-meyzieu/sessions + install -d -m 0755 $(BUILD_DIR)/var/run/mandaye-meyzieu + install -d -m 0755 $(BUILD_DIR)/var/log/mandaye-meyzieu + install -d -m 0755 $(BUILD_DIR)/usr/share/mandaye-meyzieu + cp -R mandaye_meyzieu/static $(BUILD_DIR)/usr/share/mandaye-meyzieu diff --git a/source/format b/source/format new file mode 100644 index 0000000..163aaf8 --- /dev/null +++ b/source/format @@ -0,0 +1 @@ +3.0 (quilt) From 8b74eb24a004e9f22732a753cb4cb0a9ca0c26f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Schneider?= Date: Tue, 3 Jun 2014 19:15:30 +0200 Subject: [PATCH 02/11] rules: fix local_settings rules --- rules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules b/rules index 4cbb4db..4c96958 100755 --- a/rules +++ b/rules @@ -8,7 +8,7 @@ BUILD_DIR=$(CURDIR)/debian/mandaye-meyzieu override_dh_install: dh_install for ver in $(shell pyversions -vr); do \ - ln -s /etc/mandaye-meyzieu/local_config.py $(BUILD_DIR)/usr/lib/python$$ver/dist-packages/mandaye_meyzieu/; \ + ln -s /etc/mandaye-meyzieu/local_config.py $(BUILD_DIR)/usr/lib/python$$ver/dist-packages/rp_meyzieu/; \ done install -d -m 0755 $(BUILD_DIR)/var/lib/mandaye-meyzieu install -d -m 0755 $(BUILD_DIR)/var/lib/mandaye-meyzieu/data From 950cb5aca57d4fc1c9221b0ce80e4cc1149d2c14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Schneider?= Date: Tue, 3 Jun 2014 19:17:01 +0200 Subject: [PATCH 03/11] rules: fix static path --- rules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules b/rules index 4c96958..a319c67 100755 --- a/rules +++ b/rules @@ -16,4 +16,4 @@ override_dh_install: install -d -m 0755 $(BUILD_DIR)/var/run/mandaye-meyzieu install -d -m 0755 $(BUILD_DIR)/var/log/mandaye-meyzieu install -d -m 0755 $(BUILD_DIR)/usr/share/mandaye-meyzieu - cp -R mandaye_meyzieu/static $(BUILD_DIR)/usr/share/mandaye-meyzieu + cp -R rp_meyzieu/static $(BUILD_DIR)/usr/share/mandaye-meyzieu From 1b3f4144c586e46761d7387f0c49b2d90565abbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Schneider?= Date: Tue, 3 Jun 2014 19:22:16 +0200 Subject: [PATCH 04/11] debian: fix postinst --- postinst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/postinst b/postinst index 37c7163..3ed2a8b 100644 --- a/postinst +++ b/postinst @@ -1,11 +1,11 @@ #!/bin/sh # -# Postinst script for mandaye-vincennes +# Postinst script for mandaye-meyzieu # set -e -NAME=mandaye-vincennes +NAME=mandaye-meyzieu USER=$NAME GROUP=$NAME HOME=/var/lib/$NAME @@ -19,7 +19,7 @@ case "$1" in fi if ! getent passwd $USER > /dev/null 2>&1; then echo -n "Adding user $USER.." - adduser --quiet --system --gecos "Mandaye Vincennes daemon" \ + adduser --quiet --system --gecos "Mandaye Meyzieu daemon" \ --ingroup $GROUP \ --no-create-home --home $HOME \ $USER @@ -33,7 +33,7 @@ case "$1" in if [ -z "$2" ]; then echo "Please create your database :" - echo "su $USER -p -c '/usr/bin/mandaye_vincennes_manager --createdb'" + echo "su $USER -p -c '/usr/bin/rp_meyzieu_manager --createdb'" fi ;; From 0630b07467af2665debac310624d7e6a91f1097e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Schneider?= Date: Wed, 4 Jun 2014 10:30:19 +0200 Subject: [PATCH 05/11] auto generate saml key --- dirs | 1 + postinst | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/dirs b/dirs index eebb6c3..acea3be 100644 --- a/dirs +++ b/dirs @@ -1,3 +1,4 @@ etc/mandaye-meyzieu +etc/mandaye-meyzieu/certs etc/mandaye-meyzieu/sites-available etc/mandaye-meyzieu/sites-enabled diff --git a/postinst b/postinst index 3ed2a8b..3a705fe 100644 --- a/postinst +++ b/postinst @@ -25,6 +25,14 @@ case "$1" in $USER echo "..done" fi + if [ ! -f /etc/mandaye-meyzieu/certs/saml.crt -a ! -f /etc/mandaye-meyzieu/certs/saml.key ]; the + echo -n "Generating key material..." >&2 + openssl genpkey -algorithm rsa -pkeyopt rsa_keygen_bits:2048 -out /etc/mandaye-meyzieu/certs/saml.key >&2 + openssl req -x509 -new -out /etc/mandaye-meyzieu/certs/saml.crt -subj '/CN=whocares' -key /etc/mandaye-meyzieu/certs/saml.key -days 3650 >&2 + chown root:$GROUP /etc/mandaye-meyzieu/certs/saml.crt /etc/mandaye-meyzieu/certs/saml.key + chmod 640 /etc/mandaye-meyzieu/certs/saml.crt /etc/mandaye-meyzieu/certs/saml.key + echo "..done" >&2 + fi echo -n "Fixing permissions.." chown $USER:$GROUP /var/lib/$NAME /var/run/$NAME /var/log/$NAME From ed41a84ad7987ce828c0811a06714cc9c8ee897b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Schneider?= Date: Wed, 4 Jun 2014 10:34:59 +0200 Subject: [PATCH 06/11] postinst: then and not the ... --- postinst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postinst b/postinst index 3a705fe..3d1b1cf 100644 --- a/postinst +++ b/postinst @@ -25,7 +25,7 @@ case "$1" in $USER echo "..done" fi - if [ ! -f /etc/mandaye-meyzieu/certs/saml.crt -a ! -f /etc/mandaye-meyzieu/certs/saml.key ]; the + if [ ! -f /etc/mandaye-meyzieu/certs/saml.crt -a ! -f /etc/mandaye-meyzieu/certs/saml.key ]; then echo -n "Generating key material..." >&2 openssl genpkey -algorithm rsa -pkeyopt rsa_keygen_bits:2048 -out /etc/mandaye-meyzieu/certs/saml.key >&2 openssl req -x509 -new -out /etc/mandaye-meyzieu/certs/saml.crt -subj '/CN=whocares' -key /etc/mandaye-meyzieu/certs/saml.key -days 3650 >&2 From cdee447640881a3a431418fd3b0337539efffba0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Schneider?= Date: Wed, 23 Jul 2014 15:55:19 +0200 Subject: [PATCH 07/11] use new configuration system --- config.ini | 36 ++++++++++++++++++++++++++++++++++++ dirs | 6 ++++++ install | 2 +- local_config.py | 42 ------------------------------------------ rules | 9 --------- 5 files changed, 43 insertions(+), 52 deletions(-) create mode 100644 config.ini delete mode 100644 local_config.py diff --git a/config.ini b/config.ini new file mode 100644 index 0000000..4638d37 --- /dev/null +++ b/config.ini @@ -0,0 +1,36 @@ +[database] +; http://docs.sqlalchemy.org/en/rel_0_8/core/engines.html +url: postgresql://mandaye-meyzieu@/mandaye_meyzieu + +[dirs] +config_root: /etc/mandaye-meyzieu/sites-enabled +data_dir: /var/lib/mandaye-meyzieu/data +static_root: /usr/share/mandaye-meyzieu/static +static_url: /mandaye/static + +[debug] +debug: false +use_long_trace: true +log_debug: false +; you need to install python-raven for this feature +sentry_dsn: + +[mandaye] +toolbar: false +a2_auto_connection: false +auto_decompress: true +; if you want to encypt password set to true +; you need to install pycrypto for this feature +encrypt_sp_password: false +; if encrypt_sp_password then you need to choose a secret +; must be a 16, 24, or 32 bytes long +encrypt_secret: + +[session] +; file, dbm, memory or memcached +; if memcached you need to install python-memcached and memcached +type: file +url: +cookie_expires: true +timeout: 3600 +data_dir: /var/lib/mandaye-meyzieu/sessions diff --git a/dirs b/dirs index acea3be..235df7c 100644 --- a/dirs +++ b/dirs @@ -2,3 +2,9 @@ etc/mandaye-meyzieu etc/mandaye-meyzieu/certs etc/mandaye-meyzieu/sites-available etc/mandaye-meyzieu/sites-enabled +var/lib/mandaye-meyzieu +var/lib/mandaye-meyzieu/data +var/lib/mandaye-meyzieu/sessions +var/run/mandaye-meyzieu +var/log/mandaye-meyzieu +usr/share/mandaye-meyzieu diff --git a/install b/install index e28c784..9f2bc40 100644 --- a/install +++ b/install @@ -1 +1 @@ -debian/local_config.py /etc/mandaye-meyzieu/ +debian/config.ini /etc/mandaye-meyzieu/ diff --git a/local_config.py b/local_config.py deleted file mode 100644 index 9e0d26e..0000000 --- a/local_config.py +++ /dev/null @@ -1,42 +0,0 @@ -## SQL Backend config -# http://docs.sqlalchemy.org/en/rel_0_7/core/engines.html -# rfc 1738 https://tools.ietf.org/html/rfc1738 -# dialect+driver://username:password@host:port/database -db_url = 'postgresql://mandaye-meyzieu@/mandaye_meyzieu' - -## Logging configuration -debug = False - -# Configuration directory -config_root = '/etc/mandaye-meyzieu/sites-enabled' -# Static folder -static_root = '/usr/share/mandaye-meyzieu/static' -# Data directory -data_dir = '/var/lib/mandaye-meyzieu/data' - -# Raven Sentry configuration -raven_dsn = None - -## Email notification configuration -email_notification = False -smtp_host = 'localhost' -smtp_port = 25 -email_from = 'admin+mandaye-meyzieu@entrouvert.com' -email_to = ['admin+mandaye-meyzieu@entrouvert.com'] - - -## Session configuration -# http://beaker.readthedocs.org/en/latest/configuration.html#options-for-sessions-and-caching -session_opts = { - 'session.type': 'file', - 'session.cookie_expires': True, - 'session.timeout': 3600, - 'session.data_dir': '/var/lib/mandaye-meyzieu/sessions' -} - -## Encrypt service provider passwords with a secret -# You should install pycypto to use this feature -encrypt_sp_password = True -# Must be a 16, 24, or 32 bytes long -encrypt_secret = 'CHANGEME' - diff --git a/rules b/rules index a319c67..c0ff2e9 100755 --- a/rules +++ b/rules @@ -7,13 +7,4 @@ BUILD_DIR=$(CURDIR)/debian/mandaye-meyzieu override_dh_install: dh_install - for ver in $(shell pyversions -vr); do \ - ln -s /etc/mandaye-meyzieu/local_config.py $(BUILD_DIR)/usr/lib/python$$ver/dist-packages/rp_meyzieu/; \ - done - install -d -m 0755 $(BUILD_DIR)/var/lib/mandaye-meyzieu - install -d -m 0755 $(BUILD_DIR)/var/lib/mandaye-meyzieu/data - install -d -m 0750 $(BUILD_DIR)/var/lib/mandaye-meyzieu/sessions - install -d -m 0755 $(BUILD_DIR)/var/run/mandaye-meyzieu - install -d -m 0755 $(BUILD_DIR)/var/log/mandaye-meyzieu - install -d -m 0755 $(BUILD_DIR)/usr/share/mandaye-meyzieu cp -R rp_meyzieu/static $(BUILD_DIR)/usr/share/mandaye-meyzieu From d7c82a091e771dcf3c599496fddab17165f513c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Schneider?= Date: Tue, 9 Dec 2014 11:46:58 +0100 Subject: [PATCH 08/11] port to last Mandaye version --- control | 2 +- install | 1 + mandaye_meyzieu_manager | 22 ++++++++++++++++++++++ postinst | 2 +- rules | 2 ++ 5 files changed, 27 insertions(+), 2 deletions(-) create mode 100755 mandaye_meyzieu_manager diff --git a/control b/control index f2b392b..6c4254f 100644 --- a/control +++ b/control @@ -9,7 +9,7 @@ X-Python-Version: current Package: mandaye-meyzieu Architecture: all Depends: ${misc:Depends}, ${python:Depends}, - python-mandaye (>= 0.8), + python-mandaye (>= 0.10.2), python-beautifulsoup (>= 3.1), python-crypto (>= 2.6), python-lasso (>= 2.4.0), diff --git a/install b/install index 9f2bc40..fb21d5f 100644 --- a/install +++ b/install @@ -1 +1,2 @@ debian/config.ini /etc/mandaye-meyzieu/ +debian/mandaye_meyzieu_manager /usr/bin/ diff --git a/mandaye_meyzieu_manager b/mandaye_meyzieu_manager new file mode 100755 index 0000000..a7077dc --- /dev/null +++ b/mandaye_meyzieu_manager @@ -0,0 +1,22 @@ +#!/bin/sh + +NAME=mandaye-meyzieu +MANAGER="/usr/lib/$NAME/manager.py --config=/etc/$NAME/config.ini" + +# 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 ${MANAGER} --help + exit 1 +fi + +python ${MANAGER} "$@" diff --git a/postinst b/postinst index 3d1b1cf..4704653 100644 --- a/postinst +++ b/postinst @@ -41,7 +41,7 @@ case "$1" in if [ -z "$2" ]; then echo "Please create your database :" - echo "su $USER -p -c '/usr/bin/rp_meyzieu_manager --createdb'" + echo "su $USER -p -c '/usr/bin/mandaye_meyzieu_manager --createdb'" fi ;; diff --git a/rules b/rules index c0ff2e9..5dc8cc3 100755 --- a/rules +++ b/rules @@ -7,4 +7,6 @@ BUILD_DIR=$(CURDIR)/debian/mandaye-meyzieu override_dh_install: dh_install + mv $(BUILD_DIR)/usr/bin/server.py $(BUILD_DIR)/usr/lib/mandaye-meyzieu/server.py + mv $(BUILD_DIR)/usr/bin/manager.py $(BUILD_DIR)/usr/lib/mandaye-meyzieu/manager.py cp -R rp_meyzieu/static $(BUILD_DIR)/usr/share/mandaye-meyzieu From 88973958d90815f5800ad171331b9e362f09b245 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Schneider?= Date: Tue, 9 Dec 2014 11:56:06 +0100 Subject: [PATCH 09/11] init.d: update for last Mandaye version --- init.d | 173 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 88 insertions(+), 85 deletions(-) diff --git a/init.d b/init.d index 8fe684c..5c346d4 100755 --- a/init.d +++ b/init.d @@ -14,20 +14,21 @@ PATH=/sbin:/usr/sbin:/bin:/usr/bin NAME=mandaye-meyzieu DAEMON=/usr/bin/gunicorn -PID_DIR=/var/run/mandaye-meyzieu -PIDFILE=/var/run/mandaye-meyzieu/$NAME.pid -LOG_DIR=/var/log/mandaye-meyzieu +PID_DIR=/var/run/$NAME +PIDFILE=/var/run/$NAME/$NAME.pid +LOG_DIR=/var/log/$NAME SCRIPTNAME=/etc/init.d/$NAME +MANDAYE_CONFIG_FILES=/etc/$NAME/config.ini -USER=mandaye-meyzieu -GROUP=mandaye-meyzieu +USER=$NAME +GROUP=$NAME DAEMON_ARGS="--pid $PIDFILE \ --user $USER --group $GROUP \ --daemon \ --access-logfile $LOG_DIR/gunicorn-access.log \ --log-file $LOG_DIR/gunicorn-error.log \ ---bind=unix:$PID_DIR/$NAME.sock \ +--bind=127.0.0.1:8022 \ --workers=5 \ --worker-class=sync \ --timeout=60 \ @@ -49,20 +50,23 @@ rp_meyzieu.wsgi:application" # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. . /lib/lsb/init-functions +# environment for wsgi & settings +export MANDAYE_CONFIG_FILES + # # 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 + # 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 } # @@ -70,38 +74,38 @@ do_start() # 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" + # 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 + # + # 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 } case "$1" in @@ -109,56 +113,55 @@ case "$1" in log_daemon_msg "Starting $DESC " "$NAME" do_start case "$?" in - 0|1) log_end_msg 0 ;; - 2) log_end_msg 1 ;; - esac + 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 - ;; + 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 $? - #;; + 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 then remove the - # 'force-reload' alias - # - log_daemon_msg "Restarting $DESC" "$NAME" - do_stop - case "$?" in - 0|1) - 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 - ;; + # + # 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_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|status|restart|force-reload}" >&2 - exit 3 - ;; + echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 + exit 3 + ;; esac From 3069d588b25182d0e83785e2c5bfaa505ec8dc48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Schneider?= Date: Tue, 9 Dec 2014 11:59:53 +0100 Subject: [PATCH 10/11] dirs: add /usr/lib/mandaye-meyzieu --- dirs | 1 + 1 file changed, 1 insertion(+) diff --git a/dirs b/dirs index 235df7c..913e797 100644 --- a/dirs +++ b/dirs @@ -7,4 +7,5 @@ var/lib/mandaye-meyzieu/data var/lib/mandaye-meyzieu/sessions var/run/mandaye-meyzieu var/log/mandaye-meyzieu +usr/lib/mandaye-meyzieu usr/share/mandaye-meyzieu From aebfdb1c6cbab8f78921625e90e47ddb4fea0f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Schneider?= Date: Tue, 9 Dec 2014 12:04:03 +0100 Subject: [PATCH 11/11] init.d: fix bind --- init.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.d b/init.d index 5c346d4..cafde89 100755 --- a/init.d +++ b/init.d @@ -28,7 +28,7 @@ DAEMON_ARGS="--pid $PIDFILE \ --daemon \ --access-logfile $LOG_DIR/gunicorn-access.log \ --log-file $LOG_DIR/gunicorn-error.log \ ---bind=127.0.0.1:8022 \ +--bind=unix:$PID_DIR/$NAME.sock \ --workers=5 \ --worker-class=sync \ --timeout=60 \