From 87b6b53e180f60945b74423daffb4850eda597b8 Mon Sep 17 00:00:00 2001 From: Sunpy Date: Sat, 2 Mar 2019 20:39:36 +0000 Subject: [PATCH] Fixed VPS auto-restart on commit --- main.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index b5095d7..5aff984 100644 --- a/main.py +++ b/main.py @@ -10,21 +10,23 @@ if glob.config["git"]["auto_pull_and_restart"]: # Only used on the VPS (Do not e @glob.app.route(glob.config["git"]["webhook_endpoint"], methods = ["POST"]) def git_fetch(): if request.method != "POST": - return "No" + return "No", 400 data = json.loads( request.data.decode() ) if data["secret"] != glob.config["git"]["secret"]: - return "No" - - import subprocess, os, sys - process = subprocess.Popen(["git", "pull"], stdout=subprocess.PIPE) - output = process.communicate()[0] + return "No", 400 + + from subprocess import check_output + output = check_output(["git", "pull", "origin", "master"]) + + print( "GIT: {}".format( output.decode() ) ) if output.decode().split("\n")[-2].find("fail") != -1: - return "Failed to pull changes" + return "Failed to pull changes", 500 # If needed; every open file or connection HAVE to be closed at this point + import os, sys os.execv(sys.executable, ["python"] + sys.argv) # Restart service if glob.config["disable-static-cache"]: @@ -37,7 +39,7 @@ if glob.config["disable-static-cache"]: caching static files. """ return dict(url_for=dated_url_for) - + def dated_url_for(endpoint, **values): if endpoint == "static": filename = values.get("filename", None)