Spaces:
Running
Running
File size: 1,759 Bytes
0104030 3b6db31 0104030 9db385b |
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
import os
import subprocess
from multiprocessing import Process
import uvicorn
from fastapi import FastAPI
import logging
import threading
import signal
import time
app = FastAPI()
# Configure logger
logging.basicConfig(level=logging.INFO)
# No Rtmp or Ffmpeg related variables
def start_playit_server():
try:
logging.info("Starting playit-linux-amd64")
subprocess.run("./playit-linux-amd64", shell=True, check=True)
except subprocess.CalledProcessError as e:
logging.error(f"Error running playit-linux-amd64: {e}")
def start_impostor_server():
try:
logging.info("Starting Impostor.Server")
subprocess.run("./hlds_run", shell=True, check=True)
except subprocess.CalledProcessError as e:
logging.error(f"Error running Impostor.Server: {e}")
def monitor_playit_process():
while True:
if not playit_process.is_alive():
logging.info("Playit process stopped. Restarting...")
start_playit_process()
time.sleep(1) # Check every second
def start_playit_process():
global playit_process
playit_process = Process(target=start_playit_server)
playit_process.start()
@app.get("/")
async def read_root():
return {"message": "Hello World"}
if __name__ == "__main__":
# Start playit process in a separate process
start_playit_process()
# Start Impostor.Server in a separate process
global impostor_server_process
impostor_server_process = Process(target=start_impostor_server)
impostor_server_process.start()
# Start the monitor thread
monitor_thread = threading.Thread(target=monitor_playit_process)
monitor_thread.start()
# Start the FastAPI server
uvicorn.run(app, host="0.0.0.0", port=7860) |