Initialize fargo debian branch

This commit is contained in:
Benjamin Dauvergne 2015-03-05 23:46:47 +01:00
commit 3676bfa99a
19 changed files with 489 additions and 0 deletions

5
changelog Normal file
View File

@ -0,0 +1,5 @@
fargo (0.1-1) stable; urgency=low
* Initial release. (Closes: #XXXXXX)
-- EO Admin <admin@entrouvert.com> Wed, 11 Feb 2015 11:24:07 +0100

1
compat Normal file
View File

@ -0,0 +1 @@
7

32
control Normal file
View File

@ -0,0 +1,32 @@
Source: fargo
Maintainer: Entr'ouvert <info@entrouvert.com>
Section: python
Priority: optional
Build-Depends: python-setuptools (>= 0.6b3), python-all (>= 2.7), debhelper (>= 7.4.3),
python-django (>= 1.7)
Standards-Version: 3.9.1
XS-Python-Version: >= 2.7, << 3.0
Package: fargo
Architecture: all
Pre-Depends: python-django (>= 1.7), postgresql
Depends: ${misc:Depends}, ${python:Depends},
python (>= 2.7),
python-fargo (= ${binary:Version}),
python-psycopg2,
gunicorn,
dbconfig-common,
debconf | debconf-2.0,
ucf
Recommends: postgresql-client, python-memcache,
memcached, python-raven, python-entrouvert
Suggests: nginx
Description: Fargo
Package: python-fargo
Architecture: all
Pre-Depends: python-django (>= 1.7)
Depends: ${misc:Depends}, ${python:Depends},
python (>= 2.7), python-django-sekizai
Description: Fargo Python files

5
db.conf.template Normal file
View File

@ -0,0 +1,5 @@
export DATABASE_ENGINE='django.db.backends.postgresql_psycopg2'
export DATABASE_NAME='_DBC_DBNAME_'
export DATABASE_USER='_DBC_DBUSER_'
export DATABASE_PASSWORD='_DBC_DBPASS_'
export DATABASE_HOST='localhost'

56
debian_config.py Normal file
View File

@ -0,0 +1,56 @@
import os.path
# Debian defaults
DEBUG = False
STATIC_ROOT = '/var/lib/fargo/collectstatic/'
STATICFILES_DIRS = ['/var/lib/fargo/static',] + STATICFILES_DIRS
TEMPLATE_DIRS = ['/var/lib/fargo/templates',] + TEMPLATE_DIRS
LOCALE_PATHS = ['/var/lib/fargo/locale',] + LOCALE_PATHS
MEDIA_ROOT = '/var/lib/fargo/media/'
ADMINS = (
# send tracebacks to root
('root', 'root@localhost'),
)
if os.path.exists('/var/lib/fargo/secret_key'):
SECRET_KEY = file('/var/lib/fargo/secret_key').read()
def read_database_configuration():
'''Extract database configuration from environment variables'''
for key in os.environ:
if key.startswith('DATABASE_'):
prefix, db_key = key.split('_', 1)
DATABASES['default'][db_key] = os.environ[key]
read_database_configuration()
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'syslog': {
'format': '%(levelname)s %(name)s.%(funcName)s: %(message)s',
},
},
'handlers': {
'syslog': {
'level': 'INFO',
'address': '/dev/log',
'class': 'logging.handlers.SysLogHandler',
'formatter': 'syslog',
},
},
'loggers': {
'fargo': {
'level': 'INFO',
'handlers': ['syslog', ],
'propagate': False,
},
},
}
CONFIG_FILE='/etc/fargo/settings.py'
if os.path.exists(CONFIG_FILE):
execfile('/etc/fargo/settings.py')

15
fargo-ctl Normal file
View File

@ -0,0 +1,15 @@
#!/bin/sh
if [ "$(whoami)" != "fargo" ]; then
echo "You must run this script with fargo user"
exit 1
fi
export LOCAL_SETTINGS='/usr/share/fargo/debian_config.py'
if [ -f /etc/fargo/db.conf ]; then
. /etc/fargo/db.conf
fi
/usr/share/python-fargo/manage.py "$@"

14
fargo.config Normal file
View File

@ -0,0 +1,14 @@
#!/bin/sh
# config maintainer script for foo-pgsql
set -e
# source debconf stuff
. /usr/share/debconf/confmodule
# source dbconfig-common shell library, and call the hook function
if [ -f /usr/share/dbconfig-common/dpkg/config.pgsql ]; then
. /usr/share/dbconfig-common/dpkg/config.pgsql
dbc_go fargo $@
fi
#DEBHELPER#

3
fargo.cron.hourly Normal file
View File

@ -0,0 +1,3 @@
#!/bin/sh
/usr/bin/fargo-ctl clearsessions

9
fargo.dirs Normal file
View File

@ -0,0 +1,9 @@
/usr/share/fargo
/var/lib/fargo/static
/var/lib/fargo/collectstatic
/var/lib/fargo/media
/var/lib/fargo/templates
/var/lib/fargo/locale
/var/run/fargo
/var/log/fargo
/etc/fargo

205
fargo.init Normal file
View File

