@name Python 项目守护进程 @author baozi@bt.cn @time 2023-10-21
()
| 76 | |
| 77 | |
| 78 | def PythonDaemons(): |
| 79 | ''' |
| 80 | @name Python 项目守护进程 |
| 81 | @author baozi@bt.cn |
| 82 | @time 2023-10-21 |
| 83 | ''' |
| 84 | boot_time = psutil.boot_time() |
| 85 | now = time.time() |
| 86 | boot_start = int(now - boot_time) < 60 * 10 |
| 87 | if public.M('sites').where('project_type=?', ('Python')).count() >= 1: |
| 88 | project_info = public.M('sites').where('project_type=?', ('Python')).select() |
| 89 | for i in project_info: |
| 90 | try: |
| 91 | import json |
| 92 | from projectModel import pythonModel |
| 93 | |
| 94 | i['project_config'] = json.loads(i['project_config']) |
| 95 | if 'auto_run' in i['project_config'] and i['project_config']['auto_run'] in ["1", 1, True, "true"]: |
| 96 | python_obj = pythonModel.main() |
| 97 | if python_obj.get_project_run_state(project_name=i['name']): |
| 98 | continue |
| 99 | else: |
| 100 | if not python_obj.is_stop_by_user(i["id"]) or boot_start: |
| 101 | # 如果项目是在后台停止的,那么就不再启动 |
| 102 | get = public.dict_obj() |
| 103 | get.name = i['name'] |
| 104 | python_obj.StartProject(get) |
| 105 | public.WriteLog('守护进程', 'Python项目[{}]已经被守护进程启动'.format(i['name'])) |
| 106 | except: |
| 107 | continue |
| 108 | |
| 109 | |
| 110 | def NetDaemons(): |
no test coverage detected