linux下服务启动脚本

#!/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')

猜你喜欢

转载自www.cnblogs.com/ipyanthony/p/9230669.html
今日推荐