fixed migration for old instances
This commit is contained in:
parent
d37ecf6071
commit
a69aa0a975
10 changed files with 463 additions and 86 deletions
|
|
@ -145,7 +145,7 @@ TELESRV_ADMIN_API_ADDR=
|
|||
# Admin UI 监听地址,默认值通常无需修改;RTMP ingest 保留 2400。
|
||||
TELESRV_ADMIN_UI_ADDR=127.0.0.1:2600
|
||||
|
||||
TELESRV_POSTGRES_DSN=postgres://telesrv:telesrv@127.0.0.1:5432/telesrv?sslmode=disable
|
||||
TELESRV_POSTGRES_DSN=postgres://owpengram:owpengram@127.0.0.1:5432/owpengram?sslmode=disable
|
||||
TELESRV_REDIS_ADDR=127.0.0.1:6399
|
||||
TELESRV_REDIS_PASSWORD=
|
||||
TELESRV_REDIS_DB=0
|
||||
|
|
|
|||
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -31,6 +31,8 @@ tmp/
|
|||
.public_ip
|
||||
.link_prefix
|
||||
.secrets
|
||||
.docker_naming
|
||||
.db_naming
|
||||
|
||||
# IDE
|
||||
.idea/
|
||||
|
|
|
|||
|
|
@ -31,16 +31,21 @@ services:
|
|||
- "-c"
|
||||
- "track_io_timing=on"
|
||||
environment:
|
||||
POSTGRES_DB: telesrv
|
||||
POSTGRES_USER: telesrv
|
||||
POSTGRES_PASSWORD: telesrv
|
||||
# Only take effect when Postgres bootstraps a brand-new, empty data
|
||||
# volume; a pre-existing volume ignores these and keeps whatever
|
||||
# role/database name it was originally initialized with. See
|
||||
# deploy/migrate-db-naming.ps1 for renaming an existing telesrv-named
|
||||
# role/database in-place.
|
||||
POSTGRES_DB: owpengram
|
||||
POSTGRES_USER: owpengram
|
||||
POSTGRES_PASSWORD: owpengram
|
||||
TZ: UTC
|
||||
ports:
|
||||
- "5432:5432"
|
||||
volumes:
|
||||
- pgdata:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U telesrv -d telesrv"]
|
||||
test: ["CMD-SHELL", "pg_isready -U owpengram -d owpengram"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
|
|
|
|||
126
deploy/migrate-db-naming.ps1
Normal file
126
deploy/migrate-db-naming.ps1
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
<#
|
||||
One-time, opt-in migration of the Postgres role/database name inside an
|
||||
existing data volume from "telesrv" to "owpengram".
|
||||
|
||||
docker-compose.yml's POSTGRES_USER/POSTGRES_DB env vars only take effect when
|
||||
Postgres bootstraps a brand-new, empty data volume -- they're silently
|
||||
ignored against a pre-existing volume, so changing the compose file alone
|
||||
does nothing for an install that already has data on disk. This script talks
|
||||
to the already-running Postgres container directly (run it after "docker
|
||||
compose up" plus a readiness wait, not before) and renames the role/database
|
||||
in place via ALTER ROLE / ALTER DATABASE.
|
||||
|
||||
The existing password is left untouched -- renaming doesn't change it. Only
|
||||
the TELESRV_POSTGRES_DSN line in .env is patched (never any other line, and
|
||||
never if that line was already customized away from the plain telesrv
|
||||
defaults) so the app can still connect afterwards.
|
||||
|
||||
Prints nothing when there's nothing to do. Prompts interactively at most
|
||||
once; the decision is cached in a state file next to .secrets/.public_ip, so
|
||||
this is never asked again. Declining is permanent: the install keeps the
|
||||
"telesrv" role/database name forever.
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$ContainerName = "owpengram-postgres",
|
||||
[string]$EnvFile = ".env",
|
||||
[string]$StateFile = ".db_naming"
|
||||
)
|
||||
|
||||
function Write-Info([string]$Message) {
|
||||
[Console]::Error.WriteLine($Message)
|
||||
}
|
||||
|
||||
function Test-PgRoleExists([string]$Role) {
|
||||
$out = docker exec $ContainerName psql -U telesrv -d postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname='$Role'" 2>$null
|
||||
return ($LASTEXITCODE -eq 0) -and ($out -match '1')
|
||||
}
|
||||
|
||||
$state = $null
|
||||
if (Test-Path $StateFile) {
|
||||
$state = (Get-Content $StateFile -Raw -ErrorAction SilentlyContinue)
|
||||
if ($state) { $state = $state.Trim() }
|
||||
}
|
||||
if ($state -eq "owpengram" -or $state -eq "telesrv") {
|
||||
exit 0
|
||||
}
|
||||
|
||||
$oldExists = Test-PgRoleExists "telesrv"
|
||||
$newExists = Test-PgRoleExists "owpengram"
|
||||
|
||||
if (-not $oldExists -or $newExists) {
|
||||
# Nothing to migrate: either already "owpengram"-named (fresh install or
|
||||
# already renamed), or connecting as "telesrv" didn't work at all (custom
|
||||
# credentials already in place) -- leave it alone either way.
|
||||
Set-Content -Path $StateFile -Value "owpengram" -NoNewline
|
||||
exit 0
|
||||
}
|
||||
|
||||
if ([Console]::IsInputRedirected) {
|
||||
Write-Info "[cfg] Postgres role/database still named 'telesrv' but running non-interactively; keeping old naming for now"
|
||||
exit 0
|
||||
}
|
||||
|
||||
Write-Info ""
|
||||
Write-Info "== Postgres role/database naming =="
|
||||
Write-Info "The Postgres role and database inside this install's data volume are still"
|
||||
Write-Info "named 'telesrv' (renaming docker-compose.yml alone doesn't affect existing"
|
||||
Write-Info "data). Renaming them to 'owpengram' keeps everything consistent. Recommended."
|
||||
$reply = Read-Host "Rename Postgres role/database from 'telesrv' to 'owpengram' now? [Y/n]"
|
||||
|
||||
if ($reply -match '^[Nn]') {
|
||||
Set-Content -Path $StateFile -Value "telesrv" -NoNewline
|
||||
Write-Info "[cfg] keeping 'telesrv' Postgres role/database naming (won't ask again)"
|
||||
exit 0
|
||||
}
|
||||
|
||||
Write-Info "[cfg] renaming Postgres role/database: telesrv -> owpengram"
|
||||
|
||||
# Postgres refuses "ALTER ROLE <session user> RENAME" (session user cannot be
|
||||
# renamed), so telesrv can't rename itself. Do the database rename directly
|
||||
# as telesrv, then use a short-lived second superuser to rename the telesrv
|
||||
# role, then drop that temporary role from the now-renamed "owpengram" role's
|
||||
# own session. Each step is a separate connection/transaction on purpose:
|
||||
# combining the ALTER DATABASE and ALTER ROLE in one multi-statement call
|
||||
# rolls the database rename back too when the role rename fails (Postgres
|
||||
# treats a semicolon-separated -c string as one implicit transaction).
|
||||
docker exec $ContainerName psql -U telesrv -d postgres -c "ALTER DATABASE telesrv RENAME TO owpengram; CREATE ROLE _telesrv_migrate SUPERUSER LOGIN PASSWORD 'telesrv_migrate';" *> $null
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Info "[ERROR] failed to rename Postgres database / create temporary migration role"
|
||||
exit 1
|
||||
}
|
||||
docker exec $ContainerName psql -U _telesrv_migrate -d owpengram -c "ALTER ROLE telesrv RENAME TO owpengram;" *> $null
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Info "[ERROR] failed to rename Postgres role"
|
||||
exit 1
|
||||
}
|
||||
docker exec $ContainerName psql -U owpengram -d owpengram -c "DROP ROLE _telesrv_migrate;" *> $null
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Info "[WARN] renamed role/database but failed to drop the temporary _telesrv_migrate role - remove it by hand"
|
||||
}
|
||||
|
||||
Set-Content -Path $StateFile -Value "owpengram" -NoNewline
|
||||
Write-Info "[ok] Postgres role/database renamed to 'owpengram'"
|
||||
|
||||
if (Test-Path $EnvFile) {
|
||||
$lines = Get-Content $EnvFile
|
||||
$pattern = '^TELESRV_POSTGRES_DSN=postgres://telesrv:([^@]*)@([^/]+)/telesrv(\?.*)?$'
|
||||
$patched = $false
|
||||
$newLines = foreach ($line in $lines) {
|
||||
if (-not $patched -and $line -match $pattern) {
|
||||
$patched = $true
|
||||
"TELESRV_POSTGRES_DSN=postgres://owpengram:$($Matches[1])@$($Matches[2])/owpengram$($Matches[3])"
|
||||
} else {
|
||||
$line
|
||||
}
|
||||
}
|
||||
if ($patched) {
|
||||
Set-Content -Path $EnvFile -Value $newLines
|
||||
Write-Info "[ok] updated the TELESRV_POSTGRES_DSN line in $EnvFile (only that one line)"
|
||||
} else {
|
||||
Write-Info "[WARN] TELESRV_POSTGRES_DSN in $EnvFile doesn't match the plain telesrv defaults - update it by hand:"
|
||||
Write-Info " TELESRV_POSTGRES_DSN=postgres://owpengram:<your-password>@<host>:<port>/owpengram?sslmode=disable"
|
||||
}
|
||||
} else {
|
||||
Write-Info "[WARN] $EnvFile not found - if you create one, point TELESRV_POSTGRES_DSN at the 'owpengram' role/database"
|
||||
}
|
||||
117
deploy/migrate-db-naming.sh
Normal file
117
deploy/migrate-db-naming.sh
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
#!/usr/bin/env bash
|
||||
# Bash equivalent of migrate-db-naming.ps1 for start-server.sh (Linux/macOS
|
||||
# hosts, no PowerShell dependency). Keep both in sync; start-server.bat uses
|
||||
# the .ps1 version instead.
|
||||
#
|
||||
# One-time, opt-in migration of the Postgres role/database name inside an
|
||||
# existing data volume from "telesrv" to "owpengram".
|
||||
#
|
||||
# docker-compose.yml's POSTGRES_USER/POSTGRES_DB env vars only take effect
|
||||
# when Postgres bootstraps a brand-new, empty data volume -- they're silently
|
||||
# ignored against a pre-existing volume, so changing the compose file alone
|
||||
# does nothing for an install that already has data on disk. This script
|
||||
# talks to the already-running Postgres container directly (run it after
|
||||
# "docker compose up" plus a readiness wait, not before) and renames the
|
||||
# role/database in place via ALTER ROLE / ALTER DATABASE.
|
||||
#
|
||||
# The existing password is left untouched -- renaming doesn't change it. Only
|
||||
# the TELESRV_POSTGRES_DSN line in .env is patched (never any other line, and
|
||||
# never if that line was already customized away from the plain telesrv
|
||||
# defaults) so the app can still connect afterwards.
|
||||
#
|
||||
# Prints nothing when there's nothing to do. Prompts interactively at most
|
||||
# once; the decision is cached in a state file next to .secrets/.public_ip, so
|
||||
# this is never asked again. Declining is permanent: the install keeps the
|
||||
# "telesrv" role/database name forever.
|
||||
set -euo pipefail
|
||||
|
||||
CONTAINER_NAME="${1:-owpengram-postgres}"
|
||||
ENV_FILE="${2:-.env}"
|
||||
STATE_FILE="${3:-.db_naming}"
|
||||
|
||||
info() { echo "$@" >&2; }
|
||||
|
||||
pg_role_exists() {
|
||||
local role="$1"
|
||||
local out
|
||||
out="$(docker exec "$CONTAINER_NAME" psql -U telesrv -d postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname='${role}'" 2>/dev/null || true)"
|
||||
[[ "$out" == *1* ]]
|
||||
}
|
||||
|
||||
state=""
|
||||
[[ -f "$STATE_FILE" ]] && state="$(tr -d '[:space:]' < "$STATE_FILE")"
|
||||
if [[ "$state" == "owpengram" || "$state" == "telesrv" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
old_exists=false
|
||||
new_exists=false
|
||||
pg_role_exists "telesrv" && old_exists=true
|
||||
pg_role_exists "owpengram" && new_exists=true
|
||||
|
||||
if [[ "$old_exists" == false || "$new_exists" == true ]]; then
|
||||
# Nothing to migrate: either already "owpengram"-named (fresh install or
|
||||
# already renamed), or connecting as "telesrv" didn't work at all (custom
|
||||
# credentials already in place) -- leave it alone either way.
|
||||
echo -n "owpengram" > "$STATE_FILE"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ ! -t 0 ]]; then
|
||||
info "[cfg] Postgres role/database still named 'telesrv' but running non-interactively; keeping old naming for now"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
info ""
|
||||
info "== Postgres role/database naming =="
|
||||
info "The Postgres role and database inside this install's data volume are still"
|
||||
info "named 'telesrv' (renaming docker-compose.yml alone doesn't affect existing"
|
||||
info "data). Renaming them to 'owpengram' keeps everything consistent. Recommended."
|
||||
read -rp "Rename Postgres role/database from 'telesrv' to 'owpengram' now? [Y/n] " reply
|
||||
|
||||
if [[ "$reply" =~ ^[Nn] ]]; then
|
||||
echo -n "telesrv" > "$STATE_FILE"
|
||||
info "[cfg] keeping 'telesrv' Postgres role/database naming (won't ask again)"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
info "[cfg] renaming Postgres role/database: telesrv -> owpengram"
|
||||
|
||||
# Postgres refuses "ALTER ROLE <session user> RENAME" (session user cannot be
|
||||
# renamed), so telesrv can't rename itself. Do the database rename directly
|
||||
# as telesrv, then use a short-lived second superuser to rename the telesrv
|
||||
# role, then drop that temporary role from the now-renamed "owpengram" role's
|
||||
# own session. Each step is a separate connection/transaction on purpose:
|
||||
# combining the ALTER DATABASE and ALTER ROLE in one multi-statement call
|
||||
# rolls the database rename back too when the role rename fails (Postgres
|
||||
# treats a semicolon-separated -c string as one implicit transaction).
|
||||
if ! docker exec "$CONTAINER_NAME" psql -U telesrv -d postgres -c \
|
||||
"ALTER DATABASE telesrv RENAME TO owpengram; CREATE ROLE _telesrv_migrate SUPERUSER LOGIN PASSWORD 'telesrv_migrate';" \
|
||||
>/dev/null 2>&1; then
|
||||
info "[ERROR] failed to rename Postgres database / create temporary migration role"
|
||||
exit 1
|
||||
fi
|
||||
if ! docker exec "$CONTAINER_NAME" psql -U _telesrv_migrate -d owpengram -c \
|
||||
"ALTER ROLE telesrv RENAME TO owpengram;" >/dev/null 2>&1; then
|
||||
info "[ERROR] failed to rename Postgres role"
|
||||
exit 1
|
||||
fi
|
||||
if ! docker exec "$CONTAINER_NAME" psql -U owpengram -d owpengram -c \
|
||||
"DROP ROLE _telesrv_migrate;" >/dev/null 2>&1; then
|
||||
info "[WARN] renamed role/database but failed to drop the temporary _telesrv_migrate role - remove it by hand"
|
||||
fi
|
||||
|
||||
echo -n "owpengram" > "$STATE_FILE"
|
||||
info "[ok] Postgres role/database renamed to 'owpengram'"
|
||||
|
||||
if [[ -f "$ENV_FILE" ]]; then
|
||||
if grep -qE '^TELESRV_POSTGRES_DSN=postgres://telesrv:[^@]*@[^/]+/telesrv(\?.*)?$' "$ENV_FILE"; then
|
||||
sed -i -E 's#^TELESRV_POSTGRES_DSN=postgres://telesrv:([^@]*)@([^/]+)/telesrv(\?.*)?$#TELESRV_POSTGRES_DSN=postgres://owpengram:\1@\2/owpengram\3#' "$ENV_FILE"
|
||||
info "[ok] updated the TELESRV_POSTGRES_DSN line in ${ENV_FILE} (only that one line)"
|
||||
else
|
||||
info "[WARN] TELESRV_POSTGRES_DSN in ${ENV_FILE} doesn't match the plain telesrv defaults - update it by hand:"
|
||||
info " TELESRV_POSTGRES_DSN=postgres://owpengram:<your-password>@<host>:<port>/owpengram?sslmode=disable"
|
||||
fi
|
||||
else
|
||||
info "[WARN] ${ENV_FILE} not found - if you create one, point TELESRV_POSTGRES_DSN at the 'owpengram' role/database"
|
||||
fi
|
||||
105
deploy/migrate-docker-naming.sh
Normal file
105
deploy/migrate-docker-naming.sh
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
#!/usr/bin/env bash
|
||||
# Bash equivalent of migrate-docker-naming.ps1 for start-server.sh (Linux/macOS
|
||||
# hosts, no PowerShell dependency). Keep both in sync; start-server.bat uses
|
||||
# the .ps1 version instead.
|
||||
#
|
||||
# Resolves (and, once, offers to migrate) the Docker project/container/volume
|
||||
# naming used by deploy/docker-compose.yml.
|
||||
#
|
||||
# The project used to be named "telesrv" in Docker (containers telesrv-postgres
|
||||
# / telesrv-redis, volumes telesrv_pgdata / telesrv_redisdata). It's now
|
||||
# "owpengram" by default, so a gramsrv instance running on the same machine
|
||||
# can't be confused with this one at a glance in `docker ps` / Docker Desktop.
|
||||
#
|
||||
# Existing installs may still have telesrv_* volumes with real data in them.
|
||||
# This script asks, at most once, whether to copy that data over to owpengram_*
|
||||
# naming. The answer is cached in a state file next to .secrets/.public_ip:
|
||||
# - accepted -> volumes are copied (old telesrv_* volumes are left in place,
|
||||
# untouched, as a backup), state becomes "owpengram", never asked again.
|
||||
# - declined -> state becomes "telesrv", the install keeps the old naming
|
||||
# forever, never asked again.
|
||||
# - fresh install (no telesrv_* volumes found) -> silently uses "owpengram",
|
||||
# nothing to migrate.
|
||||
#
|
||||
# Prints exactly two lines to stdout: the resolved project name, then the
|
||||
# resolved container/volume prefix. Everything else (prompts, progress) goes
|
||||
# to stderr, so a caller can safely capture just stdout.
|
||||
set -euo pipefail
|
||||
|
||||
COMPOSE_FILE="${1:-deploy/docker-compose.yml}"
|
||||
STATE_FILE="${2:-.docker_naming}"
|
||||
|
||||
info() { echo "$@" >&2; }
|
||||
result() { printf '%s\n%s\n' "$1" "$2"; }
|
||||
|
||||
volume_exists() { docker volume inspect "$1" >/dev/null 2>&1; }
|
||||
|
||||
state=""
|
||||
[[ -f "$STATE_FILE" ]] && state="$(tr -d '[:space:]' < "$STATE_FILE")"
|
||||
|
||||
if [[ "$state" == "owpengram" ]]; then
|
||||
result "owpengram" "owpengram"
|
||||
exit 0
|
||||
fi
|
||||
if [[ "$state" == "telesrv" ]]; then
|
||||
result "telesrv" "telesrv"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
old_pg=false
|
||||
old_redis=false
|
||||
volume_exists "telesrv_pgdata" && old_pg=true
|
||||
volume_exists "telesrv_redisdata" && old_redis=true
|
||||
|
||||
if [[ "$old_pg" == false && "$old_redis" == false ]]; then
|
||||
echo -n "owpengram" > "$STATE_FILE"
|
||||
result "owpengram" "owpengram"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ ! -t 0 ]]; then
|
||||
info "[cfg] old 'telesrv_*' Docker volumes found but running non-interactively; keeping old naming for now"
|
||||
result "telesrv" "telesrv"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
info ""
|
||||
info "== Docker container/volume naming =="
|
||||
info "Found existing Docker volumes named 'telesrv_*' (from before the project was"
|
||||
info "renamed to OwpenGram). Renaming them to 'owpengram_*' avoids confusing this"
|
||||
info "server with a gramsrv instance running on the same machine. Recommended."
|
||||
read -rp "Migrate Docker containers/volumes from 'telesrv' to 'owpengram' naming now? [Y/n] " reply
|
||||
|
||||
if [[ "$reply" =~ ^[Nn] ]]; then
|
||||
echo -n "telesrv" > "$STATE_FILE"
|
||||
info "[cfg] keeping 'telesrv' Docker naming (won't ask again)"
|
||||
result "telesrv" "telesrv"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
info "[cfg] migrating Docker volumes: telesrv_* -> owpengram_*"
|
||||
|
||||
TELESRV_DOCKER_PROJECT=telesrv TELESRV_DOCKER_PREFIX=telesrv \
|
||||
docker compose -f "$COMPOSE_FILE" -p telesrv stop postgres redis >/dev/null 2>&1 || true
|
||||
|
||||
if [[ "$old_pg" == true ]]; then
|
||||
docker volume create owpengram_pgdata >/dev/null
|
||||
if ! docker run --rm -v telesrv_pgdata:/from -v owpengram_pgdata:/to alpine sh -c "cp -a /from/. /to/"; then
|
||||
info "[ERROR] failed to copy pgdata volume"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
if [[ "$old_redis" == true ]]; then
|
||||
docker volume create owpengram_redisdata >/dev/null
|
||||
if ! docker run --rm -v telesrv_redisdata:/from -v owpengram_redisdata:/to alpine sh -c "cp -a /from/. /to/"; then
|
||||
info "[ERROR] failed to copy redisdata volume"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
TELESRV_DOCKER_PROJECT=telesrv TELESRV_DOCKER_PREFIX=telesrv \
|
||||
docker compose -f "$COMPOSE_FILE" -p telesrv down >/dev/null 2>&1 || true
|
||||
|
||||
echo -n "owpengram" > "$STATE_FILE"
|
||||
info "[ok] migration complete - old 'telesrv_*' volumes were left in place, untouched, as a backup"
|
||||
result "owpengram" "owpengram"
|
||||
|
|
@ -379,7 +379,7 @@ key rings independently on different instances.
|
|||
|
||||
| Setting | Type / code default | Description and constraints |
|
||||
|---|---|---|
|
||||
| `TELESRV_POSTGRES_DSN` | secret DSN / `postgres://telesrv:telesrv@127.0.0.1:5432/telesrv?sslmode=disable` | Primary durable business database. Production must replace the development credentials and TLS policy. |
|
||||
| `TELESRV_POSTGRES_DSN` | secret DSN / `postgres://owpengram:owpengram@127.0.0.1:5432/owpengram?sslmode=disable` | Primary durable business database. Production must replace the development credentials and TLS policy. |
|
||||
| `TELESRV_POSTGRES_MAX_CONNS` | int / `50` | pgxpool maximum connections. `<=0` delegates to pgx defaults, which are usually too small for production outbox/RPC concurrency. |
|
||||
| `TELESRV_POSTGRES_MIN_CONNS` | int / `16` | pgxpool pre-warmed minimum connections. |
|
||||
| `TELESRV_REDIS_ADDR` | address / `127.0.0.1:6399` | Redis used for volatile codes, limits, and shared update/cache state. |
|
||||
|
|
|
|||
|
|
@ -361,7 +361,7 @@ active key。不要手工编辑 manifest 或 PEM,不要在各实例上分别
|
|||
|
||||
| 参数 | 类型 / 代码默认值 | 说明与约束 |
|
||||
|---|---|---|
|
||||
| `TELESRV_POSTGRES_DSN` | secret DSN / `postgres://telesrv:telesrv@127.0.0.1:5432/telesrv?sslmode=disable` | 主业务持久库;生产必须替换开发凭证与 TLS 策略。 |
|
||||
| `TELESRV_POSTGRES_DSN` | secret DSN / `postgres://owpengram:owpengram@127.0.0.1:5432/owpengram?sslmode=disable` | 主业务持久库;生产必须替换开发凭证与 TLS 策略。 |
|
||||
| `TELESRV_POSTGRES_MAX_CONNS` | int / `50` | pgxpool 最大连接数;`<=0` 使用 pgx 默认值,该默认通常不足以覆盖生产 outbox/RPC 并发。 |
|
||||
| `TELESRV_POSTGRES_MIN_CONNS` | int / `16` | pgxpool 预热最小连接数。 |
|
||||
| `TELESRV_REDIS_ADDR` | address / `127.0.0.1:6399` | 验证码、限流、共享更新/缓存易失态使用的 Redis。 |
|
||||
|
|
|
|||
|
|
@ -71,13 +71,26 @@ goto wait_pg
|
|||
:pg_ready
|
||||
echo [ok] PostgreSQL is ready
|
||||
|
||||
rem --- Postgres role/database naming (telesrv -> owpengram), one-time, opt-in
|
||||
rem Only runs for installs that already accepted the Docker naming migration
|
||||
rem above; a "telesrv"-naming install already said no to this rename theme
|
||||
rem once and isn't asked again. See deploy\migrate-db-naming.ps1.
|
||||
if "%DOCKER_PREFIX%"=="owpengram" (
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -File deploy\migrate-db-naming.ps1 -ContainerName "%DOCKER_PREFIX%-postgres"
|
||||
if !ERRORLEVEL! neq 0 (
|
||||
echo [ERROR] postgres naming migration failed
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
)
|
||||
|
||||
rem --- Build ------------------------------------------------------------------
|
||||
echo.
|
||||
echo == [3/4] Building server binaries ==
|
||||
if /i "%NO_BUILD%"=="true" (
|
||||
echo [cfg] skipping build, --no-build set
|
||||
if not exist "bin\telesrv.exe" (
|
||||
if not exist "bin\telesrv-admin.exe" (
|
||||
if not exist "bin\owpengram-server.exe" (
|
||||
if not exist "bin\owpengram-admin-panel.exe" (
|
||||
echo [ERROR] no binaries found in bin\ - run without --no-build first
|
||||
pause
|
||||
exit /b 1
|
||||
|
|
@ -85,17 +98,17 @@ if /i "%NO_BUILD%"=="true" (
|
|||
)
|
||||
) else (
|
||||
if not exist bin mkdir bin
|
||||
echo [cfg] building telesrv...
|
||||
go build -o bin\telesrv.exe .\cmd\telesrv
|
||||
if %ERRORLEVEL% neq 0 (
|
||||
echo [ERROR] failed to build telesrv
|
||||
echo [cfg] building owpengram-server...
|
||||
go build -o bin\owpengram-server.exe .\cmd\telesrv
|
||||
if !ERRORLEVEL! neq 0 (
|
||||
echo [ERROR] failed to build owpengram-server
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
echo [cfg] building telesrv-admin...
|
||||
go build -o bin\telesrv-admin.exe .\cmd\telesrv-admin
|
||||
if %ERRORLEVEL% neq 0 (
|
||||
echo [ERROR] failed to build telesrv-admin
|
||||
echo [cfg] building owpengram-admin-panel...
|
||||
go build -o bin\owpengram-admin-panel.exe .\cmd\telesrv-admin
|
||||
if !ERRORLEVEL! neq 0 (
|
||||
echo [ERROR] failed to build owpengram-admin-panel
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
|
@ -104,38 +117,38 @@ if /i "%NO_BUILD%"=="true" (
|
|||
|
||||
rem --- Start servers ----------------------------------------------------------
|
||||
echo.
|
||||
echo == [4/4] Starting telesrv + telesrv-admin ==
|
||||
echo == [4/4] Starting owpengram-server + owpengram-admin-panel ==
|
||||
|
||||
if not exist "%LOG_DIR%" mkdir "%LOG_DIR%"
|
||||
set "TELESRV_LOG=%LOG_DIR%\telesrv.log"
|
||||
set "ADMIN_LOG=%LOG_DIR%\telesrv-admin.log"
|
||||
set "SERVER_LOG=%LOG_DIR%\owpengram-server.log"
|
||||
set "ADMIN_LOG=%LOG_DIR%\owpengram-admin-panel.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 stderr into one file the way the bash script does (the server'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
|
||||
set "SERVER_PID="
|
||||
for /f "usebackq delims=" %%i in (`powershell -NoProfile -Command "(Start-Process -FilePath 'cmd.exe' -ArgumentList '/c bin\owpengram-server.exe >> \"%SERVER_LOG%\" 2>&1' -WindowStyle Hidden -PassThru).Id"`) do set "SERVER_PID=%%i"
|
||||
if not defined SERVER_PID (
|
||||
echo [ERROR] failed to start owpengram-server
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
echo [ok] telesrv started (PID %TELESRV_PID%), logs -^> %TELESRV_LOG%
|
||||
echo [ok] owpengram-server started, PID %SERVER_PID%, logs -^> %SERVER_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"
|
||||
for /f "usebackq delims=" %%i in (`powershell -NoProfile -Command "(Start-Process -FilePath 'cmd.exe' -ArgumentList '/c bin\owpengram-admin-panel.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
|
||||
echo [ERROR] failed to start owpengram-admin-panel
|
||||
taskkill /PID %SERVER_PID% /T /F >nul 2>&1
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
echo [ok] telesrv-admin started (PID %ADMIN_PID%), logs -^> %ADMIN_LOG%
|
||||
echo [ok] owpengram-admin-panel started, PID %ADMIN_PID%, logs -^> %ADMIN_LOG%
|
||||
|
||||
echo.
|
||||
echo ============================================
|
||||
|
|
@ -143,42 +156,42 @@ echo OwpenGram server is running
|
|||
echo ============================================
|
||||
echo.
|
||||
echo Logs:
|
||||
echo telesrv: type %TELESRV_LOG%
|
||||
echo telesrv-admin: type %ADMIN_LOG%
|
||||
echo owpengram-server: type %SERVER_LOG%
|
||||
echo owpengram-admin-panel: type %ADMIN_LOG%
|
||||
echo.
|
||||
echo ============================================
|
||||
|
||||
rem --- Interactive menu ------------------------------------------------------
|
||||
:menu
|
||||
tasklist /FI "PID eq %TELESRV_PID%" 2>nul | find "%TELESRV_PID%" >nul
|
||||
tasklist /FI "PID eq %SERVER_PID%" 2>nul | find "%SERVER_PID%" >nul
|
||||
if errorlevel 1 (
|
||||
echo [WARN] telesrv PID %TELESRV_PID% exited unexpectedly
|
||||
echo Check %TELESRV_LOG% for details
|
||||
echo [WARN] owpengram-server PID %SERVER_PID% exited unexpectedly
|
||||
echo Check %SERVER_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 [WARN] owpengram-admin-panel PID %ADMIN_PID% exited unexpectedly
|
||||
echo Check %ADMIN_LOG% for details
|
||||
taskkill /PID %TELESRV_PID% /T /F >nul 2>&1
|
||||
taskkill /PID %SERVER_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)
|
||||
echo [1] View owpengram-server logs (last 50 lines)
|
||||
echo [2] View owpengram-admin-panel logs (last 50 lines)
|
||||
echo [3] View both logs (last 50 lines)
|
||||
echo [4] Follow telesrv logs (live)
|
||||
echo [5] Follow telesrv-admin logs (live)
|
||||
echo [4] Follow owpengram-server logs (live)
|
||||
echo [5] Follow owpengram-admin-panel logs (live)
|
||||
echo [q] Stop server and exit
|
||||
echo.
|
||||
set /p "choice= Choice: "
|
||||
|
||||
if "!choice!"=="1" (
|
||||
powershell -NoProfile -Command "Get-Content '%TELESRV_LOG%' -Tail 50 -ErrorAction SilentlyContinue"
|
||||
powershell -NoProfile -Command "Get-Content '%SERVER_LOG%' -Tail 50 -ErrorAction SilentlyContinue"
|
||||
goto menu
|
||||
)
|
||||
if "!choice!"=="2" (
|
||||
|
|
@ -186,15 +199,15 @@ if "!choice!"=="2" (
|
|||
goto menu
|
||||
)
|
||||
if "!choice!"=="3" (
|
||||
echo --- telesrv ---
|
||||
powershell -NoProfile -Command "Get-Content '%TELESRV_LOG%' -Tail 50 -ErrorAction SilentlyContinue"
|
||||
echo --- telesrv-admin ---
|
||||
echo --- owpengram-server ---
|
||||
powershell -NoProfile -Command "Get-Content '%SERVER_LOG%' -Tail 50 -ErrorAction SilentlyContinue"
|
||||
echo --- owpengram-admin-panel ---
|
||||
powershell -NoProfile -Command "Get-Content '%ADMIN_LOG%' -Tail 50 -ErrorAction SilentlyContinue"
|
||||
goto menu
|
||||
)
|
||||
if "!choice!"=="4" (
|
||||
echo Press Ctrl+C to stop following
|
||||
powershell -NoProfile -Command "Get-Content '%TELESRV_LOG%' -Wait -Tail 10"
|
||||
powershell -NoProfile -Command "Get-Content '%SERVER_LOG%' -Wait -Tail 10"
|
||||
goto menu
|
||||
)
|
||||
if "!choice!"=="5" (
|
||||
|
|
@ -208,8 +221,8 @@ goto menu
|
|||
|
||||
:stop_server
|
||||
echo.
|
||||
echo [stop] stopping telesrv and telesrv-admin ...
|
||||
if defined TELESRV_PID taskkill /PID %TELESRV_PID% /T /F >nul 2>&1
|
||||
echo [stop] stopping owpengram-server and owpengram-admin-panel ...
|
||||
if defined SERVER_PID taskkill /PID %SERVER_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
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ die() { echo "[ERROR] $*" >&2; exit 1; }
|
|||
# --- Docker container/volume naming (telesrv -> owpengram), one-time, opt-in
|
||||
# Resolves whether this install uses the new "owpengram" Docker naming or (if
|
||||
# telesrv_* volumes exist and the user declined migrating them) keeps the old
|
||||
# "telesrv" naming permanently. See deploy/migrate-docker-naming.ps1.
|
||||
NAMING_OUT="$(powershell -NoProfile -ExecutionPolicy Bypass -File deploy/migrate-docker-naming.ps1)" \
|
||||
# "telesrv" naming permanently. See deploy/migrate-docker-naming.sh.
|
||||
NAMING_OUT="$(bash deploy/migrate-docker-naming.sh "$COMPOSE_FILE" .docker_naming)" \
|
||||
|| die "docker naming resolution failed"
|
||||
DOCKER_PROJECT="$(sed -n '1p' <<<"$NAMING_OUT")"
|
||||
DOCKER_PREFIX="$(sed -n '2p' <<<"$NAMING_OUT")"
|
||||
|
|
@ -57,53 +57,62 @@ for i in $(seq 1 30); do
|
|||
sleep 2
|
||||
done
|
||||
|
||||
# --- Postgres role/database naming (telesrv -> owpengram), one-time, opt-in
|
||||
# Only runs for installs that already accepted the Docker naming migration
|
||||
# above; a "telesrv"-naming install already said no to this rename theme once
|
||||
# and isn't asked again. See deploy/migrate-db-naming.sh.
|
||||
if [ "$DOCKER_PREFIX" = "owpengram" ]; then
|
||||
bash deploy/migrate-db-naming.sh "${DOCKER_PREFIX}-postgres" "$ENV_FILE" .db_naming \
|
||||
|| die "postgres naming migration failed"
|
||||
fi
|
||||
|
||||
# --- Build ------------------------------------------------------------------
|
||||
step "[3/4] Building server binaries"
|
||||
if [ "$NO_BUILD" = true ]; then
|
||||
log "skipping build (--no-build)"
|
||||
if [[ ! -f "bin/telesrv" ]] && [[ ! -f "bin/telesrv.exe" ]]; then
|
||||
if [[ ! -f "bin/owpengram-server" ]] && [[ ! -f "bin/owpengram-server.exe" ]]; then
|
||||
die "no binaries found in bin/ — run without --no-build first"
|
||||
fi
|
||||
else
|
||||
mkdir -p bin
|
||||
echo " building telesrv ..."
|
||||
go build -o bin/telesrv ./cmd/telesrv
|
||||
echo " building telesrv-admin ..."
|
||||
go build -o bin/telesrv-admin ./cmd/telesrv-admin
|
||||
echo " building owpengram-server ..."
|
||||
go build -o bin/owpengram-server ./cmd/telesrv
|
||||
echo " building owpengram-admin-panel ..."
|
||||
go build -o bin/owpengram-admin-panel ./cmd/telesrv-admin
|
||||
echo "[ok] binaries built in bin/"
|
||||
fi
|
||||
|
||||
# --- Start servers ----------------------------------------------------------
|
||||
step "[4/4] Starting telesrv + telesrv-admin"
|
||||
step "[4/4] Starting owpengram-server + owpengram-admin-panel"
|
||||
|
||||
mkdir -p "$LOG_DIR"
|
||||
TELESRV_LOG="$LOG_DIR/telesrv.log"
|
||||
ADMIN_LOG="$LOG_DIR/telesrv-admin.log"
|
||||
SERVER_LOG="$LOG_DIR/owpengram-server.log"
|
||||
ADMIN_LOG="$LOG_DIR/owpengram-admin-panel.log"
|
||||
|
||||
cleanup() {
|
||||
echo
|
||||
echo "[stop] stopping telesrv and telesrv-admin ..."
|
||||
kill "$TELESRV_PID" 2>/dev/null || true
|
||||
echo "[stop] stopping owpengram-server and owpengram-admin-panel ..."
|
||||
kill "$SERVER_PID" 2>/dev/null || true
|
||||
kill "$ADMIN_PID" 2>/dev/null || true
|
||||
wait "$TELESRV_PID" 2>/dev/null || true
|
||||
wait "$SERVER_PID" 2>/dev/null || true
|
||||
wait "$ADMIN_PID" 2>/dev/null || true
|
||||
echo "[ok] stopped."
|
||||
}
|
||||
trap cleanup EXIT INT TERM
|
||||
|
||||
# Start telesrv (main server)
|
||||
BIN="./bin/telesrv"
|
||||
[[ -f "bin/telesrv.exe" ]] && BIN="./bin/telesrv.exe"
|
||||
$BIN >>"$TELESRV_LOG" 2>&1 &
|
||||
TELESRV_PID=$!
|
||||
echo "[ok] telesrv started (PID ${TELESRV_PID}), logs -> ${TELESRV_LOG}"
|
||||
# Start owpengram-server (main server)
|
||||
BIN="./bin/owpengram-server"
|
||||
[[ -f "bin/owpengram-server.exe" ]] && BIN="./bin/owpengram-server.exe"
|
||||
$BIN >>"$SERVER_LOG" 2>&1 &
|
||||
SERVER_PID=$!
|
||||
echo "[ok] owpengram-server started (PID ${SERVER_PID}), logs -> ${SERVER_LOG}"
|
||||
|
||||
# Start telesrv-admin (admin panel)
|
||||
ADMIN_BIN="./bin/telesrv-admin"
|
||||
[[ -f "bin/telesrv-admin.exe" ]] && ADMIN_BIN="./bin/telesrv-admin.exe"
|
||||
# Start owpengram-admin-panel (admin panel)
|
||||
ADMIN_BIN="./bin/owpengram-admin-panel"
|
||||
[[ -f "bin/owpengram-admin-panel.exe" ]] && ADMIN_BIN="./bin/owpengram-admin-panel.exe"
|
||||
$ADMIN_BIN >>"$ADMIN_LOG" 2>&1 &
|
||||
ADMIN_PID=$!
|
||||
echo "[ok] telesrv-admin started (PID ${ADMIN_PID}), logs -> ${ADMIN_LOG}"
|
||||
echo "[ok] owpengram-admin-panel started (PID ${ADMIN_PID}), logs -> ${ADMIN_LOG}"
|
||||
|
||||
echo
|
||||
echo "============================================"
|
||||
|
|
@ -111,45 +120,45 @@ echo " OwpenGram server is running"
|
|||
echo "============================================"
|
||||
echo ""
|
||||
echo " Logs:"
|
||||
echo " telesrv: tail -f ${TELESRV_LOG}"
|
||||
echo " telesrv-admin: tail -f ${ADMIN_LOG}"
|
||||
echo " owpengram-server: tail -f ${SERVER_LOG}"
|
||||
echo " owpengram-admin-panel: tail -f ${ADMIN_LOG}"
|
||||
echo "============================================"
|
||||
|
||||
# --- Interactive menu -------------------------------------------------------
|
||||
show_menu() {
|
||||
echo
|
||||
echo " [1] View telesrv logs (last 50 lines)"
|
||||
echo " [2] View telesrv-admin logs (last 50 lines)"
|
||||
echo " [1] View owpengram-server logs (last 50 lines)"
|
||||
echo " [2] View owpengram-admin-panel logs (last 50 lines)"
|
||||
echo " [3] View both logs (last 50 lines)"
|
||||
echo " [4] Tail telesrv logs (live)"
|
||||
echo " [5] Tail telesrv-admin logs (live)"
|
||||
echo " [4] Tail owpengram-server logs (live)"
|
||||
echo " [5] Tail owpengram-admin-panel logs (live)"
|
||||
echo " [q] Stop server and exit"
|
||||
echo
|
||||
}
|
||||
|
||||
while true; do
|
||||
# Check if processes are still alive
|
||||
if ! kill -0 "$TELESRV_PID" 2>/dev/null; then
|
||||
echo "[WARN] telesrv (PID ${TELESRV_PID}) exited unexpectedly"
|
||||
echo " Check ${TELESRV_LOG} for details"
|
||||
if ! kill -0 "$SERVER_PID" 2>/dev/null; then
|
||||
echo "[WARN] owpengram-server (PID ${SERVER_PID}) exited unexpectedly"
|
||||
echo " Check ${SERVER_LOG} for details"
|
||||
kill "$ADMIN_PID" 2>/dev/null || true
|
||||
break
|
||||
fi
|
||||
if ! kill -0 "$ADMIN_PID" 2>/dev/null; then
|
||||
echo "[WARN] telesrv-admin (PID ${ADMIN_PID}) exited unexpectedly"
|
||||
echo "[WARN] owpengram-admin-panel (PID ${ADMIN_PID}) exited unexpectedly"
|
||||
echo " Check ${ADMIN_LOG} for details"
|
||||
kill "$TELESRV_PID" 2>/dev/null || true
|
||||
kill "$SERVER_PID" 2>/dev/null || true
|
||||
break
|
||||
fi
|
||||
|
||||
show_menu
|
||||
read -rp " Choice: " choice
|
||||
case "$choice" in
|
||||
1) tail -n 50 "$TELESRV_LOG" 2>/dev/null || echo " (no logs yet)" ;;
|
||||
1) tail -n 50 "$SERVER_LOG" 2>/dev/null || echo " (no logs yet)" ;;
|
||||
2) tail -n 50 "$ADMIN_LOG" 2>/dev/null || echo " (no logs yet)" ;;
|
||||
3) echo " --- telesrv ---" ; tail -n 50 "$TELESRV_LOG" 2>/dev/null || echo " (no logs yet)"
|
||||
echo " --- telesrv-admin ---" ; tail -n 50 "$ADMIN_LOG" 2>/dev/null || echo " (no logs yet)" ;;
|
||||
4) echo " Press Ctrl+C to stop tailing"; tail -f "$TELESRV_LOG" ;;
|
||||
3) echo " --- owpengram-server ---" ; tail -n 50 "$SERVER_LOG" 2>/dev/null || echo " (no logs yet)"
|
||||
echo " --- owpengram-admin-panel ---" ; tail -n 50 "$ADMIN_LOG" 2>/dev/null || echo " (no logs yet)" ;;
|
||||
4) echo " Press Ctrl+C to stop tailing"; tail -f "$SERVER_LOG" ;;
|
||||
5) echo " Press Ctrl+C to stop tailing"; tail -f "$ADMIN_LOG" ;;
|
||||
q|Q) break ;;
|
||||
*) echo " Invalid choice" ;;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue