mirror of
https://github.com/chatmail/relay.git
synced 2026-05-20 12:58:04 +00:00
cmdeploy: fail init and run if SSH doesn't connect
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import importlib
|
import importlib
|
||||||
import subprocess
|
import subprocess
|
||||||
@@ -11,19 +13,21 @@ class DNS:
|
|||||||
self.out = out
|
self.out = out
|
||||||
self.ssh = f"ssh root@{mail_domain} -- "
|
self.ssh = f"ssh root@{mail_domain} -- "
|
||||||
try:
|
try:
|
||||||
self.shell(f"unbound-control flush {mail_domain}", retry_local=False, warn_reachable=True)
|
self.shell(f"unbound-control flush {mail_domain}", retry_local=False)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def shell(self, cmd, retry_local=False, warn_reachable=False):
|
def shell(self, cmd, retry_local=False):
|
||||||
try:
|
try:
|
||||||
return self.out.shell_output(f"{self.ssh}{cmd}", no_print=True, timeout=3)
|
return self.out.shell_output(f"{self.ssh}{cmd}", no_print=True, timeout=3)
|
||||||
except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as e:
|
except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as e:
|
||||||
str(e)
|
str(e)
|
||||||
if warn_reachable and ("exit status 255" in str(e) or "timed out" in str(e)):
|
|
||||||
self.out.red(f"\nWarning: can't reach the server with: {self.ssh[:-4]}")
|
|
||||||
if retry_local:
|
if retry_local:
|
||||||
return self.out.shell_output(f"{cmd}", no_print=True)
|
return self.out.shell_output(f"{cmd}", no_print=True)
|
||||||
|
else:
|
||||||
|
if "exit status 255" in str(e) or "timed out" in str(e):
|
||||||
|
self.out.red(f"\nError: can't reach the server with: {self.ssh[:-4]}")
|
||||||
|
sys.exit(1)
|
||||||
if e == subprocess.CalledProcessError:
|
if e == subprocess.CalledProcessError:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user