Commit a295fb99 authored by Vitaly Lipatov's avatar Vitaly Lipatov

internal: avoid restart loop on config errors

parent 27975bf5
...@@ -144,5 +144,9 @@ def run_server(host, port=82): ...@@ -144,5 +144,9 @@ def run_server(host, port=82):
httpd.serve_forever() httpd.serve_forever()
if __name__ == "__main__": if __name__ == "__main__":
try:
settings = read_settings('/etc/eterban/settings.ini') settings = read_settings('/etc/eterban/settings.ini')
run_server(settings['ban_server']) run_server(settings['ban_server'])
except (KeyError, ValueError, configparser.Error) as error:
logger.error('Invalid Eterban configuration: %s', error)
raise SystemExit(78)
...@@ -7,6 +7,7 @@ Type=simple ...@@ -7,6 +7,7 @@ Type=simple
ExecStart=/usr/bin/python3 /usr/share/eterban/eterban_internal.py ExecStart=/usr/bin/python3 /usr/share/eterban/eterban_internal.py
Restart=on-failure Restart=on-failure
RestartSec=5 RestartSec=5
RestartPreventExitStatus=78
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
...@@ -30,3 +30,14 @@ if [ "$status" -ne 78 ]; then ...@@ -30,3 +30,14 @@ if [ "$status" -ne 78 ]; then
echo "switcher without configuration returned $status, expected 78" >&2 echo "switcher without configuration returned $status, expected 78" >&2
exit 1 exit 1
fi fi
if (cd ban-internal-server/data/www && python3 -c 'from pathlib import Path; p = Path("int2.py"); code = p.read_text().replace("/etc/eterban/settings.ini", "/dev/null"); exec(compile(code, str(p), "exec"))') >/dev/null 2>&1; then
echo 'internal service without configuration must fail' >&2
exit 1
else
status=$?
fi
if [ "$status" -ne 78 ]; then
echo "internal service without configuration returned $status, expected 78" >&2
exit 1
fi
Markdown is supported
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