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",
|
"user": "tunnel",
|
||||||
"mapping": [
|
"mapping": [
|
||||||
{
|
{
|
||||||
"remote": 50022,
|
"remote": 39999,
|
||||||
"local": 22
|
"local": 22
|
||||||
},
|
|
||||||
{
|
|
||||||
"remote": 8000,
|
|
||||||
"local": 80
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,14 +6,27 @@ import json
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
def load_cfg(path):
|
||||||
|
with open(path) as f:
|
||||||
|
return json.loads(jsmin.jsmin(f.read()))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if len(sys.argv) == 2:
|
# try config files in the order they are passed to us
|
||||||
cfg_path = sys.argv[1]
|
# first one wins
|
||||||
else:
|
|
||||||
cfg_path = "/etc/safe-harbor/config.json"
|
|
||||||
|
|
||||||
with open(cfg_path) as f:
|
cfg = None
|
||||||
cfg = json.loads(jsmin.jsmin(f.read()))
|
|
||||||
|
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"]
|
command = ["/usr/bin/ssh", "-o", "ServerAliveInterval 45", "-o", "ServerAliveCountMax 2", "-o", "ExitOnForwardFailure yes", "-N"]
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ After=network.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
User=%i
|
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
|
Restart=always
|
||||||
RestartSec=90
|
RestartSec=90
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue