由于生产环境在客户现场,每次远程过去更新费时费力,现场的人员后不会敲linux命令,抽空用python写了个脚本,以后的更新简单方便。话不多说,先展示脚本。
#!/usr/local/python/bin/python3
#coding=utf-8
import os
import subprocess
import time
import signal
print("1 更新前端\n2 更新后端")
input = input("请选择:")
pid = subprocess.getoutput("ps -ef|grep officialwebsite-0.0.1-SNAPSHOT.jar|grep -v grep | awk '{print $2}'")
def start():
os.system("cd /opt && rm -rf officialwebsite-0.0.1-SNAPSHOT.jar* && rz && ./start.sh")
with open('/opt/gw.log') as f:
f.seek(0,2)
while True:
last_pos = f.tell()
line = f.readline()
if line:
print(line)
if "Started OfficaialWebsiteApplication" in line:
break
pid1 = subprocess.getoutput("ps -ef|grep officialwebsite-0.0.1-SNAPSHOT.jar|grep -v grep | awk '{print $2}'")
if pid1:
print("\033[1;32m----------------后端更新完成----------------\033[0m")
else:
print("\033[1;31m----------------更新出错啦!----------------\033[0m")
if int(input) == 1:
print("----------------请上传前端包----------------")
os.system("cd /usr/local/nginx/html/zdzr && rm -rf dist* && rz && unzip dist.zip")
print("\033[1;32m----------------前端更新完成----------------\033[0m")
elif int(input) == 2:
if pid:
os.kill(int(pid),signal.SIGKILL)
print("------------------结束进程------------------")
print("----------------请上传后端包----------------")
start()
else:
print("---------------后端服务未启动---------------")
print("----------------请上传后端包----------------")
start()
else:
print("NMSL")
项目包含前后端,前端nginx静态页面,后端jar包,脚本运行环境python3