Add files for deployment. Make testing use memory-DB.

This commit is contained in:
Thomas L 2018-03-24 15:02:11 +01:00
parent 454a9d5e4d
commit 54aaecfbc1
4 changed files with 39 additions and 9 deletions

10
db.py
View file

@ -2,7 +2,7 @@ from bottle import redirect, request
from functools import wraps
from inspect import Signature
import jwt
from os import path, urandom
from os import urandom
from pylibscrypt import scrypt_mcf, scrypt_mcf_check
import sqlite3
import prepare
@ -10,11 +10,9 @@ from user import User
class DB(object):
def __init__(self):
def __init__(self, dbfile):
self.config = prepare.get_config()
self.logger = prepare.get_logger(self.config)
dbfile = path.join(path.dirname(path.abspath(__file__)),
self.config['database']['db_path'])
self.conn = sqlite3.connect(dbfile)
self.cur = self.conn.cursor()
self.create()
@ -149,8 +147,8 @@ class DBPlugin(object):
name = 'DBPlugin'
api = 2
def __init__(self, loginpage):
self.db = DB()
def __init__(self, dbfile, loginpage):
self.db = DB(dbfile)
self.loginpage = loginpage
def close(self):

View file

@ -0,0 +1,16 @@
[Unit]
Description=Ticketfrei Web Application
After=syslog.target network.target
[Service]
ExecStart=/usr/bin/uwsgi --ini /srv/ticketfrei/deployment/uwsgi.ini
# Requires systemd version 211 or newer
RuntimeDirectory=uwsgi
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all
[Install]
WantedBy=multi-user.target

11
deployment/uwsgi.ini Normal file
View file

@ -0,0 +1,11 @@
[uwsgi]
plugins = python3
master = true
uid = www-data
gid = www-data
processes = 1
# logto = /var/log/ticketfrei.log
socket = /var/run/ticketfrei/ticketfrei.sock
chmod-socket = 660
wsgi-file = /srv/ticketfrei/frontend.py
virtualenv = /srv/ticketfrei/venv

View file

@ -143,6 +143,11 @@ def login_mastodon(user):
return dict(error='Login to Mastodon failed.')
config = prepare.get_config()
bottle.install(DBPlugin('/'))
bottle.run(host=config['web']['host'], port=8080)
if __name__ == '__main__':
# testing only
bottle.install(DBPlugin(':memory:', '/'))
bottle.run(host='localhost', port=8080)
else:
config = prepare.get_config()
bottle.install(DBPlugin(config['database']['db_path'], '/'))
application = bottle.default_app()