added support for fallback config files

This commit is contained in:
Martin Sekera 2019-09-17 02:11:45 +02:00
parent bb089bf19c
commit 7a95b46c73
3 changed files with 22 additions and 13 deletions

View file

@ -1,14 +1,10 @@
{
"host": "decade.cz",
"host": "nice.wafe.eu",
"user": "tunnel",
"mapping": [
{
"remote": 50022,
"remote": 39999,
"local": 22
},
{
"remote": 8000,
"local": 80
}
]
}

View file

@ -6,14 +6,27 @@ import json
import subprocess
import sys
def load_cfg(path):
with open(path) as f:
return json.loads(jsmin.jsmin(f.read()))
if __name__ == "__main__":
if len(sys.argv) == 2:
cfg_path = sys.argv[1]
else:
cfg_path = "/etc/safe-harbor/config.json"
# try config files in the order they are passed to us
# first one wins
with open(cfg_path) as f:
cfg = json.loads(jsmin.jsmin(f.read()))
cfg = None
for path in sys.argv[1:]:
try:
cfg = load_cfg(path)
break
except Exception as e:
print("! cfg file %s failed to load (%s)" %(path, e))
if not cfg:
print("!!! unable to load any configuration")
sys.exit(1)
command = ["/usr/bin/ssh", "-o", "ServerAliveInterval 45", "-o", "ServerAliveCountMax 2", "-o", "ExitOnForwardFailure yes", "-N"]

View file

@ -4,7 +4,7 @@ After=network.target
[Service]
User=%i
ExecStart=/usr/bin/python3 /usr/lib/safe-harbor/safe-harbor.py
ExecStart=/usr/bin/python3 /usr/lib/safe-harbor/safe-harbor.py /state/safe-harbor.json /etc/safe-harbor/config.json
Restart=always
RestartSec=90