diff --git a/.gitignore b/.gitignore index 0c8bf2f..23d733b 100644 --- a/.gitignore +++ b/.gitignore @@ -168,3 +168,4 @@ diomerdas furizon.net/site/* furizon.net.zip stuff/secrets.py +backups/* \ No newline at end of file diff --git a/app.py b/app.py index 1e45d20..1b95995 100644 --- a/app.py +++ b/app.py @@ -1,7 +1,7 @@ from sanic import Sanic, response, exceptions from sanic.response import text, html, redirect, raw from jinja2 import Environment, FileSystemLoader -from time import time +from time import time, sleep import httpx from os.path import join from ext import * @@ -12,6 +12,8 @@ from io import BytesIO from asyncio import Queue from messages import LOCALES import sqlite3 +import requests +import sys from sanic.log import logger, logging app = Sanic(__name__) @@ -185,4 +187,21 @@ async def logout(request): raise exceptions.Forbidden("You have been logged out.") if __name__ == "__main__": - app.run(host="0.0.0.0", port=8188, dev=DEV_MODE, access_log=ACCESS_LOG) + # Wait for pretix in server reboot + # Using a docker configuration, pretix may be unable to talk with postgres if postgres' service started before it. + # To fix this issue I added a After=pretix.service to the [Unit] section of /lib/systemd/system/postgresql@.service + # to let it start in the correct order. The following piece of code makes sure that pretix is running and can talk to + # postgres before actually starting the reserved area, since this operation requires a cache-fill in startup + print("Waiting for pretix to be up and running", file=sys.stderr) + while True: + print("Trying connecting to pretix...", file=sys.stderr) + try: + res = requests.get(base_url_event, headers=headers) + res = res.json() + if(res['slug'] == EVENT_NAME): + break + except: + pass + sleep(5) + print("Connected to pretix!", file=sys.stderr) + app.run(host="127.0.0.1", port=8188, dev=DEV_MODE, access_log=ACCESS_LOG) diff --git a/reg.furizon.net/index.html b/reg.furizon.net/index.html index c07a871..9815975 100644 --- a/reg.furizon.net/index.html +++ b/reg.furizon.net/index.html @@ -94,21 +94,6 @@ #clock {display:block;} - - -
diff --git a/requirements.txt b/requirements.txt index bfa4da3..c2ae761 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,5 @@ sanic-ext httpx Pillow aztec_code_generator -jinja2 +Jinja2 +Requests \ No newline at end of file diff --git a/stuff/runBackup.py b/stuff/runBackup.py new file mode 100644 index 0000000..740a1b3 --- /dev/null +++ b/stuff/runBackup.py @@ -0,0 +1,44 @@ +#!/usr/bin/python + +from os import listdir, remove +from os.path import isfile, join +import datetime +import subprocess + +PRETIX_BACKUP = False +WEBINT_BACKUP = False + +BACKUP_DIR_PRETIX = "/home/pretix/backups/" +BACKUP_DIR_WEBINT = "/home/webint/backups/" + +MAX_FILE_NO = 14 + +COMMAND_PRETIX_POSTGRES = "pg_dump -F p pretix | gzip > %s" # Restore with psql -f %s +COMMAND_PRETIX_DATA = "tar -cf %s /var/pretix-data" # Restore with tar -xvf %s. To make .secret readable I used setfacl -m u:pretix:r /var/pretix-data/.secret +COMMAND_WEBINT = "tar -cf %s /home/webint/furizon_webint" # Restore with tar -xvf %s + + +def deleteOlder(path : str, prefix : str, postfix : str): + backupFileNames = sorted([f for f in listdir(path) if (isfile(join(path, f)) and f.startswith(prefix) and f.endswith(postfix))]) + while(len(backupFileNames) > MAX_FILE_NO): + print(f"Removing {backupFileNames[0]}") + remove(join(path, backupFileNames[0])) + backupFileNames.pop(0) + +def genFileName(prefix : str, postfix : str): + return prefix + "_" + datetime.datetime.now(datetime.UTC).strftime('%Y%m%d-%H%M%S') + "_" + postfix + +def runBackup(prefix : str, postfix : str, path : str, command : str): + deleteOlder(path, prefix, postfix) + name = join(path, genFileName(prefix, postfix)) + process = subprocess.Popen(command % name, shell=True) + process.wait() + + + +if(PRETIX_BACKUP): + runBackup("pretix_postres", "backup.sql.gz", join(BACKUP_DIR_PRETIX, "postgres"), COMMAND_PRETIX_POSTGRES) + runBackup("pretix_data", "backup.tar.gz", join(BACKUP_DIR_PRETIX, "data"), COMMAND_PRETIX_DATA) + +if(WEBINT_BACKUP): + runBackup("webint_full", "backup.tar.gz", BACKUP_DIR_WEBINT, COMMAND_WEBINT) \ No newline at end of file