当前位置: 移动技术网 > IT编程>脚本编程>Python > windows服务器实现自动化部署,启动以及暂停

windows服务器实现自动化部署,启动以及暂停

2020年04月04日  | 移动技术网IT编程  | 我要评论

为自保掐死弟弟,windows7官方下载,好货源网官网

一.环境安装

安装git桌面,配置秘钥

安装python环境

二.python-flask起服务完成自动化部署

"""
用flask 完成对项目kill与拉取
"""
from flask import flask
app =flask(__name__)
import os
import re
import requests

@app.route("/start")
def start():
    '''更新代码并执行'''
    #拉取代码 
    os.system('cd 项目绝对路径\\ && git pull')
    #重启,最好写成绝对路径
    os.popen('c:\\users\\administrator\\desktop\\snkrs-spider-py\\运行程序.exe')
    return f'已重启'

@app.route("/stop")
def stop():
    '''关闭运行程序'''
    data_str=os.popen(f'tasklist | findstr "运行程序.exe"')
    data=data_str.read()
    data = re.findall('运行程序.exe(.*?)console',chrome_data,re.m) #本地基本上以console结尾
    #data = re.findall('运行程序.exe(.*?)rdp-tcp',chrome_data,re.m) #云服务器基本上以为rdp-tcp结尾
    #具体情况具体分析
    for pid in chrome_pid_list:
        pid =pid.strip()
        os.popen(f'taskkill /f /pid {pid}')  # taskkill windows杀死进程命令 

    return f'已关闭'

#自动化你调用接口即可

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网