main_sys_restart.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. from .tool.func import *
  2. def main_sys_restart_do():
  3. print('Restart')
  4. time.sleep(3)
  5. python_ver = ''
  6. python_ver = str(sys.version_info.major) + '.' + str(sys.version_info.minor)
  7. run_list = [
  8. sys.executable,
  9. 'python' + python_ver,
  10. 'python3',
  11. 'python',
  12. 'py -' + python_ver
  13. ]
  14. for exe_name in run_list:
  15. try:
  16. subprocess.Popen([exe_name] + sys.argv)
  17. break
  18. except:
  19. continue
  20. os._exit(0)
  21. async def main_sys_restart(golang_process):
  22. with get_db_connect() as conn:
  23. if await acl_check('', 'owner_auth', '', '') == 1:
  24. return await re_error(conn, 3)
  25. if flask.request.method == 'POST':
  26. await acl_check(tool = 'owner_auth', memo = 'restart')
  27. if golang_process.poll() is None:
  28. golang_process.terminate()
  29. try:
  30. golang_process.wait(timeout = 5)
  31. except subprocess.TimeoutExpired:
  32. golang_process.kill()
  33. try:
  34. golang_process.wait(timeout = 5)
  35. except subprocess.TimeoutExpired:
  36. print('Golang process not terminated properly.')
  37. threading.Thread(target = main_sys_restart_do).start()
  38. return flask.Response(get_lang(conn, "warning_restart"), status = 200)
  39. else:
  40. return easy_minify(conn, flask.render_template(skin_check(conn),
  41. imp = [get_lang(conn, 'wiki_restart'), await wiki_set(), await wiki_custom(conn), wiki_css([0, 0])],
  42. data = '''
  43. <form method="post">
  44. <button type="submit">''' + get_lang(conn, 'restart') + '''</button>
  45. </form>
  46. ''',
  47. menu = [['manager', get_lang(conn, 'return')]]
  48. ))