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

转载于:https://www.cnblogs.com/ipyanthony/p/9230669.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值