@name 获取项目运行状态信息 @param sitename 项目名称 @return dict
(self, get)
| 1000 | |
| 1001 | # 获取项目状态 |
| 1002 | def get_project_run_state(self, get): |
| 1003 | ''' |
| 1004 | @name 获取项目运行状态信息 |
| 1005 | @param sitename<string> 项目名称 |
| 1006 | @return dict |
| 1007 | ''' |
| 1008 | try: |
| 1009 | sitename = get.sitename.strip() |
| 1010 | result = {} |
| 1011 | project_info = self.get_project_find(sitename) |
| 1012 | res = RealServer().daemon_status(sitename) |
| 1013 | result['status'] = res['status'] |
| 1014 | result['sitename'] = sitename |
| 1015 | result['is_power_on'] = int(project_info["project_config"]['is_power_on']) |
| 1016 | result['project_path'] = project_info['path'] # type : str |
| 1017 | result['project_cmd'] = project_info["project_config"].get('start_cmd', '') |
| 1018 | result['project_port'] = project_info['project_config']['port'] |
| 1019 | if result['project_path'][-1] != "/": |
| 1020 | result['project_path'] += "/" |
| 1021 | result['site_run_path'] = DirTool().get_site_run_path(sitename).replace(result['project_path'].rstrip("/"), "") |
| 1022 | if not result['site_run_path']: |
| 1023 | result['site_run_path'] = "/" |
| 1024 | result['php_version'] = project_info['project_config']['php_version'] |
| 1025 | result['run_user'] = project_info['project_config'].get('run_user', 'www') |
| 1026 | result['ps'] = project_info['ps'] |
| 1027 | result['pid'] = RealServer().get_daemon_pid(sitename)["data"] |
| 1028 | if result['pid'] in [0, '0', ''] and result['status']: |
| 1029 | res = public.ExecShell("""ps -aux |grep "{}"|grep -v "grep"|awk '{{print $2}}'""".format(result['project_cmd']))[0] |
| 1030 | res = res.strip().split("\n") |
| 1031 | if res and len(res) >= 1: |
| 1032 | res.sort() |
| 1033 | result['pid'] = res[0] |
| 1034 | result['Listen'] = [] |
| 1035 | if result['pid']: |
| 1036 | children = RealProcess().get_process_tree(result['pid'])["data"] |
| 1037 | for chi in children: |
| 1038 | for i in chi.get("connections", []): |
| 1039 | port = i.get("local_port", '') |
| 1040 | addr = i.get("local_addr", '') |
| 1041 | status = i.get("status", 'dasd') |
| 1042 | if addr == '0.0.0.0': |
| 1043 | addr = public.GetLocalIp() |
| 1044 | if port and addr and status.lower() == 'listen': |
| 1045 | result['Listen'].append((addr, port)) |
| 1046 | result['Listen'] = list(set(result['Listen'])) |
| 1047 | |
| 1048 | return public.returnResult(True, data=result) |
| 1049 | except: |
| 1050 | public.print_log(traceback.format_exc()) |
| 1051 | return public.returnResult(False, '获取项目状态失败') |
| 1052 | |
| 1053 | # 修改项目运行状态 |
| 1054 | def modify_project_run_state(self, get): |
no test coverage detected