github - 利用Python 自動化部署問題
問題描述
本職是前端,最近想利用GitHub的webhook + Flask 搞個簡單的自動化部署,需求很簡單:在有提交的時候通過webhook接口自動拉取代碼,并重啟uwsgi。
python新手,代碼輕噴。
flask代碼(目錄結構參考的《FLASK WEB開發》中的目錄,就不貼了);主要的代碼如下:
# coding=utf-8import osfrom flask import request, json, jsonifyfrom threading import Threadfrom . import maindef 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腳本代碼
#/usr/bin/shsleep 10skillall -s INT /www/webhook/bin/uwsgisleep 10suwsgi uwsgi.ini
遇到的問題如下:
1.return語句不會執行,因為線程中把uwsgi殺死了2.腳本關閉uwsgi報 `is taking too much time to die...NO MERCY !!!`3.上一步時間太長導致uwsgi重啟失敗
有木有大神幫忙看下有什么問題,可以怎么改
問題解答
回答1:重啟服務器可以用:
ps -ef | grep uwsgi | grep -v -E ’grep’ | xargs kill -USR1
相關文章:
1. mysql - AttributeError: ’module’ object has no attribute ’MatchType’2. python - from ..xxxx import xxxx到底是什么意思呢?3. 求大神幫我看看是哪里寫錯了 感謝細心解答4. npm鏡像站全新上線5. javascript - 圖片能在網站顯示,但控制臺仍舊報錯403 (Forbidden)6. 網頁爬蟲 - python爬蟲翻頁問題,請問各位大神我這段代碼怎樣翻頁,還有價格要登陸后才能看到,應該怎么解決7. php自學從哪里開始?8. MySQL客戶端吃掉了SQL注解?9. phpstady在win10上運行10. 數據庫 - MySQL 單表500W+數據,查詢超時,如何優化呢?
