File size: 1,231 Bytes
75a0eaa ace970e 75a0eaa | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | import subprocess
import time
import os
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/')
def health_check():
return jsonify({"status": "3x-ui is running"})
@app.route('/health')
def health():
# Check if 3x-ui process is alive
result = subprocess.run(['pgrep', 'x-ui'], capture_output=True)
if result.returncode == 0:
return jsonify({"status": "healthy"}), 200
return jsonify({"status": "unhealthy"}), 503
if __name__ == '__main__':
# Change port
subprocess.run(['/usr/bin/x-ui', 'setting', '-port', '7860'])
# Start 3x-ui in background
subprocess.Popen(['/usr/bin/x-ui', 'start'])
time.sleep(5)
# Run Flask on the same port? No, it's occupied.
# We'll run Flask on port 7860 and use it as a reverse proxy, or run on a different port.
# Actually, we can run Flask on 7860 and forward requests to 3x-ui on a different port.
# But 3x-ui is listening on 7860. This is conflicting.
# Solution: Run 3x-ui on 8080, and Flask on 7860 and proxy.
# Or run Flask on 7860 and 3x-ui on another port. Let's do Flask on 7860 and proxy.
# But then we need to implement a proxy in Flask.
# It's more complex. The start.sh approach is simpler. |