Fixed VPS auto-restart on commit
This commit is contained in:
parent
bfb9ce1b84
commit
87b6b53e18
18
main.py
18
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"])
|
@glob.app.route(glob.config["git"]["webhook_endpoint"], methods = ["POST"])
|
||||||
def git_fetch():
|
def git_fetch():
|
||||||
if request.method != "POST":
|
if request.method != "POST":
|
||||||
return "No"
|
return "No", 400
|
||||||
|
|
||||||
data = json.loads( request.data.decode() )
|
data = json.loads( request.data.decode() )
|
||||||
if data["secret"] != glob.config["git"]["secret"]:
|
if data["secret"] != glob.config["git"]["secret"]:
|
||||||
return "No"
|
return "No", 400
|
||||||
|
|
||||||
import subprocess, os, sys
|
from subprocess import check_output
|
||||||
process = subprocess.Popen(["git", "pull"], stdout=subprocess.PIPE)
|
output = check_output(["git", "pull", "origin", "master"])
|
||||||
output = process.communicate()[0]
|
|
||||||
|
print( "GIT: {}".format( output.decode() ) )
|
||||||
|
|
||||||
if output.decode().split("\n")[-2].find("fail") != -1:
|
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
|
# 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
|
os.execv(sys.executable, ["python"] + sys.argv) # Restart service
|
||||||
|
|
||||||
if glob.config["disable-static-cache"]:
|
if glob.config["disable-static-cache"]:
|
||||||
|
@ -37,7 +39,7 @@ if glob.config["disable-static-cache"]:
|
||||||
caching static files.
|
caching static files.
|
||||||
"""
|
"""
|
||||||
return dict(url_for=dated_url_for)
|
return dict(url_for=dated_url_for)
|
||||||
|
|
||||||
def dated_url_for(endpoint, **values):
|
def dated_url_for(endpoint, **values):
|
||||||
if endpoint == "static":
|
if endpoint == "static":
|
||||||
filename = values.get("filename", None)
|
filename = values.get("filename", None)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user