Fixed VPS auto-restart on commit
This commit is contained in:
parent
bfb9ce1b84
commit
87b6b53e18
14
main.py
14
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"
|
||||
return "No", 400
|
||||
|
||||
import subprocess, os, sys
|
||||
process = subprocess.Popen(["git", "pull"], stdout=subprocess.PIPE)
|
||||
output = process.communicate()[0]
|
||||
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"]:
|
||||
|
|
Loading…
Reference in New Issue
Block a user