diff --git a/gateway.py b/gateway.py index a4273f6..c5a1175 100644 --- a/gateway.py +++ b/gateway.py @@ -237,6 +237,19 @@ class Gateway(): print('timedout', flush=True) return False + def reboot_device(self, wait_timeout = None): + try: + params = { 'client': 'web' } + res = requests.post(gw.apiurl + "xqsystem/reboot", params = params, timeout=self.timeout) + if res.text.find('"code":0') < 0: + return False + if wait_timeout: + if not self.wait_shutdown(wait_timeout): + return False + return True + except Exception as e: + return False + #=============================================================================== def shutdown(self): if self.use_ssh: diff --git a/reboot.py b/reboot.py index 01a52a1..75e1860 100644 --- a/reboot.py +++ b/reboot.py @@ -10,9 +10,20 @@ import gateway from gateway import die -gw = gateway.Gateway() +gw = gateway.Gateway(detect_ssh = False) -print("Send command...") -gw.run_cmd("reboot") +ssh = gw.detect_ssh(verbose = 1, interactive = True) +if ssh > 0: + print('Send command "reboot" via SSH ...') + gw.run_cmd("reboot") +else: + if not gw.stok: + gw.web_login() + print('Send command "reboot" via WEB API ...') + if not gw.reboot_device(): + die('Can\'t run reboot command.') + +if not gw.wait_shutdown(10): + die('The "reboot" command did not shutdown the device.') print("Reboot activated!")