github - Automate deployment issues using Python
大家讲道理
大家讲道理 2017-05-24 11:35:21
0
1
1071

My job is front-end, and recently I want to use GitHub's webhook Flask to do a simple automated deployment. The requirements are very simple:
Automatically pull the code through the webhook interface when there is a submission, and restart uwsgi.

New to python, code lightly.

flask code (the directory structure refers to the directory in "FLASK WEB Development", which will not be posted); the main code is as follows:

# coding=utf-8
import os
from flask import request, json, jsonify
from threading import Thread
from . import main


def restart():
    os.system('./reload.sh')


@main.route('/')
def welcome():
    user_agent = request.headers.get('User-Agent')
    return "Welcome, %s" % user_agent


@main.route('/webhook', methods=['POST'])
def webhook():
    print('---------------------begin----------------------')
    print(request.get_json())

    print('---------------------end----------------------')
    push_info = request.get_json()
    commit_info = push_info['commits']
    if push_info['ref'] == 'refs/heads/master':
        print('master分支有提交')
        print(push_info['commits'])
        os.system('git pull origin master')

    if push_info['commits'][0]['committer']['email'] == '**********@qq.com':
        print('确认是自己提交的')

    data = {
        'hello': 'world',
    }
    js = json.dumps(data)
    resp = jsonify(data)
    resp.status_code = 200
    t = Thread(target=restart,  daemon=True)
    t.start()
    return resp

reload.sh script code

#/usr/bin/sh
sleep 10s
killall -s INT /www/webhook/bin/uwsgi
sleep 10s
uwsgi uwsgi.ini

The problems encountered are as follows:

1.return语句不会执行,因为线程中把uwsgi杀死了
2.脚本关闭uwsgi报  `is taking too much time to die...NO MERCY !!!`
3.上一步时间太长导致uwsgi重启失败

Is there anyone out there who can help me figure out what’s wrong and how to fix it

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
習慣沉默

Restart the server using:

ps -ef | grep uwsgi | grep -v -E 'grep' | xargs kill -USR1
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template