From 3574eacb2513758acecf965172f357613bc26f18 Mon Sep 17 00:00:00 2001 From: jokajak Date: Sun, 24 Apr 2016 08:35:37 -0400 Subject: [PATCH] Add example files for running clipperz with uwsgi and nginx Additionally make changes to enable running clipperz from uwsgi --- backend/flask/src/clipperz/views.py | 15 ++++++++---- backend/flask/src/nginx.conf.example | 11 +++++++++ backend/flask/src/run.py | 10 ++++++++ backend/flask/src/uwsg-emperor.ini.example | 28 ++++++++++++++++++++++ 4 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 backend/flask/src/nginx.conf.example create mode 100644 backend/flask/src/run.py create mode 100644 backend/flask/src/uwsg-emperor.ini.example diff --git a/backend/flask/src/clipperz/views.py b/backend/flask/src/clipperz/views.py index 0bece2a..e57fbed 100644 --- a/backend/flask/src/clipperz/views.py +++ b/backend/flask/src/clipperz/views.py @@ -1,10 +1,11 @@ """Clipperz views.""" -from flask import session, request, g +from flask import session, request, g, send_from_directory from clipperz import app, db, lm from .models import User from .api import * # NOQA from .exceptions import InvalidUsage from flask.ext.login import login_required +from os.path import dirname @lm.user_loader @@ -113,19 +114,25 @@ def dump(frontend_version): @app.route('/beta/') def beta(path): """Fallback for serving beta version.""" - return send_from_directory('beta', path) + here = dirname(__file__) + file_path = "{0}/../beta/".format(here) + return send_from_directory(file_path, path) @app.route('/gamma/') def gamma(path): """Fallback for serving gamma version.""" - return send_from_directory('gamma', path) + here = dirname(__file__) + file_path = "{0}/../gamma/".format(here) + return send_from_directory(file_path, path) @app.route('/delta/') def delta(path): """Fallback for serving delta version.""" - return send_from_directory('delta', path) + here = dirname(__file__) + file_path = "{0}/../delta/".format(here) + return send_from_directory(file_path, path) @app.route('/pm', methods=['GET', 'OPTIONS', 'POST']) diff --git a/backend/flask/src/nginx.conf.example b/backend/flask/src/nginx.conf.example new file mode 100644 index 0000000..8dad8ce --- /dev/null +++ b/backend/flask/src/nginx.conf.example @@ -0,0 +1,11 @@ + location /pm { + auth_basic "Restricted"; + auth_basic_user_file /etc/nginx/.htpasswd; + try_files $uri $uri/ @pm; + } + location @pm { + include uwsgi_params; + uwsgi_param SCRIPT_NAME /pm; + uwsgi_modifier1 30; + uwsgi_pass unix:/run/uwsgi/pm.sock; + } diff --git a/backend/flask/src/run.py b/backend/flask/src/run.py new file mode 100644 index 0000000..5fa654f --- /dev/null +++ b/backend/flask/src/run.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +from clipperz import app, db + + +def main(): + db.create_all() + app.run(debug=True) + +if __name__ == "__main__": + main() diff --git a/backend/flask/src/uwsg-emperor.ini.example b/backend/flask/src/uwsg-emperor.ini.example new file mode 100644 index 0000000..d301077 --- /dev/null +++ b/backend/flask/src/uwsg-emperor.ini.example @@ -0,0 +1,28 @@ +[uwsgi] +plugin = python +socket = /run/uwsgi/%n.sock +chmod-socket = 660 +master = true +processes = 1 +uid = clipperz +gid = clipperz +umask = 027 +procname-master = uwsgi pm + +vacuum = true + +die-on-term = true + +base = /home/clipperz/password-manager/target/flask/ +module = clipperz +callable = app +venv = /home/clipperz/password-manager/target/flask/ + +#the variable that holds a flask application inside the module imported at line #6 +callable = app + +#location of log files +logto = /var/log/uwsgi/%n.log + +env = PYTHON_EGG_CACHE=/var/tmp/clipperz +env = DATABASE_URL = 'mysql://clipperz:clipperz@localhost/clipperz'