added support for fallback config files
This commit is contained in:
parent
bb089bf19c
commit
7a95b46c73
3 changed files with 22 additions and 13 deletions
|
@ -1,14 +1,10 @@
|
|||
{
|
||||
"host": "decade.cz",
|
||||
"host": "nice.wafe.eu",
|
||||
"user": "tunnel",
|
||||
"mapping": [
|
||||
{
|
||||
"remote": 50022,
|
||||
"remote": 39999,
|
||||
"local": 22
|
||||
},
|
||||
{
|
||||
"remote": 8000,
|
||||
"local": 80
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -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"]
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue