23 lines
623 B
Python
23 lines
623 B
Python
|
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)
|