MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / stop_project

Method stop_project

class/projectModel/nodejsModel.py:1628–1668  ·  view source on GitHub ↗

@name 停止项目 @author hwliang<2021-08-09> @param get { project_name: string<项目名称> } @return dict

(self,get)

Source from the content-addressed store, hash-verified

1626
1627
1628 def stop_project(self,get):
1629 ''&#x27;
1630 @name 停止项目
1631 @author hwliang<2021-08-09>
1632 @param get<dict_obj>{
1633 project_name: string<项目名称>
1634 }
1635 @return dict
1636 ''&#x27;
1637 project_find = self.get_project_find(get.project_name)
1638 if not project_find: return public.return_error('项目不存在')
1639 project_find = self.get_project_find(get.project_name)
1640 if project_find['edate'] != "0000-00-00" and project_find['edate'] < datetime.datetime.today().strftime("%Y-%m-%d"):
1641 return public.return_error('当前项目已过期,请重新设置项目到期时间')
1642 project_script = project_find['project_config']['project_script'].strip().replace(' ',' ')
1643 pid_file = "{}/{}.pid".format(self._node_pid_path,get.project_name)
1644 if project_script.find('pm2 start') != -1: # 处理PM2启动的项目
1645 nodejs_version = project_find['project_config']['nodejs_version']
1646 last_env = self.get_last_env(nodejs_version,project_find['path'])
1647 project_script = project_script.replace('pm2 start','pm2 stop')
1648 public.ExecShell(''&#x27;{}
1649cd {}
1650{}'''.format(last_env,project_find['path&#x27;],project_script))
1651 else:
1652 pid_file = "{}/{}.pid".format(self._node_pid_path,get.project_name)
1653 if not os.path.exists(pid_file): return public.return_error('项目未启动')
1654 data = public.readFile(pid_file)
1655 if isinstance(data,str) and data:
1656 pid = int(data)
1657 pids = self.get_project_pids(pid=pid)
1658 else:
1659 return public.return_error('项目未启动')
1660 if not pids: return public.return_error('项目未启动')
1661 self.kill_pids(pids=pids)
1662 if os.path.exists(pid_file): os.remove(pid_file)
1663 time.sleep(0.5)
1664 pids = self.get_project_state_by_cwd(get.project_name)
1665 if pids: self.kill_pids(pids=pids)
1666
1667 self.stop_by_user(project_find["id"])
1668 return public.return_data(True, '停止成功')
1669
1670 def restart_project(self,get):
1671 ''&#x27;

Callers 4

remove_projectMethod · 0.95
start_projectMethod · 0.95
restart_projectMethod · 0.95
change_log_pathMethod · 0.95

Calls 14

get_project_findMethod · 0.95
get_last_envMethod · 0.95
get_project_pidsMethod · 0.95
kill_pidsMethod · 0.95
ExecShellMethod · 0.80
readFileMethod · 0.80
replaceMethod · 0.45
formatMethod · 0.45
findMethod · 0.45
existsMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected