#!/usr/bin/env python# -*- coding: utf-8 -*-# @File : deployment.py# @Author: Anthony.waa# @Date : 2018/6/26 0026# @Desc :# 服務啓動import osimport timepath = '/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')