search

Home  >  Q&A  >  body text

github - Automate deployment issues using Python

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

大家讲道理大家讲道理2748 days ago1073

reply all(1)I'll reply

  • 習慣沉默

    習慣沉默2017-05-24 11:37:21

    Restart the server using:

    ps -ef | grep uwsgi | grep -v -E 'grep' | xargs kill -USR1
    

    reply
    0
  • Cancelreply