stranck-dev in drew-dev #17
|
@ -168,3 +168,4 @@ diomerdas
|
||||||
furizon.net/site/*
|
furizon.net/site/*
|
||||||
furizon.net.zip
|
furizon.net.zip
|
||||||
stuff/secrets.py
|
stuff/secrets.py
|
||||||
|
backups/*
|
23
app.py
23
app.py
|
@ -1,7 +1,7 @@
|
||||||
from sanic import Sanic, response, exceptions
|
from sanic import Sanic, response, exceptions
|
||||||
from sanic.response import text, html, redirect, raw
|
from sanic.response import text, html, redirect, raw
|
||||||
from jinja2 import Environment, FileSystemLoader
|
from jinja2 import Environment, FileSystemLoader
|
||||||
from time import time
|
from time import time, sleep
|
||||||
import httpx
|
import httpx
|
||||||
from os.path import join
|
from os.path import join
|
||||||
from ext import *
|
from ext import *
|
||||||
|
@ -12,6 +12,8 @@ from io import BytesIO
|
||||||
from asyncio import Queue
|
from asyncio import Queue
|
||||||
from messages import LOCALES
|
from messages import LOCALES
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
import requests
|
||||||
|
import sys
|
||||||
from sanic.log import logger, logging
|
from sanic.log import logger, logging
|
||||||
|
|
||||||
app = Sanic(__name__)
|
app = Sanic(__name__)
|
||||||
|
@ -185,4 +187,21 @@ async def logout(request):
|
||||||
raise exceptions.Forbidden("You have been logged out.")
|
raise exceptions.Forbidden("You have been logged out.")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
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)
|
||||||
|
|
|
@ -94,21 +94,6 @@
|
||||||
#clock {display:block;}
|
#clock {display:block;}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
<!-- Matomo -->
|
|
||||||
<script>
|
|
||||||
var _paq = window._paq = window._paq || [];
|
|
||||||
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
|
|
||||||
_paq.push(['trackPageView']);
|
|
||||||
_paq.push(['enableLinkTracking']);
|
|
||||||
(function() {
|
|
||||||
var u="https://y.foxo.me/";
|
|
||||||
_paq.push(['setTrackerUrl', u+'matomo.php']);
|
|
||||||
_paq.push(['setSiteId', '2']);
|
|
||||||
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
|
|
||||||
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
|
|
||||||
})();
|
|
||||||
</script>
|
|
||||||
<!-- End Matomo Code -->
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="containedBg"></div>
|
<div class="containedBg"></div>
|
||||||
|
|
|
@ -3,4 +3,5 @@ sanic-ext
|
||||||
httpx
|
httpx
|
||||||
Pillow
|
Pillow
|
||||||
aztec_code_generator
|
aztec_code_generator
|
||||||
jinja2
|
Jinja2
|
||||||
|
Requests
|
|
@ -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)
|
Loading…
Reference in New Issue