use subprocess instead
This commit is contained in:
parent
22328683ea
commit
c2acfa6431
2 changed files with 5 additions and 5 deletions
27
lib/safe-harbor.py
Executable file
27
lib/safe-harbor.py
Executable file
|
@ -0,0 +1,27 @@
|
|||
#! /usr/bin/env python3
|
||||
# encoding: utf-8
|
||||
|
||||
import jsmin
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) == 2:
|
||||
cfg_path = sys.argv[1]
|
||||
else:
|
||||
cfg_path = "/etc/safe-harbor/config.json"
|
||||
|
||||
with open(cfg_path) as f:
|
||||
cfg = json.loads(jsmin.jsmin(f.read()))
|
||||
|
||||
command = ["/usr/bin/ssh", "-o", "ServerAliveInterval 45", "-o", "ServerAliveCountMax 2", "-o", "ExitOnForwardFailure yes", "-N"]
|
||||
|
||||
for m in cfg["mapping"]:
|
||||
command.append("-R")
|
||||
command.append("%d:localhost:%d" %(m["remote"], m["local"]))
|
||||
|
||||
command.append("%s@%s" %(cfg["user"], cfg["host"]))
|
||||
|
||||
# replace this process, systemd will restart us if needed
|
||||
subprocess.run(command)
|
Loading…
Add table
Add a link
Reference in a new issue