Commit 27975bf5 authored by Vitaly Lipatov's avatar Vitaly Lipatov

gateway: avoid restarting switcher on config errors

parent 82460dc5
......@@ -4,6 +4,7 @@ After=syslog.target network.target
[Service]
Restart=always
RestartPreventExitStatus=78
ExecStart=/usr/bin/python3 /usr/share/eterban/eterban_switcher.py
[Install]
......
......@@ -45,7 +45,7 @@ def parse_config (path_to_config, path_to_log):
info +=' ' + 'Problem in config file (' + path_to_config + '). Check him!'
with open(path_to_log, "a") as log_file:
log_file.write(info)
sys.exit(1)
sys.exit(78)
config = configparser.ConfigParser()
config.read(path_to_config)
......@@ -96,14 +96,14 @@ def parse_config (path_to_config, path_to_log):
info += " Problem in config file (" + path_to_config + "): " + str(error) + "\n"
with open(path_to_log, "a") as log_file:
log_file.write(info)
sys.exit(1)
sys.exit(78)
if redis_server == "redis_server" or ban_server == "ban_server" or not wan_ifaces:
info = time.strftime( "%Y-%m-%d %H:%M:%S", time.localtime())
info +=' ' + 'Problem in config file (' + path_to_config + '). Check him!'
with open(path_to_log, "a") as log_file:
log_file.write(info)
sys.exit(1)
sys.exit(78)
else:
return (redis_server, ban_server, ban_server_ipv6, wan_ifaces, internal_interface, maxelem, whitelist_file)
......
......@@ -19,3 +19,14 @@ if python3 -c 'from pathlib import Path; p = Path("prod-server/usr/share/eterban
echo 'ban.py without configuration must fail' >&2
exit 1
fi
if (cd gateway/usr/share/eterban && python3 -c 'from pathlib import Path; p = Path("eterban_switcher.py"); code = p.read_text().replace("/etc/eterban/settings.ini", "/dev/null").replace("/var/log/eterban/eterban.log", "/tmp/eterban-switcher-static-check.log"); exec(compile(code, str(p), "exec"))') >/dev/null 2>&1; then
echo 'switcher without configuration must fail' >&2
exit 1
else
status=$?
fi
if [ "$status" -ne 78 ]; then
echo "switcher 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