#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @File : deployment.py
# @Author: Anthony.waa
# @Date : 2018/6/26 0026
# @Desc :
# 服务启动
import os
import time
path = '/opt/data/'
files = os.listdir(path)
for file in files:
'''
# 遍历当前文件夹中所有文件
# 使用linux系统命令启动path路径下所有jar程序,并设置间隔为1秒
'''
# 拼接程序所在路径
split_path = path + file
split_path_service = split_path.split('/')[3]
process_info = os.popen("ps aux|grep microservice|grep -v grep|awk -F ' ' '{print $14}'")
# 判断服务是否已经启动,如果进程存在则跳过,不存在启动服务
if split_path_service not in process_info.read():
# 程序启动命令
cmding = 'nohup java -jar -Dspring.profiles.active=test %s >/dev/null 2>&1 & ' % split_path
time.sleep(0.2)
os.system(cmding)
else:
print('%s下的进程已经存在' % split_path_service)
os.system('ps aux|grep microservice')
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步