forked from forks/microblog.pub
More tweals for Yunohost support
This commit is contained in:
parent
601313cf65
commit
8837acd57f
2 changed files with 81 additions and 0 deletions
57
app/utils/yunohost.py
Normal file
57
app/utils/yunohost.py
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
"""Basic wizard for setting up microblog.pub configuration files."""
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
import bcrypt
|
||||||
|
import tomli_w
|
||||||
|
from markdown import markdown # type: ignore
|
||||||
|
|
||||||
|
from app.key import generate_key
|
||||||
|
|
||||||
|
_ROOT_DIR = Path().parent.parent.resolve()
|
||||||
|
_KEY_PATH = _ROOT_DIR / "data" / "key.pem"
|
||||||
|
_CONFIG_PATH = _ROOT_DIR / "data" / "profile.toml"
|
||||||
|
|
||||||
|
|
||||||
|
def setup_config_file(
|
||||||
|
domain: str,
|
||||||
|
username: str,
|
||||||
|
name: str,
|
||||||
|
summary: str,
|
||||||
|
password: str,
|
||||||
|
) -> None:
|
||||||
|
print("Generating microblog.pub config\n")
|
||||||
|
if _KEY_PATH.exists():
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
|
generate_key(_KEY_PATH)
|
||||||
|
|
||||||
|
config_file = _CONFIG_PATH
|
||||||
|
|
||||||
|
if config_file.exists():
|
||||||
|
# Spit out the relative path for the "config artifacts"
|
||||||
|
rconfig_file = "data/profile.toml"
|
||||||
|
print(
|
||||||
|
f"Existing setup detected, please delete {rconfig_file} "
|
||||||
|
"before restarting the wizard"
|
||||||
|
)
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
|
dat: dict[str, Any] = {}
|
||||||
|
dat["domain"] = domain
|
||||||
|
dat["username"] = username
|
||||||
|
dat["admin_password"] = bcrypt.hashpw(password.encode(), bcrypt.gensalt()).decode()
|
||||||
|
dat["name"] = name
|
||||||
|
dat["summary"] = markdown(summary)
|
||||||
|
dat["https"] = True
|
||||||
|
proto = "https"
|
||||||
|
dat["icon_url"] = f'{proto}://{dat["domain"]}/static/nopic.png'
|
||||||
|
dat["secret"] = os.urandom(16).hex()
|
||||||
|
|
||||||
|
with config_file.open("w") as f:
|
||||||
|
f.write(tomli_w.dumps(dat))
|
||||||
|
|
||||||
|
print("Done")
|
||||||
|
sys.exit(0)
|
24
misc/ynh-supervisord.conf
Normal file
24
misc/ynh-supervisord.conf
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
[supervisord]
|
||||||
|
|
||||||
|
[fcgi-program:uvicorn]
|
||||||
|
socket=tcp://localhost:%(ENV_UVICORN_PORT)
|
||||||
|
command=%(ENV_VENV_DIR)s/bin/uvicorn app.main:app --no-server-header --fd 0
|
||||||
|
numprocs=2
|
||||||
|
process_name=uvicorn-%(process_num)d
|
||||||
|
redirect_stderr=true
|
||||||
|
stdout_logfile=uvicorn.log
|
||||||
|
stdout_logfile_maxbytes=0
|
||||||
|
|
||||||
|
[program:incoming_worker]
|
||||||
|
command=%(ENV_VENV_DIR)s/bin/inv process-incoming-activities
|
||||||
|
numproc=1
|
||||||
|
redirect_stderr=true
|
||||||
|
stdout_logfile=incoming_worker.log
|
||||||
|
stdout_logfile_maxbytes=0
|
||||||
|
|
||||||
|
[program:outgoing_worker]
|
||||||
|
command=%(ENV_VENV_DIR)s/bin/inv process-outgoing-activities
|
||||||
|
numproc=1
|
||||||
|
redirect_stderr=true
|
||||||
|
stdout_logfile=outgoing_worker.log
|
||||||
|
stdout_logfile_maxbytes=0
|
Loading…
Reference in a new issue