@ -0,0 +1,205 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: fargo
# Required-Start: $network $local_fs
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Fargo is a versatile identity provider
# Description: Fargo is a versatile identity provider
### END INIT INFO
# Author: Jérôme Schneider <jschneider@entrouvert.com>
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC=fargo
NAME=fargo
DAEMON=/usr/bin/gunicorn
PID_DIR=/var/run/$NAME
CACHE_DIR=/var/cache/$NAME
LOG_DIR=/var/log/$NAME
PIDFILE=$PID_DIR/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
CTL=/usr/bin/$NAME-ctl
SOCKFILE=$PID_DIR/$NAME.sock
BIND=unix:$SOCKFILE
LOCAL_SETTINGS=/usr/share/$NAME/debian_config.py
USER=fargo
GROUP=fargo
# 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="--pid $PIDFILE \
--user $USER --group $GROUP \
--daemon \
--access-logfile $LOG_DIR/gunicorn-access.log \
--log-file $LOG_DIR/gunicorn-error.log \
--bind=$BIND \
--workers=10 \
--worker-class=sync \
--timeout=60 \
fargo.wsgi:application"
# Load config
if [ -f /etc/fargo/db.conf ]; then
. /etc/fargo/db.conf
fi
# 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 pid directory
if [ ! -d $PID_DIR ]; then
install -d -m 755 -o $USER -g $GROUP $PID_DIR
fi
# Create cache directory
if [ ! -d $CACHE_DIR ]; then
install -d -m 755 -o $USER -g $GROUP $CACHE_DIR
fi
#
# 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
export DJANGO_CONFIG_FILE
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 $SOCKFILE
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 `basename $DAEMON`
return 0
}
do_migrate() {
log_action_msg "Applying new migrations .."
su $USER -p -c "$CTL migrate"
log_action_msg ".. done"
}
do_collectstatic() {
log_action_msg "Collecting static files .."
su $USER -p -c "$CTL collectstatic --noinput"
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_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
;;
collectstatic)
do_collectstatic
;;
migrate)
do_migrate
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac

5
fargo.install Normal file
View File

@ -0,0 +1,5 @@
debian/debian_config.py /usr/share/fargo/
debian/fargo-ctl /usr/bin
debian/db.conf.template /usr/share/fargo/
debian/nginx.conf /usr/share/fargo/
manage.py /usr/lib/fargo/

76
fargo.postinst Normal file
View File

@ -0,0 +1,76 @@
#!/bin/sh
#
# Postinst script for fargo
#
set -e
NAME=fargo
A2__USER=fargo
A2__GROUP=fargo
A2__HOME=/var/lib/fargo
A2__SECRET_KEY="$A2__HOME/secret_key"
# source debconf stuff
. /usr/share/debconf/confmodule
case "$1" in
configure)
if ! getent group $A2__GROUP > /dev/null 2>&1; then
echo -n "Adding group $A2__GROUP.." >&2
addgroup --quiet --system $A2__GROUP
echo "..done" >&2
fi
if ! getent passwd $A2__USER > /dev/null 2>&1; then
echo -n "Adding user $A2__USER.." >&2
adduser --quiet --system --gecos "Fargo daemon" \
--ingroup $A2__GROUP \
--no-create-home --home $A2__HOME \
$A2__USER
echo "..done" >&2
fi
if [ ! -f $A2__SECRET_KEY ]; then
echo -n "Generating a secret key.." >&2
echo -n "`</dev/urandom tr -dc [:alnum:]-_\!\%\^:\; | head -c70`" > "$A2__SECRET_KEY"
chmod 0600 $A2__SECRET_KEY
chown $A2__USER $A2__SECRET_KEY
echo "..done" >&2
fi
chown -R $A2__USER:$A2__GROUP \
/var/lib/fargo/collectstatic \
/var/lib/fargo/media \
/var/run/fargo
# 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/fargo/db.conf"
dbc_generate_include_args="-o template_infile=/usr/share/fargo/db.conf.template -U"
dbc_generate_include_owner="root:fargo"
dbc_generate_include_perms="640"
dbc_pgsql_createdb_encoding="UTF8"
dbc_go fargo $@
fi
;;
reconfigure|abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
db_stop
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0

32
fargo.postrm Normal file
View File

@ -0,0 +1,32 @@
#!/bin/sh
# postrm script for fargo
#
# see: dh_installdeb(1)
set -e
case "$1" in purge)
deluser --quiet --system fargo > /dev/null || true
rm -f /var/lib/fargo/secret_key
rm -rf /var/lib/fargo/collectstatic/*
# source debconf stuff
. /usr/share/debconf/confmodule
# source dbconfig-common shell library, and call the hook function
if [ -f /usr/share/dbconfig-common/dpkg/postrm.pgsql ]; then
. /usr/share/dbconfig-common/dpkg/postrm.pgsql
dbc_go fargo $@
fi
DBCONF=/etc/fargo/db.conf
if [ "$1" = "purge" ]; then
rm -f $DBCONF
if which ucf >/dev/null 2>&1; then
ucf --purge $DBCONF
fi
fi
;;
esac
exit 0

12
nginx.conf Normal file
View File

@ -0,0 +1,12 @@
access_log /var/log/nginx/fargo-access.log combined;
error_log /var/log/nginx/fargo-error.log;
location /fargo/static {
alias /var/lib/fargo/collectstatic;
}
location /fargo {
proxy_pass http://unix:/var/run/fargo/fargo.sock;
proxy_set_header Host $http_host;
proxy_set_header SCRIPT_NAME /fargo
}

2
python-fargo.dirs Normal file
View File

@ -0,0 +1,2 @@
/usr/share/python-fargo/
/usr/share/python-fargo/themes/

2
python-fargo.docs Normal file
View File

@ -0,0 +1,2 @@
AUTHORS.txt
COPYING

1
python-fargo.install Normal file
View File

@ -0,0 +1 @@
usr/lib

13
rules Executable file
View File

@ -0,0 +1,13 @@
#!/usr/bin/make -f
fargo=$(CURDIR)/debian/fargo
python_fargo=$(CURDIR)/debian/python-fargo
%:
dh $@ --with python2
override_dh_install:
dh_install
mv $(CURDIR)/debian/tmp/usr/bin/manage.py $(python_fargo)/usr/share/python-fargo/manage.py

1
source/format Normal file
View File

@ -0,0 +1 @@
3.0 (quilt)