updated to docker containers new name

This commit is contained in:
onysd 2026-07-27 23:35:20 +03:00
parent 0e5da4c8aa
commit d37ecf6071
9 changed files with 216 additions and 249 deletions

View file

@ -2,11 +2,7 @@
setlocal enabledelayedexpansion
cd /d "%~dp0"
set "ENV_EXAMPLE=.env.example"
set "ENV_FILE=.env"
set "IP_FILE=.public_ip"
set "PREFIX_FILE=.link_prefix"
set "SECRETS_FILE=.secrets"
set "COMPOSE_FILE=deploy\docker-compose.yml"
set "LOG_DIR=logs"
@ -20,127 +16,31 @@ goto parse_args
echo [cfg] script started, NO_BUILD=%NO_BUILD%
rem --- Public address (interactive) -----------------------------------------
set "DEFAULT_IP="
if exist "%IP_FILE%" (
set /p DEFAULT_IP=<"%IP_FILE%"
echo [cfg] loaded saved IP: !DEFAULT_IP!
)
if not defined DEFAULT_IP (
echo [cfg] detecting public IP...
for /f "usebackq delims=" %%i in (`powershell -NoProfile -Command "(Invoke-WebRequest -Uri 'https://api.ipify.org' -TimeoutSec 5 -UseBasicParsing).Content" 2^>nul`) do set "DEFAULT_IP=%%i"
if defined DEFAULT_IP echo [cfg] detected IP: !DEFAULT_IP!
)
if defined DEFAULT_IP (
set /p "PUBLIC_IP=Public server IP/host [!DEFAULT_IP!]: "
) else (
set /p "PUBLIC_IP=Public server IP/host: "
)
if not defined PUBLIC_IP set "PUBLIC_IP=!DEFAULT_IP!"
if not defined PUBLIC_IP (
echo [ERROR] public IP/host is required.
rem This script only starts the server -- it never writes or edits .env. Set
rem up .env yourself (from .env.example) before running it.
if not exist "%ENV_FILE%" (
echo [ERROR] %ENV_FILE% not found - copy .env.example to %ENV_FILE% and configure it first
pause
exit /b 1
)
> "%IP_FILE%" echo !PUBLIC_IP!
echo [cfg] public address = !PUBLIC_IP!
rem --- Link prefix / me_url_prefix (interactive) ----------------------------
set "DEFAULT_PREFIX=!PUBLIC_IP!"
if exist "%PREFIX_FILE%" set /p DEFAULT_PREFIX=<"%PREFIX_FILE%"
set /p "LINK_PREFIX=Link prefix [!DEFAULT_PREFIX!]: "
if not defined LINK_PREFIX set "LINK_PREFIX=!DEFAULT_PREFIX!"
for /f "usebackq delims=" %%i in (`powershell -NoProfile -Command "$p='!LINK_PREFIX!'; $p=$p -replace '^https?://','' -replace '/+$',''; Write-Output $p"`) do set "LINK_PREFIX=%%i"
if not defined LINK_PREFIX (
echo [ERROR] link prefix is required.
rem --- Docker container/volume naming (telesrv -> owpengram), one-time, opt-in
rem Resolves whether this install uses the new "owpengram" Docker naming or
rem (if telesrv_* volumes exist and the user declined migrating them) keeps
rem the old "telesrv" naming permanently. See deploy\migrate-docker-naming.ps1.
set "DOCKER_PROJECT="
set "DOCKER_PREFIX="
for /f "usebackq delims=" %%i in (`powershell -NoProfile -ExecutionPolicy Bypass -File deploy\migrate-docker-naming.ps1`) do (
if not defined DOCKER_PROJECT (set "DOCKER_PROJECT=%%i") else if not defined DOCKER_PREFIX (set "DOCKER_PREFIX=%%i")
)
if not defined DOCKER_PROJECT (
echo [ERROR] docker naming resolution failed
pause
exit /b 1
)
> "%PREFIX_FILE%" echo !LINK_PREFIX!
echo [cfg] link prefix = !LINK_PREFIX!
rem --- Secrets (generated once, cached) -------------------------------------
set "ADMIN_TOKEN="
set "ADMIN_PASSWORD="
set "SESSION_KEY="
set "SECRETS_CHANGED="
if exist "%SECRETS_FILE%" (
echo [cfg] loading secrets from %SECRETS_FILE%
for /f "usebackq tokens=1,* delims==" %%A in (`type "%SECRETS_FILE%"`) do (
if "%%A"=="ADMIN_TOKEN" set "ADMIN_TOKEN=%%B"
if "%%A"=="ADMIN_PASSWORD" set "ADMIN_PASSWORD=%%B"
if "%%A"=="SESSION_KEY" set "SESSION_KEY=%%B"
)
)
if not defined ADMIN_TOKEN (
echo [cfg] generating ADMIN_TOKEN...
for /f "usebackq delims=" %%i in (`powershell -NoProfile -Command "$bytes=New-Object byte[] 32; [System.Security.Cryptography.RandomNumberGenerator]::Fill($bytes); ($bytes | ForEach-Object { $_.ToString('x2') }) -join ''"`) do set "ADMIN_TOKEN=%%i"
set "SECRETS_CHANGED=1"
)
if not defined ADMIN_PASSWORD (
echo [cfg] generating ADMIN_PASSWORD...
for /f "usebackq delims=" %%i in (`powershell -NoProfile -Command "$chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; -join (1..24 | ForEach-Object { $chars[(Get-Random -Maximum $chars.Length)] })"`) do set "ADMIN_PASSWORD=%%i"
set "SECRETS_CHANGED=1"
)
if not defined SESSION_KEY (
echo [cfg] generating SESSION_KEY...
for /f "usebackq delims=" %%i in (`powershell -NoProfile -Command "$chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; -join (1..48 | ForEach-Object { $chars[(Get-Random -Maximum $chars.Length)] })"`) do set "SESSION_KEY=%%i"
set "SECRETS_CHANGED=1"
)
if defined SECRETS_CHANGED (
> "%SECRETS_FILE%" echo ADMIN_TOKEN=!ADMIN_TOKEN!
>> "%SECRETS_FILE%" echo ADMIN_PASSWORD=!ADMIN_PASSWORD!
>> "%SECRETS_FILE%" echo SESSION_KEY=!SESSION_KEY!
echo [cfg] secrets written to %SECRETS_FILE%
) else (
echo [cfg] secrets loaded from %SECRETS_FILE%
)
rem --- Generate .env from .env.example --------------------------------------
if not exist "%ENV_EXAMPLE%" (
echo [ERROR] template file %ENV_EXAMPLE% not found
pause
exit /b 1
)
copy /Y "%ENV_EXAMPLE%" "%ENV_FILE%" >nul
echo [cfg] copied %ENV_EXAMPLE% to %ENV_FILE%
echo [cfg] patching .env values...
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"$f='%ENV_FILE%'; " ^
"$enc=New-Object System.Text.UTF8Encoding($false); " ^
"$t=[System.IO.File]::ReadAllText($f,$enc); " ^
"$map=[ordered]@{ " ^
" 'TELESRV_ADVERTISE_IP'='!PUBLIC_IP!'; " ^
" 'TELESRV_TURN_ADVERTISE_IP'='!PUBLIC_IP!'; " ^
" 'TELESRV_SFU_ADVERTISE_IP'='!PUBLIC_IP!'; " ^
" 'TELESRV_PUBLIC_BASE_URL'='https://!LINK_PREFIX!'; " ^
" 'TELESRV_PASSKEY_RP_ID'='!LINK_PREFIX!'; " ^
" 'TELESRV_PUBLIC_APP_SCHEME'='owpg'; " ^
" 'TELESRV_PUBLIC_APP_NAME'='OwpenGram'; " ^
" 'TELESRV_ADMIN_API_TOKEN'='!ADMIN_TOKEN!'; " ^
" 'TELESRV_ADMIN_UI_PASSWORD'='!ADMIN_PASSWORD!'; " ^
" 'TELESRV_ADMIN_SESSION_KEY'='!SESSION_KEY!'; " ^
" 'TELESRV_ADMIN_UI_ADDR'='127.0.0.1:2600'; " ^
" 'TELESRV_ADMIN_API_ADDR'='127.0.0.1:2399'; " ^
" 'TELESRV_PUBLIC_LINK_WEB_ADDR'='127.0.0.1:2401' " ^
"}; " ^
"foreach ($k in $map.Keys) { " ^
" $pat='(?m)^' + [regex]::Escape($k) + '=.*$'; " ^
" $rep=$k + '=' + $map[$k]; " ^
" if ($t -match $pat) { $t=[regex]::Replace($t,$pat,$rep) } " ^
" else { $t+=\"`r`n\"+$rep } " ^
"}; " ^
"[System.IO.File]::WriteAllText($f,$t,$enc); " ^
"Write-Output 'ok'"
if %ERRORLEVEL% neq 0 (
echo [ERROR] failed to patch .env
pause
exit /b 1
)
echo [cfg] .env written
set "TELESRV_DOCKER_PROJECT=%DOCKER_PROJECT%"
set "TELESRV_DOCKER_PREFIX=%DOCKER_PREFIX%"
echo [cfg] docker naming = %DOCKER_PREFIX% (project %DOCKER_PROJECT%)
rem --- Start infrastructure (PostgreSQL + Redis) ----------------------------
echo.
@ -157,7 +57,7 @@ echo.
echo == [2/4] Waiting for PostgreSQL ==
set /a "_pgw=0"
:wait_pg
docker exec telesrv-postgres pg_isready -U telesrv -d telesrv >nul 2>&1
docker exec %DOCKER_PREFIX%-postgres pg_isready -U telesrv -d telesrv >nul 2>&1
if not errorlevel 1 goto pg_ready
set /a "_pgw+=1"
if !_pgw! gtr 30 (
@ -175,7 +75,7 @@ rem --- Build ------------------------------------------------------------------
echo.
echo == [3/4] Building server binaries ==
if /i "%NO_BUILD%"=="true" (
echo [cfg] skipping build (--no-build)
echo [cfg] skipping build, --no-build set
if not exist "bin\telesrv.exe" (
if not exist "bin\telesrv-admin.exe" (
echo [ERROR] no binaries found in bin\ - run without --no-build first
@ -210,23 +110,38 @@ if not exist "%LOG_DIR%" mkdir "%LOG_DIR%"
set "TELESRV_LOG=%LOG_DIR%\telesrv.log"
set "ADMIN_LOG=%LOG_DIR%\telesrv-admin.log"
start "telesrv" /B cmd /c "bin\telesrv.exe >> "%TELESRV_LOG%" 2>&1"
echo [ok] telesrv started, logs -^> %TELESRV_LOG%
rem "start /B cmd /c ..." creates no window, so the earlier WINDOWTITLE-based
rem taskkill in stop_server below never matched anything and silently killed
rem nothing. Launch via Start-Process -PassThru instead and track the real
rem PID. Still routed through cmd.exe /c so ">>log 2>&1" can merge stdout and
rem stderr into one file the way the bash script does (telesrv's own zap
rem logger writes to stderr, so splitting the streams would leave the "main"
rem log file nearly empty); "taskkill /T" below kills the whole cmd+exe tree,
rem not just the cmd.exe wrapper, so this still actually stops the process.
set "TELESRV_PID="
for /f "usebackq delims=" %%i in (`powershell -NoProfile -Command "(Start-Process -FilePath 'cmd.exe' -ArgumentList '/c bin\telesrv.exe >> \"%TELESRV_LOG%\" 2>&1' -WindowStyle Hidden -PassThru).Id"`) do set "TELESRV_PID=%%i"
if not defined TELESRV_PID (
echo [ERROR] failed to start telesrv
pause
exit /b 1
)
echo [ok] telesrv started (PID %TELESRV_PID%), logs -^> %TELESRV_LOG%
start "telesrv-admin" /B cmd /c "bin\telesrv-admin.exe >> "%ADMIN_LOG%" 2>&1"
echo [ok] telesrv-admin started, logs -^> %ADMIN_LOG%
set "ADMIN_PID="
for /f "usebackq delims=" %%i in (`powershell -NoProfile -Command "(Start-Process -FilePath 'cmd.exe' -ArgumentList '/c bin\telesrv-admin.exe >> \"%ADMIN_LOG%\" 2>&1' -WindowStyle Hidden -PassThru).Id"`) do set "ADMIN_PID=%%i"
if not defined ADMIN_PID (
echo [ERROR] failed to start telesrv-admin
taskkill /PID %TELESRV_PID% /T /F >nul 2>&1
pause
exit /b 1
)
echo [ok] telesrv-admin started (PID %ADMIN_PID%), logs -^> %ADMIN_LOG%
echo.
echo ============================================
echo OwpenGram server is running
echo ============================================
echo.
echo MTProto: !PUBLIC_IP!:2398
echo Admin UI: http://127.0.0.1:2600
echo Admin API: http://127.0.0.1:2399
echo.
echo Admin login password: !ADMIN_PASSWORD!
echo.
echo Logs:
echo telesrv: type %TELESRV_LOG%
echo telesrv-admin: type %ADMIN_LOG%
@ -235,6 +150,23 @@ echo ============================================
rem --- Interactive menu ------------------------------------------------------
:menu
tasklist /FI "PID eq %TELESRV_PID%" 2>nul | find "%TELESRV_PID%" >nul
if errorlevel 1 (
echo [WARN] telesrv PID %TELESRV_PID% exited unexpectedly
echo Check %TELESRV_LOG% for details
taskkill /PID %ADMIN_PID% /T /F >nul 2>&1
pause
exit /b 1
)
tasklist /FI "PID eq %ADMIN_PID%" 2>nul | find "%ADMIN_PID%" >nul
if errorlevel 1 (
echo [WARN] telesrv-admin PID %ADMIN_PID% exited unexpectedly
echo Check %ADMIN_LOG% for details
taskkill /PID %TELESRV_PID% /T /F >nul 2>&1
pause
exit /b 1
)
echo.
echo [1] View telesrv logs (last 50 lines)
echo [2] View telesrv-admin logs (last 50 lines)
@ -277,7 +209,7 @@ goto menu
:stop_server
echo.
echo [stop] stopping telesrv and telesrv-admin ...
taskkill /FI "WINDOWTITLE eq telesrv*" /F >nul 2>&1
taskkill /FI "WINDOWTITLE eq telesrv-admin*" /F >nul 2>&1
if defined TELESRV_PID taskkill /PID %TELESRV_PID% /T /F >nul 2>&1
if defined ADMIN_PID taskkill /PID %ADMIN_PID% /T /F >nul 2>&1
echo [ok] stopped.
exit /b 0