@name 启动项目 @author hwliang<2021-08-09> @param get { project_name: string<项目名称> } @return dict
(self, get)
| 2567 | return public.returnMsg(True, '重启成功') |
| 2568 | |
| 2569 | def start_project(self, get): |
| 2570 | ''' |
| 2571 | @name 启动项目 |
| 2572 | @author hwliang<2021-08-09> |
| 2573 | @param get<dict_obj>{ |
| 2574 | project_name: string<项目名称> |
| 2575 | } |
| 2576 | @return dict |
| 2577 | ''' |
| 2578 | project_find = self.get_project_find(get.project_name) |
| 2579 | if not project_find: return public.returnMsg(False, '项目不存在') |
| 2580 | |
| 2581 | project_find = self.get_project_find(get.project_name) |
| 2582 | if project_find['edate'] != "0000-00-00" and project_find['edate'] < datetime.datetime.today().strftime("%Y-%m-%d"): |
| 2583 | return public.return_error('当前项目已过期,请重新设置项目到期时间') |
| 2584 | |
| 2585 | self._update_project(get.project_name, project_find) |
| 2586 | if project_find['project_config']['java_type'] == 'duli': |
| 2587 | get.domain = project_find['name'] |
| 2588 | get.type = 'start' |
| 2589 | return self.pendent_tomcat_start(get) |
| 2590 | if project_find['project_config']['java_type'] == 'neizhi': |
| 2591 | get.version = project_find['project_config']['tomcat_version'] |
| 2592 | get.type = 'start' |
| 2593 | return self.start_tomcat(get) |
| 2594 | if project_find['project_config']['java_type'] == 'springboot': |
| 2595 | project_cmd = project_find["project_config"]['project_cmd'] |
| 2596 | # 前置准备 |
| 2597 | log_file = project_find["project_config"]['logs'] |
| 2598 | pid_file = project_find["project_config"]['pids'] |
| 2599 | nohup_log = ' &>> {log_file}'.format(log_file = log_file) |
| 2600 | if not int(project_find["project_config"].get('nohup_log', 1)): |
| 2601 | nohup_log = '' |
| 2602 | if 'jar_path' in project_find['project_config']: |
| 2603 | jar_path = project_find['project_config']['jar_path'] |
| 2604 | else: |
| 2605 | jar_path = '{}'.format(self._springboot) |
| 2606 | # 启动脚本 |
| 2607 | start_cmd = '''#!/bin/bash |
| 2608 | PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin |
| 2609 | export PATH |
| 2610 | cd {jar_path} |
| 2611 | nohup {project_cmd}{nohup_log} & |
| 2612 | echo $! > {pid_file} |
| 2613 | '''.format( |
| 2614 | jar_path = jar_path, |
| 2615 | project_cmd = project_cmd, |
| 2616 | pid_file = pid_file, |
| 2617 | log_file = log_file, |
| 2618 | nohup_log = nohup_log |
| 2619 | ) |
| 2620 | script_file = project_find["project_config"]['scripts'] |
| 2621 | # 写入启动脚本 |
| 2622 | public.writeFile(script_file, start_cmd) |
| 2623 | if os.path.exists(pid_file): os.remove(pid_file) |
| 2624 | public.ExecShell("chmod -R 777 /var/tmp/springboot/") |
| 2625 | # public.ExecShell("chown -R {}:{} {}".format(project_find['project_config']['run_user'],project_find['project_config']['run_user'],self._springboot)) |
| 2626 | public.set_mode(script_file, 755) |
no test coverage detected