Start GetEndpoints and populate db
This commit is contained in:
parent
a5babe6b15
commit
e8aae5647c
|
@ -0,0 +1,3 @@
|
|||
[submodule "getendpoints"]
|
||||
path = getendpoints
|
||||
url = https://git.slc.ar/slococo-uni/getendpoints.git
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 7b778cbe9fd731bcb84edaa16e8c33bc93bab9fe
|
|
@ -67,11 +67,19 @@ def generate_mediamtx_files(env_vars, num_servers):
|
|||
print(f"Removed extra file: {file}")
|
||||
|
||||
|
||||
def generate_start_bat(num_servers):
|
||||
def generate_start_bat(env_vars, num_servers, getendpoints_env_vars):
|
||||
with open("templates/start.bat", "r") as template_file:
|
||||
bat_template = template_file.read()
|
||||
|
||||
ip = env_vars.get("IP")
|
||||
getendpoints_hostname = (
|
||||
getendpoints_env_vars.get("SERVICE_IP")
|
||||
+ ":"
|
||||
+ getendpoints_env_vars.get("SERVICE_PORT")
|
||||
)
|
||||
|
||||
obs_instances = ""
|
||||
post_requests = ""
|
||||
for i in range(1, num_servers + 1):
|
||||
obs_instance = f"""
|
||||
echo Launching OBS instance {i}
|
||||
|
@ -80,7 +88,19 @@ timeout /t 1 >nul
|
|||
""" # noqa: E501
|
||||
obs_instances += obs_instance
|
||||
|
||||
port = env_vars.get(f"PORT_{i}")
|
||||
post_request = f"""
|
||||
echo Registering WebRTC endpoint {i}
|
||||
powershell -Command "Invoke-WebRequest -Uri http://{getendpoints_hostname}/api/endpoints/{i} -Method PUT -Headers @{{'Content-Type'='application/json'}} -Body '{{\\"url\\": \\"http://{ip}:{port}/mystream/\\"}}'"
|
||||
timeout /t 1 >nul
|
||||
""" # noqa: E501
|
||||
post_requests += post_request
|
||||
|
||||
bat_content = bat_template.replace("{{OBS_INSTANCES}}", obs_instances)
|
||||
bat_content = bat_content.replace(
|
||||
"{{GETENDPOINTS_HOSTNAME}}", getendpoints_hostname
|
||||
)
|
||||
bat_content = bat_content.replace("{{POST_REQUESTS}}", post_requests)
|
||||
|
||||
with open("start.bat", "w") as f:
|
||||
f.write(bat_content)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import os
|
||||
|
||||
from dotenv import dotenv_values
|
||||
|
||||
from config import (
|
||||
|
@ -15,7 +17,16 @@ def main():
|
|||
|
||||
generate_docker_compose(env_vars, num_servers)
|
||||
generate_mediamtx_files(env_vars, num_servers)
|
||||
generate_start_bat(num_servers)
|
||||
|
||||
if not os.path.exists("./getendpoints/src/.env"):
|
||||
print(
|
||||
"File not found: /getendpoints/src/.env. Read the README.md file for more information."
|
||||
)
|
||||
raise SystemExit
|
||||
|
||||
getendpoints_env_vars = dotenv_values("./getendpoints/src/.env")
|
||||
|
||||
generate_start_bat(env_vars, num_servers, getendpoints_env_vars)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -21,11 +21,48 @@ if errorlevel 1 (
|
|||
)
|
||||
|
||||
echo Starting docker compose
|
||||
cd ".\mediamtx"
|
||||
docker compose up -d
|
||||
|
||||
timeout /t 3 >nul
|
||||
|
||||
{{OBS_INSTANCES}}
|
||||
|
||||
powershell -Command ^
|
||||
"try { ^
|
||||
$response = Invoke-WebRequest -Uri http://{{GETENDPOINTS_HOSTNAME}}/api/health; ^
|
||||
if ($response.StatusCode -eq 200) { ^
|
||||
exit 0 ^
|
||||
} else { ^
|
||||
exit 1 ^
|
||||
} ^
|
||||
} catch { ^
|
||||
exit 1 ^
|
||||
}"
|
||||
|
||||
if errorlevel 1 (
|
||||
echo Starting GetEndpoints
|
||||
cd ".\getendpoints"
|
||||
start cmd /k run.bat
|
||||
)
|
||||
|
||||
:waitForGetEndpoints
|
||||
powershell -Command ^
|
||||
"try { ^
|
||||
$response = Invoke-WebRequest -Uri http://{{GETENDPOINTS_HOSTNAME}}/api/health; ^
|
||||
if ($response.StatusCode -eq 200) { ^
|
||||
exit 0 ^
|
||||
} else { ^
|
||||
exit 1 ^
|
||||
} ^
|
||||
} catch { ^
|
||||
exit 1 ^
|
||||
}"
|
||||
|
||||
if errorlevel 1 (
|
||||
timeout /t 1 >nul
|
||||
goto waitForGetEndpoints
|
||||
)
|
||||
|
||||
{{POST_REQUESTS}}
|
||||
|
||||
pause
|
||||
|
|
Loading…
Reference in New Issue