fix update
This commit is contained in:
parent
bcbbf99cab
commit
96eecd5c34
@ -1,10 +1,12 @@
|
||||
import time
|
||||
import logging
|
||||
import threading
|
||||
import platform
|
||||
|
||||
from flask import Flask, redirect, url_for
|
||||
|
||||
from src.interface.ObController import ObController
|
||||
from src.util.utils import run_system_command, sudo_run_system_command, get_working_directory, am_i_in_docker
|
||||
from src.util.utils import run_system_command, sudo_run_system_command, get_working_directory, am_i_in_docker, restart
|
||||
from src.Application import Application
|
||||
|
||||
|
||||
@ -14,6 +16,17 @@ class GitUpdaterController(ObController):
|
||||
self._app.add_url_rule('/git-updater/update/now', 'git_updater_update_now', self._auth(self.update_now), methods=['GET'])
|
||||
|
||||
def update_now(self):
|
||||
secret = self._model_store.config().map().get('secret_key')
|
||||
debug = self._model_store.config().map().get('debug')
|
||||
thread = threading.Thread(target=self.update, args=(debug,))
|
||||
thread.daemon = True
|
||||
thread.start()
|
||||
|
||||
return redirect(url_for('manage'))
|
||||
|
||||
def update(self, debug: bool) -> None:
|
||||
time.sleep(1)
|
||||
|
||||
old_version = Application.get_version()
|
||||
logging.info("🚧 Application update from {} to master...".format(old_version))
|
||||
|
||||
@ -38,7 +51,6 @@ class GitUpdaterController(ObController):
|
||||
|
||||
if os_name == "linux":
|
||||
logging.warn('Git Updater supports linux process manager, using apt...')
|
||||
sudo_run_system_command(['systemctl', 'restart', Application.get_name()])
|
||||
elif os_name == "windows":
|
||||
logging.warn('Git Updater doesn\'t fully supports windows process manager, you may need to restart application manually')
|
||||
elif os_name == "darwin":
|
||||
@ -51,7 +63,5 @@ class GitUpdaterController(ObController):
|
||||
else:
|
||||
logging.info("🧊 Application already up to date with version {}".format(new_version))
|
||||
|
||||
return redirect(url_for(
|
||||
'sysinfo_restart',
|
||||
secret_key=self._model_store.config().map().get('secret_key')
|
||||
))
|
||||
restart(debug)
|
||||
|
||||
@ -11,7 +11,7 @@ from src.manager.ConfigManager import ConfigManager
|
||||
from src.service.ModelStore import ModelStore
|
||||
|
||||
from src.interface.ObController import ObController
|
||||
from src.util.utils import am_i_in_docker
|
||||
from src.util.utils import restart
|
||||
from src.util.UtilNetwork import get_ip_address
|
||||
from src.service.Sysinfo import get_all_sysinfo
|
||||
|
||||
@ -34,9 +34,14 @@ class SysinfoController(ObController):
|
||||
)
|
||||
|
||||
def sysinfo_restart(self):
|
||||
debug = self._model_store.config().map().get('debug')
|
||||
secret = self._model_store.config().map().get('secret_key')
|
||||
challenge = request.args.get('secret_key')
|
||||
thread = threading.Thread(target=self.restart, args=(secret, challenge))
|
||||
|
||||
if secret != challenge:
|
||||
return jsonify({'status': 'error'})
|
||||
|
||||
thread = threading.Thread(target=restart, args=(debug,))
|
||||
thread.daemon = True
|
||||
thread.start()
|
||||
|
||||
@ -51,28 +56,6 @@ class SysinfoController(ObController):
|
||||
|
||||
return jsonify({'status': True})
|
||||
|
||||
def restart(self, secret: str, challenge: str) -> None:
|
||||
time.sleep(1)
|
||||
|
||||
if secret != challenge:
|
||||
return jsonify({'status': 'error'})
|
||||
|
||||
if platform.system().lower() == 'darwin':
|
||||
if self._model_store.config().map().get('debug'):
|
||||
python = sys.executable
|
||||
os.execl(python, python, *sys.argv)
|
||||
elif am_i_in_docker():
|
||||
python = sys.executable
|
||||
os.execl(python, python, *sys.argv)
|
||||
else:
|
||||
try:
|
||||
subprocess.run(["sudo", "systemctl", "restart", 'obscreen-studio'], check=True, timeout=10, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
pass
|
||||
except subprocess.TimeoutExpired:
|
||||
pass
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
|
||||
def sysinfo_get_ipaddr(self):
|
||||
ipaddr = get_ip_address()
|
||||
return ipaddr if ipaddr else ''
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
import inspect
|
||||
import subprocess
|
||||
import unicodedata
|
||||
import platform
|
||||
|
||||
|
||||
from typing import Optional, List, Dict
|
||||
@ -210,3 +213,24 @@ def get_function_caller(depth: int = 3) -> str:
|
||||
|
||||
def clamp(x: float, minimum: float, maximum: float) -> float:
|
||||
return max(minimum, min(x, maximum))
|
||||
|
||||
|
||||
def restart(debug: bool) -> None:
|
||||
time.sleep(1)
|
||||
|
||||
if platform.system().lower() == 'darwin':
|
||||
if debug:
|
||||
python = sys.executable
|
||||
os.execl(python, python, *sys.argv)
|
||||
elif am_i_in_docker():
|
||||
python = sys.executable
|
||||
os.execl(python, python, *sys.argv)
|
||||
else:
|
||||
try:
|
||||
subprocess.run(["sudo", "systemctl", "restart", 'obscreen-studio'], check=True, timeout=10, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
pass
|
||||
except subprocess.TimeoutExpired:
|
||||
pass
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
|
||||
Loading…
Reference in New Issue
Block a user