启动 项目 @author baozi <202-02-22> @param: project_conf ( dict ): 站点配置 reconstruction ( bool ): 是否重写启动指令 @return bool : 是否启动成功
(self, project_conf, reconstruction=False)
| 1255 | return None |
| 1256 | |
| 1257 | def __start_project(self, project_conf, reconstruction=False): |
| 1258 | """启动 项目 |
| 1259 | @author baozi <202-02-22> |
| 1260 | @param: |
| 1261 | project_conf ( dict ): 站点配置 |
| 1262 | reconstruction ( bool ): 是否重写启动指令 |
| 1263 | @return bool : 是否启动成功 |
| 1264 | """ |
| 1265 | if self.get_project_run_state(project_name=project_conf["pjname"]): |
| 1266 | return True |
| 1267 | uwsgi_file = "{}/uwsgi.ini".format(project_conf['path']) |
| 1268 | gconf_file = "{}/gunicorn_conf.py".format(project_conf['path']) |
| 1269 | cmd_file = self._get_cmd_file(project_conf) |
| 1270 | if not os.path.exists(cmd_file) or not os.path.exists(uwsgi_file) or not os.path.exists(gconf_file): |
| 1271 | self.__prepare_start_conf(project_conf) |
| 1272 | pid_file = "{}/{}.pid".format(self._pid_path, project_conf["pjname"]) |
| 1273 | if os.path.exists(pid_file): |
| 1274 | os.remove(pid_file) |
| 1275 | run_user = project_conf["user"] |
| 1276 | public.ExecShell("chown -R {}:{} {}".format(run_user, run_user, project_conf["path"])) |
| 1277 | public.set_mode(cmd_file, 755) |
| 1278 | public.set_mode(self._pid_path, 777) |
| 1279 | public.set_own(cmd_file, run_user) |
| 1280 | |
| 1281 | # 处理日志文件 |
| 1282 | log_file = self._project_logfile(project_conf) |
| 1283 | if not os.path.exists(log_file): |
| 1284 | public.ExecShell("touch {}".format(log_file)) |
| 1285 | public.ExecShell("chown {}:{} {}".format(run_user, run_user, log_file)) |
| 1286 | self._pass_dir_for_user(os.path.dirname(log_file), run_user) # 让进程至少可以访问到日志文件 |
| 1287 | self._pass_dir_for_user(os.path.dirname(project_conf["path"]), run_user) # 让进程至少可以访问到程序文件 |
| 1288 | |
| 1289 | # 执行脚本文件 |
| 1290 | if project_conf["stype"] in ("uwsgi", "gunicorn"): |
| 1291 | res = public.ExecShell("{}".format(cmd_file), env=os.environ.copy()) |
| 1292 | else: |
| 1293 | res = public.ExecShell("{}".format(cmd_file), user=run_user, env=os.environ.copy()) |
| 1294 | time.sleep(1) |
| 1295 | |
| 1296 | if self._pids: |
| 1297 | self._pids = None # 清理缓存重新检查 |
| 1298 | if self.get_project_run_state(project_name=project_conf["pjname"]): |
| 1299 | return True |
| 1300 | return False |
| 1301 | |
| 1302 | def only_start_main_project(self, project_name): |
| 1303 | """启动项目api接口 |
no test coverage detected