diff --git a/app.py b/app.py new file mode 100644 index 0000000..b7bd7ad --- /dev/null +++ b/app.py @@ -0,0 +1,22 @@ +from flask import Flask, request +import subprocess +import json + +app = Flask(__name__) + +@app.route('/webhook', methods=['POST']) +def webhook(): + # Check if the received webhook is from Git + if request.headers.get('X-GitHub-Event') == 'push': + # Pull the latest changes from Git + subprocess.run(['git', 'pull']) + + # Restart the example_app + subprocess.run(['systemctl', 'stop', 'restart_this_app.service']) + + return 'Success!', 200 + else: + return 'Invalid webhook event.', 400 + +if __name__ == '__main__': + app.run(host='0.0.0.0', port=5001) diff --git a/restart_this_app.py b/restart_this_app.py new file mode 100644 index 0000000..79ab36c --- /dev/null +++ b/restart_this_app.py @@ -0,0 +1,14 @@ +from flask import Flask, request +import json + +app = Flask(__name__) + +@app.route('/restart-this-app') +def funky_function(): + data = { 'message': "Hello World!" } + response = json.dumps(data) + + return response, 200, { 'Content-Type': 'application/json' } + +if __name__ == '__main__': + app.run(host='0.0.0.0', port=5002)