main_sys_restart.py 1.8 KB

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