From 14c1789a26f587963430ca42b5496375941fc39c Mon Sep 17 00:00:00 2001 From: Jocelyn Delande Date: Fri, 1 May 2015 14:30:09 +0200 Subject: [PATCH] Work in progress : installation is working but upstream app lacks url prefix support --- conf/gunicorn.conf.py | 7 ++++ conf/nginx.conf | 19 +++++++++++ conf/settings.py | 11 +++++++ conf/supervisord.conf | 7 ++++ manifest.json | 36 ++++++++++++++++++++ scripts/install | 76 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 156 insertions(+) create mode 100644 conf/gunicorn.conf.py create mode 100644 conf/nginx.conf create mode 100644 conf/settings.py create mode 100644 conf/supervisord.conf create mode 100644 manifest.json create mode 100644 scripts/install diff --git a/conf/gunicorn.conf.py b/conf/gunicorn.conf.py new file mode 100644 index 0000000..5c3ae32 --- /dev/null +++ b/conf/gunicorn.conf.py @@ -0,0 +1,7 @@ +backlog = 2048 +daemon = False +debug = True +workers = 3 +logfile = "/var/log/ihatemoney/budget.gunicorn.log" +loglevel = "info" +bind = "unix:/var/run/ihatemoney/budget.gunicorn.sock" diff --git a/conf/nginx.conf b/conf/nginx.conf new file mode 100644 index 0000000..2935dda --- /dev/null +++ b/conf/nginx.conf @@ -0,0 +1,19 @@ +location PATHTOCHANGE/static/ { + alias /path/to/app/budget/static/; +} +location PATHTOCHANGE/ { + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_connect_timeout 90; + proxy_send_timeout 180; + proxy_read_timeout 180; + proxy_buffer_size 16k; + proxy_buffers 8 16k; + proxy_busy_buffers_size 32k; + proxy_intercept_errors on; + if (!-f $request_filename) { + proxy_pass http://unix:/var/run/ihatemoney/budget.gunicorn.sock; + break; + } +} diff --git a/conf/settings.py b/conf/settings.py new file mode 100644 index 0000000..5026544 --- /dev/null +++ b/conf/settings.py @@ -0,0 +1,11 @@ +DEBUG = True +SQLALCHEMY_DATABASE_URI = 'mysql://ihatemoney:MY_MYSQL_PW@localhost/ihatemoney' +SQLACHEMY_ECHO = DEBUG +SECRET_KEY = "MY_SECRET_KEY" + +DEFAULT_MAIL_SENDER = ("Budget manager", "MY_EMAIL") + +try: + from settings import * +except ImportError: + pass diff --git a/conf/supervisord.conf b/conf/supervisord.conf new file mode 100644 index 0000000..ebb5742 --- /dev/null +++ b/conf/supervisord.conf @@ -0,0 +1,7 @@ +[program:budget] +command=/opt/yunohost/ihatemoney/venv/bin/gunicorn -c /etc/ihatemoney/gunicorn.conf.py run:app +directory=/opt/yunohost/ihatemoney/src/budget +user=ihatemoney +autostart=true +autorestart=true +redirect_stderr=True diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..0cb0235 --- /dev/null +++ b/manifest.json @@ -0,0 +1,36 @@ +{ + "name": "I Hate Money", + "id": "ihatemoney", + "description": { + "en": "A simple shared budget manager web application", + "fr": "Une application web de comptes partagés à plusieurs" + }, + "licence": "BSD custom beerware", + "developer": { + "name": "Jocelyn Delalande", + "email": "jocelyn@crapouillou.net", + "url": "http://jocelyn.delalande.fr" + }, + "multi_instance": "false", + "arguments": { + "install" : [ + { + "name": "domain", + "ask": { + "en": "Choose a domain for ihatemoney", + "fr": "Choisir un domaine pour ihatemoney" + }, + "example": "example.com" + }, + { + "name": "path", + "ask": { + "en": "Choose a path for ihatemoney", + "fr": "Choisir un chemin pour ihatemoney" + }, + "example": "/example", + "default": "/ihatemoney" + } + ] + } +} diff --git a/scripts/install b/scripts/install new file mode 100644 index 0000000..f2238c0 --- /dev/null +++ b/scripts/install @@ -0,0 +1,76 @@ +#!/bin/bash +set -e +# Constants + +# Retrieve arguments +domain=$1 +path=$2 + +# Constant arguments +db_user=ihatemoney +secret_key=`openssl rand -base64 32` +mails_sender="no-reply@${domain}" + +sudo yunohost app checkurl $domain$path -a ihatemoney +if [[ ! $? -eq 0 ]]; then + exit 1 +fi + +# Remove trailing "/" for next commands +path=${path%/} + +# Install debian packages dependencies +sudo apt-get install -y -qq python-virtualenv supervisor + +# Create the dedicated user +sudo useradd ihatemoney -d /opt/yunohost/ihatemoney/ + +# Prepare venv +sudo virtualenv /opt/yunohost/ihatemoney/venv +sudo /opt/yunohost/ihatemoney/venv/bin/pip install -r ../sources/budget/requirements.txt +sudo /opt/yunohost/ihatemoney/venv/bin/pip install gunicorn>=19.3.0 + + +# Install source +sudo cp -r ../sources/ /opt/yunohost/ihatemoney/src/ +sudo find /opt/yunohost/ihatemoney/src/ -type f | while read LINE; do sudo chmod 640 "$LINE" ; done +sudo find /opt/yunohost/ihatemoney/src/ -type d | while read LINE; do sudo chmod 750 "$LINE" ; done +sudo chown -R ihatemoney:ihatemoney /opt/yunohost/ihatemoney/src + + +# Create various dirs +sudo install -o ihatemoney -g ihatemoney -m 755 \ + -d /var/log/ihatemoney /etc/ihatemoney /var/run/ihatemoney/ + +# Configure supervisor +sudo install -o root -g root -m 644 \ + ../conf/supervisord.conf /etc/supervisor/conf.d/ihatemoney.conf +sudo service supervisor restart +sudo yunohost service add supervisor + +# Configure gunicorn +sudo install -o ihatemoney -g ihatemoney -m 644 \ + ../conf/gunicorn.conf.py /etc/ihatemoney/gunicorn.conf.py + +# Configure database +db_pwd=`sudo yunohost app initdb $db_user` +sudo yunohost app setting ihatemoney mysqlpwd -v $db_pwd + +# Configure ihatemoney +sed -i "s/MY_SECRET_KEY/$secret_key/" ../conf/settings.py +sed -i "s/MY_EMAIL/$mails_sender/" ../conf/settings.py +sed -i "s/MY_MYSQL_PW/$db_pwd/" ../conf/settings.py +sudo install -o ihatemoney -g ihatemoney -m 640 \ + ../conf/settings.py /etc/ihatemoney/settings.py +# The settings have to be stored here (on python path) +sudo ln -s /etc/ihatemoney/settings.py /opt/yunohost/ihatemoney/src/budget/settings.py + +# Reconfigure sso +sudo yunohost app ssowatconf + +# Configure Nginx and reload +sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf +sudo install -o root -g root -m644 \ + ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/ihatemoney.conf +sudo service nginx reload +echo $?