Auto-pull and restart for VPS
This commit is contained in:
parent
78c79fdbf5
commit
d4e787a547
24
main.py
24
main.py
|
@ -1,10 +1,32 @@
|
|||
from flask import Flask, url_for
|
||||
import json
|
||||
from flask import Flask, url_for, request
|
||||
from objects import glob # Global sharing of python objects in a manageable way
|
||||
|
||||
glob.app = Flask(__name__)
|
||||
|
||||
import routes # All flask app routes
|
||||
|
||||
if glob.config["git"]["auto_pull_and_restart"]: # Only used on the VPS (Do not enable in config)
|
||||
@glob.app.route(glob.config["git"]["webhook_endpoint"], methods = ["POST"])
|
||||
def git_fetch():
|
||||
if request.method != "POST":
|
||||
return "No"
|
||||
|
||||
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]
|
||||
|
||||
if output.decode().split("\n")[-2].find("fail") != -1:
|
||||
return "Failed to pull changes"
|
||||
|
||||
# If needed; every open file or connection HAVE to be closed at this point
|
||||
|
||||
os.execv(sys.executable, ["python"] + sys.argv) # Restart service
|
||||
|
||||
if glob.config["disable-static-cache"]:
|
||||
import os
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user