diff options
author | Jannis M. Hoffmann <jannis@fehcom.de> | 2023-12-06 00:16:20 +0100 |
---|---|---|
committer | Jannis M. Hoffmann <jannis@fehcom.de> | 2023-12-06 00:16:20 +0100 |
commit | b747e65de17eb65f0390731371becbe3a958a3ce (patch) | |
tree | 0f2ee644001bb90dee2a0cdf31ba498c8506b741 | |
parent | 6d6b403032a8768c63b4105e592116244b614954 (diff) |
add install script and unit file
reformat sources
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | script/install.py | 35 | ||||
-rw-r--r-- | script/jwebmail.service.in | 16 | ||||
-rw-r--r-- | src/jwebmail/__init__.py | 8 |
4 files changed, 58 insertions, 2 deletions
@@ -9,3 +9,4 @@ user_sessions *.mo src/jwebmail/static/css/ dist/ +jwebmail.prod.toml diff --git a/script/install.py b/script/install.py new file mode 100644 index 0000000..e08f8c5 --- /dev/null +++ b/script/install.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 + +import re +import sys +from pathlib import Path + + +def install_service_unit(prefix): + project_path = Path(__file__).parents[1] + + if prefix == "usr": + install_path = Path("/etc/systemd/system") + elif prefix == "usr/local": + install_path = Path("/usr/local/lib/systemd/system") + else: + raise Exception("first arg <prefix> must be one of `usr` or `usr/local`") + + def substitute(match): + if match[1] == "PROJECT_PATH": + return str(project_path) + else: + raise KeyError(match[1]) + + service_text_in = open( + project_path / "script" / "jwebmail.service.in", mode="r" + ).read() + service_text = re.sub("@(\w+)@", substitute, service_text_in, flags=re.ASCII) + + install_path.mkdir(0o755, True, True) + + open(install_path / "jwebmail.service", mode="w").write(service_text) + + +if __name__ == "__main__": + install_service_unit(sys.argv[1] if len(sys.argv) == 2 else '') diff --git a/script/jwebmail.service.in b/script/jwebmail.service.in new file mode 100644 index 0000000..2be6e5d --- /dev/null +++ b/script/jwebmail.service.in @@ -0,0 +1,16 @@ +[Unit] +Description=JWebmail managed by gunicorn +After=network.target +Requires=redis.service + +[Service] +Type=exec +User=jmhoffmann +Environment=JWEBMAIL_CONFIG="/@PREFIX@/jwebmail.toml" +ExecStart=@PROJECT_PATH@/.venv/bin/gunicorn -b :5000 -w 4 --pythonpath "@PROJECT_PATH@/src/" -n jwebmail 'jwebmail:create_app()' +ExecReload=/bin/kill -s HUP $MAINPID +KillMode=mixed +TimeoutStopSec=5 + +[Install] +WantedBy=multi-user.target diff --git a/src/jwebmail/__init__.py b/src/jwebmail/__init__.py index 26d6ffc..e1afe82 100644 --- a/src/jwebmail/__init__.py +++ b/src/jwebmail/__init__.py @@ -3,11 +3,11 @@ import pwd import sys from os import environ -from werkzeug.middleware.proxy_fix import ProxyFix from flask import Flask, g from flask_babel import Babel, get_locale from flask_login import LoginManager, login_required from jinja2 import ChainableUndefined +from werkzeug.middleware.proxy_fix import ProxyFix from .css import compile_css_command from .read_mails import load_user @@ -82,7 +82,11 @@ def create_app(): @app.context_processor def inject_version(): - return {"version": __version__, "get_locale": get_locale, "format_mail": format_mail} + return { + "version": __version__, + "get_locale": get_locale, + "format_mail": format_mail, + } @app.url_defaults def add_language_code(endpoint, values): |