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')


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM