Commit f4da814b authored by Vladimír Štill's avatar Vladimír Štill
Browse files

Add templates for systemd unit+socket

parent bb49da64
Pipeline #65644 passed with stage
in 52 seconds
[Unit]
Description=FJA web frontend
[Service]
Type=simple
WorkingDirectory={{workdir | default("/var/lib/fjaweb")}}
Environment=PYTHONPATH={{workdir | default("/var/lib/fjaweb")}}
ExecStart={{uwsgi | default("/usr/bin/uwsgi")}} \
-s {{socket | default("/run/uwsgi/fjaweb.socket")}} \
--manage-script-name --plugin python3 \
--mount '/=evalweb:create_app()'
User={{user | default("fjaweb")}}
Group={{group | default("nginx")}}
Restart=always
RestartSec=2
TimeoutStopSec=300
{% if quota | default(True) %}
CPUAccounting=true
MemoryAccounting=true
Nice=10
# quota for one CPU
CPUQuota={{quota_cpu | default("10%")}}
MemoryHigh={{quota_mem_high | default("800M")}}
MemoryMax={{quota_mem_max | default("1G")}}
{% endif %}
[Unit]
StartLimitBurst=0
StartLimitIntervalSec=0
# vim: ft=systemd
[Unit]
Description=Socket for FJA web frontend
[Socket]
ListenStream={{socket | default("/run/uwsgi/fjaweb.socket")}}
SocketUser={{user | default("fjaweb")}}
SocketGroup={{group | default("nginx")}}
SocketMode=0660
[Install]
WantedBy=sockets.target
# vim: ft=systemd
#!/usr/bin/env bash
# vim: ft=bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
if [[ "$1" = "--help" ]]; then
echo -e "usage: $0 [--workdir WORKDIR] [--uwsgi UWSGI_BINARY_PATH]\n" \
" [--user USENAME] [--group GROUPNAME]\n" \
" [--[no-]quota] [--quota-cpu CPU_QUOTA]\n" \
" [--quota-mem-high MEM_QUOTA] [--quota-mem-max MEM_QUOTA]\n"
exit 1
fi
for i in "socket" "service"; do
$DIR/../utils/render-template $DIR/fjaweb.$i.j2 /etc/systemd/system/fjaweb.$i "$@"
done
#!/usr/bin/env python3
import jinja2
import sys
from typing import Dict, Union
def die(msg: str) -> None:
print("ERROR: ", msg, file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
in_file = sys.argv[1]
out_file = sys.argv[2]
args: Dict[str, Union[str, bool]] = {}
i = 3
while i < len(sys.argv):
arg = sys.argv[i]
if not arg.startswith("--"):
die("argument {arg} does not start with --")
key = arg[2:]
if i != len(sys.argv) - 1 and not sys.argv[i + 1].startswith("--"):
args[key.replace("-", "_")] = sys.argv[i + 1]
i += 2
else:
bval = True
if key.startswith("no-"):
bval = False
key = key[3:]
args[key.replace("-", "_")] = bval
i += 1
template = jinja2.Template(open(in_file, "r").read())
out = open(out_file, "w")
out.write(template.render(**args))
# vim: ft=python
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment