Fix Tachyon APK discovery and release package revision 122-r2
OpenWrt IPK and APK / Validate source and resolve stable SDKs (push) Waiting to run
OpenWrt IPK and APK / Validate source and resolve stable SDKs (push) Waiting to run
This commit is contained in:
1 parent
70a4705e67
commit
927aec8ffe
18 files changed
+496
-45
No files matched your search
@@ -0,0 +1,113 @@
|
||||
[CmdletBinding(DefaultParameterSetName = 'Router')]
|
||||
param(
|
||||
[Parameter(ParameterSetName = 'Router')][string]$Router = 'root@192.168.2.1',
|
||||
[Parameter(Mandatory = $true, ParameterSetName = 'Vps')][string]$Vps,
|
||||
[Parameter(ParameterSetName = 'Vps')][ValidatePattern('^[A-Za-z0-9_.-]+$')][string]$RouterId,
|
||||
[ValidateSet('Install', 'Rollback', 'Status')][string]$Action = 'Install',
|
||||
[switch]$PrepareOnly
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$Deploy = Join-Path $PSScriptRoot 'deploy-tachyon.ps1'
|
||||
if ($Action -eq 'Status') {
|
||||
if (-not $Vps -or -not $RouterId) { throw 'Status requires -Vps and -RouterId, for example node-12.' }
|
||||
$Status = @'
|
||||
import json, sqlite3, time, urllib.request
|
||||
from contextlib import closing
|
||||
with closing(sqlite3.connect('file:/var/lib/owrt-remote/hub.db?mode=ro', uri=True)) as db:
|
||||
row = db.execute('select last_seen,status_json,tachyon_entry_port from routers where id=? and coalesce(deleted_at,0)=0', ('__ROUTER_ID__',)).fetchone()
|
||||
if not row:
|
||||
raise SystemExit('Router __ROUTER_ID__ not found in Hub')
|
||||
status = json.loads(row[1] or '{}')
|
||||
tachyon = status.get('tachyon') or {}
|
||||
age = max(0, int(time.time() - float(row[0] or 0)))
|
||||
api_ok = False
|
||||
reason = 'standalone route unavailable'
|
||||
if tachyon.get('mode') == 'standalone' and row[2]:
|
||||
try:
|
||||
opener = urllib.request.build_opener(urllib.request.ProxyHandler({}))
|
||||
with opener.open('http://127.0.0.1:' + str(int(row[2])) + '/api/agent/v1/health', timeout=4) as response:
|
||||
health = json.loads(response.read(65536))
|
||||
api_ok = type(health.get('core_running')) is bool
|
||||
reason = 'Tachyon API confirmed through the reverse tunnel' if api_ok else 'Unexpected API response'
|
||||
except Exception as error:
|
||||
reason = 'Reverse route: ' + type(error).__name__
|
||||
print(json.dumps({'router':'__ROUTER_ID__', 'version':tachyon.get('version') or '',
|
||||
'package_version':tachyon.get('package_version') or '', 'mode':tachyon.get('mode') or 'unknown',
|
||||
'port':tachyon.get('port'), 'xray':status.get('xray'), 'heartbeat_age_seconds':age,
|
||||
'api_ok':api_ok, 'reason':reason}, ensure_ascii=True, indent=2))
|
||||
ok = age <= 120 and status.get('xray') == 'running' and tachyon.get('available') and api_ok
|
||||
print('TACHYON_CHECK_OK: __ROUTER_ID__' if ok else 'TACHYON_CHECK_FAILED: __ROUTER_ID__')
|
||||
raise SystemExit(0 if ok else 1)
|
||||
'@
|
||||
$Status = $Status.Replace('__ROUTER_ID__', $RouterId)
|
||||
$Status.Replace("`r`n", "`n") | & ssh -T -o ConnectTimeout=20 $Vps 'python3 -'
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Router check failed. See mode, version and API result above. No files were changed.' }
|
||||
return
|
||||
}
|
||||
$Options = @{ Action = $Action; BackupName = 'tachyon-detection'; BackupVersion = 'v122'; PrepareOnly = $PrepareOnly }
|
||||
if ($PSCmdlet.ParameterSetName -eq 'Router') {
|
||||
& $Deploy -Router $Router @Options
|
||||
} elseif (-not $RouterId) {
|
||||
& $Deploy -Vps $Vps @Options
|
||||
} else {
|
||||
# Query only this router's loopback SSH listener. RouterId cannot contain
|
||||
# shell/SQL quoting characters, and the database is opened read-only.
|
||||
$Query = @'
|
||||
import sqlite3, time
|
||||
from contextlib import closing
|
||||
with closing(sqlite3.connect('file:/var/lib/owrt-remote/hub.db?mode=ro', uri=True)) as db:
|
||||
row = db.execute('select ssh_entry_port from routers where id=? and coalesce(deleted_at,0)=0', ('__ROUTER_ID__',)).fetchone()
|
||||
if not row or not isinstance(row[0], int) or not 1024 <= row[0] <= 65535:
|
||||
raise SystemExit('Router has no valid loopback SSH entry in Hub')
|
||||
print('TACHYON_SSH_PORT=' + str(row[0]))
|
||||
print('TACHYON_MIN_SEEN=' + str(int(time.time())))
|
||||
'@
|
||||
$Query = $Query.Replace('__ROUTER_ID__', $RouterId)
|
||||
$Output = $Query.Replace("`r`n", "`n") | & ssh -T -o ConnectTimeout=20 $Vps 'python3 -'
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Cannot read the selected router SSH port. Router was not changed.' }
|
||||
$PortLine = @($Output | Where-Object { $_ -match '^TACHYON_SSH_PORT=([0-9]+)$' })
|
||||
if ($PortLine.Count -ne 1) { throw 'Hub did not return one SSH port. Router was not changed.' }
|
||||
$RouterPort = [int]($PortLine[0] -replace '^TACHYON_SSH_PORT=', '')
|
||||
if ($RouterPort -lt 1024 -or $RouterPort -gt 65535) { throw 'Invalid SSH listener port.' }
|
||||
Write-Host "Selected router: $RouterId; SSH via $Vps and loopback port $RouterPort"
|
||||
$SinceLine = @($Output | Where-Object { $_ -match '^TACHYON_MIN_SEEN=([0-9]+)$' })
|
||||
if ($SinceLine.Count -ne 1) { throw 'Hub did not return a verification timestamp.' }
|
||||
$Since = [long]($SinceLine[0] -replace '^TACHYON_MIN_SEEN=', '')
|
||||
& $Deploy -Router root@127.0.0.1 -Port $RouterPort -JumpHost $Vps -DeferRestart @Options
|
||||
if ($PrepareOnly) { return }
|
||||
# Verification uses the VPS, so a reconnecting reverse SSH tunnel does
|
||||
# not interrupt it. It also verifies the real route, not just a green card.
|
||||
$Verify = @'
|
||||
import json, sqlite3, time, urllib.request
|
||||
from contextlib import closing
|
||||
opener = urllib.request.build_opener(urllib.request.ProxyHandler({}))
|
||||
last = 'Waiting for a fresh Heartbeat and the standalone route'
|
||||
for attempt in range(40):
|
||||
with closing(sqlite3.connect('file:/var/lib/owrt-remote/hub.db?mode=ro', uri=True)) as db:
|
||||
row = db.execute('select last_seen,status_json,tachyon_entry_port from routers where id=?', ('__ROUTER_ID__',)).fetchone()
|
||||
try:
|
||||
status = json.loads(row[1] or '{}') if row else {}
|
||||
tachyon = status.get('tachyon') or {}
|
||||
fresh = row and float(row[0] or 0) >= __SINCE__
|
||||
if fresh and status.get('xray') == 'running':
|
||||
if '__ACTION__' == 'Rollback':
|
||||
print('TACHYON_DETECTION_Router_Rollback_OK: fresh Heartbeat; Xray running')
|
||||
break
|
||||
if tachyon.get('mode') == 'standalone' and tachyon.get('available') and tachyon.get('version') and row[2]:
|
||||
with opener.open('http://127.0.0.1:' + str(int(row[2])) + '/api/agent/v1/health', timeout=3) as response:
|
||||
health = json.loads(response.read(65536))
|
||||
if type(health.get('core_running')) is bool:
|
||||
print('TACHYON_DETECTION_Router_Install_OK: ' + str(tachyon.get('version')) + '; standalone API verified through the router tunnel')
|
||||
break
|
||||
last = 'Waiting for router __ROUTER_ID__: mode=' + str(tachyon.get('mode')) + '; Xray=' + str(status.get('xray'))
|
||||
except Exception as error:
|
||||
last = 'Reverse route not ready: ' + type(error).__name__
|
||||
time.sleep(2)
|
||||
else:
|
||||
raise SystemExit('Result not confirmed: ' + last + '; backup retained at /root/owrt-remote-backup-before-tachyon-detection-v122')
|
||||
'@
|
||||
$Verify = $Verify.Replace('__ROUTER_ID__', $RouterId).Replace('__SINCE__', [string]$Since).Replace('__ACTION__', $Action)
|
||||
$Verify.Replace("`r`n", "`n") | & ssh -T -o ConnectTimeout=20 -o ServerAliveInterval=15 $Vps 'python3 -'
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Router result not confirmed. See diagnostic above; retained backup is available for Rollback.' }
|
||||
}
|
||||
+36
-8
@@ -2,7 +2,11 @@ param(
|
||||
[Parameter(Mandatory = $true, ParameterSetName = 'Vps')][string]$Vps,
|
||||
[Parameter(Mandatory = $true, ParameterSetName = 'Router')][string]$Router,
|
||||
[ValidateSet('Install', 'Rollback')][string]$Action = 'Install',
|
||||
[ValidateSet('tachyon-integration', 'tachyon-layout')][string]$BackupName = 'tachyon-integration',
|
||||
[ValidateSet('tachyon-integration', 'tachyon-layout', 'tachyon-detection')][string]$BackupName = 'tachyon-integration',
|
||||
[ValidateSet('v121', 'v122')][string]$BackupVersion = 'v121',
|
||||
[ValidateRange(1, 65535)][int]$Port = 22,
|
||||
[string]$JumpHost = '',
|
||||
[switch]$DeferRestart,
|
||||
[switch]$PrepareOnly
|
||||
)
|
||||
|
||||
@@ -13,6 +17,7 @@ $StageRoot = Join-Path ([System.IO.Path]::GetTempPath()) $UploadName
|
||||
$Utf8 = [System.Text.UTF8Encoding]::new($false)
|
||||
$TargetKind = $PSCmdlet.ParameterSetName
|
||||
$Destination = if ($TargetKind -eq 'Vps') { $Vps } else { $Router }
|
||||
if ($DeferRestart -and $TargetKind -ne 'Router') { throw 'Deferred restart requires a router target.' }
|
||||
|
||||
$RemoteScript = @'
|
||||
#!/bin/sh
|
||||
@@ -23,6 +28,7 @@ action=__ACTION__
|
||||
backup=/root/owrt-remote-backup-before-__BACKUP_NAME__-v121
|
||||
changed=0
|
||||
step=preflight
|
||||
defer_restart=__DEFER_RESTART__
|
||||
|
||||
if [ "$kind" = Vps ]; then
|
||||
names=hub.py
|
||||
@@ -155,8 +161,15 @@ snapshot "$stage/previous"
|
||||
changed=1
|
||||
step=apply-files
|
||||
apply_files "$source_dir"
|
||||
if [ "$kind" = Router ] && [ "$action" = Install ]; then
|
||||
step=refresh-discovery
|
||||
# Refresh the bounded RAM cache before rendering Xray, so an old LuCI
|
||||
# classification cannot keep the standalone route absent for another beat.
|
||||
/usr/sbin/owrt-remote tachyon-status >"$stage/tachyon-status"
|
||||
cat "$stage/tachyon-status"
|
||||
fi
|
||||
step=restart
|
||||
restart
|
||||
if [ "$defer_restart" != 1 ]; then restart; fi
|
||||
|
||||
step=verify-health
|
||||
if [ "$kind" = Vps ]; then
|
||||
@@ -190,12 +203,21 @@ for name in $names; do
|
||||
path="$(target "$name")"
|
||||
if [ -e "$source_dir/$name.absent" ]; then test ! -e "$path"; else cmp "$source_dir/$name" "$path"; fi
|
||||
done
|
||||
printf '\nBackup: %s\nTACHYON_INTEGRATION_%s_%s_OK\n' "$backup" "$kind" "$action"
|
||||
if [ "$defer_restart" = 1 ]; then
|
||||
step=queue-restart
|
||||
# An SSH connection through Xray must finish before Xray stops. This
|
||||
# bounded procd worker is independent of the service being restarted.
|
||||
ubus call service add '{"name":"owrt-remote-tachyon-refresh","instances":{"once":{"command":["/bin/sh","-c","sleep 3; /etc/init.d/owrt-remote restart","__UPLOAD_NAME__"],"stdout":true,"stderr":true}}}' >/dev/null
|
||||
printf '\nBackup: %s\nTACHYON_RESTART_QUEUED\n' "$backup"
|
||||
else
|
||||
printf '\nBackup: %s\nTACHYON_INTEGRATION_%s_%s_OK\n' "$backup" "$kind" "$action"
|
||||
fi
|
||||
'@
|
||||
|
||||
try {
|
||||
[System.IO.Directory]::CreateDirectory($StageRoot) | Out-Null
|
||||
$RemoteScript = $RemoteScript.Replace('__UPLOAD_NAME__', $UploadName).Replace('__KIND__', $TargetKind).Replace('__ACTION__', $Action).Replace('__BACKUP_NAME__', $BackupName)
|
||||
if ($BackupVersion -eq 'v122') { $RemoteScript = $RemoteScript.Replace('-__BACKUP_NAME__-v121', '-__BACKUP_NAME__-v122') }
|
||||
$RemoteScript = $RemoteScript.Replace('__UPLOAD_NAME__', $UploadName).Replace('__KIND__', $TargetKind).Replace('__ACTION__', $Action).Replace('__BACKUP_NAME__', $BackupName).Replace('__DEFER_RESTART__', $(if ($DeferRestart) { '1' } else { '0' }))
|
||||
[System.IO.File]::WriteAllText((Join-Path $StageRoot 'run.sh'), $RemoteScript.Replace("`r`n", "`n") + "`n", $Utf8)
|
||||
if ($Action -eq 'Install') {
|
||||
$Sources = if ($TargetKind -eq 'Vps') {
|
||||
@@ -209,11 +231,17 @@ try {
|
||||
}
|
||||
}
|
||||
if ($PrepareOnly) { Write-Host "Prepared only: $StageRoot"; return }
|
||||
& scp -O -o ConnectTimeout=20 -r -- $StageRoot "${Destination}:/tmp/"
|
||||
$JumpOptions = if ($JumpHost) { @('-o', "ProxyJump=$JumpHost") } else { @() }
|
||||
& scp -O -P $Port @JumpOptions -o ConnectTimeout=20 -r -- $StageRoot "${Destination}:/tmp/"
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Upload failed. Target was not changed.' }
|
||||
& ssh -T -o ConnectTimeout=20 -o ServerAliveInterval=15 $Destination "sh /tmp/$UploadName/run.sh"
|
||||
if ($LASTEXITCODE -ne 0) { throw "$Action failed. Success was not confirmed; see output above." }
|
||||
Write-Host "Tachyon integration $TargetKind $Action finished successfully."
|
||||
$RemoteOutput = & ssh -T -p $Port @JumpOptions -o ConnectTimeout=20 -o ServerAliveInterval=15 $Destination "sh /tmp/$UploadName/run.sh"
|
||||
$RemoteCode = $LASTEXITCODE
|
||||
$RemoteOutput | Write-Output
|
||||
if ($RemoteCode -ne 0 -and -not ($DeferRestart -and $RemoteCode -eq 255 -and @($RemoteOutput) -contains 'TACHYON_RESTART_QUEUED')) {
|
||||
throw "$Action failed. Success was not confirmed; see output above."
|
||||
}
|
||||
if ($DeferRestart) { Write-Host 'Files applied; restart queued. Runtime verification follows.' }
|
||||
else { Write-Host "Tachyon integration $TargetKind $Action finished successfully." }
|
||||
} finally {
|
||||
if (-not $PrepareOnly -and (Test-Path -LiteralPath $StageRoot)) {
|
||||
$Resolved = [System.IO.Path]::GetFullPath($StageRoot)
|
||||
|
||||
@@ -8461,7 +8461,7 @@ function renderTachyon(router) {{
|
||||
const button = (router.permissions || {{}}).admin
|
||||
? `<a class="btn" href="${{escapeAttr(t.url)}}" target="_blank" rel="noopener noreferrer">Открыть Tachyon</a>`
|
||||
: '<span class="btn disabled">Открыть Tachyon</span>';
|
||||
return `<div class="tachyonIntegration" style="display:flex;flex-wrap:wrap;align-items:center;justify-content:center;gap:8px;padding:10px;margin-top:10px;border:1px solid var(--line,rgba(180,150,220,.25));border-radius:12px"><strong>Tachyon ${{escapeHtml(t.version || '')}}</strong><span style="color:${{t.online ? '#74e3ac' : '#f2bc6b'}}">${{label}}</span>${{button}}</div>`;
|
||||
return `<div class="tachyonIntegration" style="display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;padding:10px;margin-top:10px;border:1px solid var(--line,rgba(180,150,220,.25));border-radius:12px"><div class="tachyonMeta" style="display:flex;flex-wrap:wrap;align-items:center;justify-content:center;gap:8px;min-height:24px;max-width:100%"><strong style="min-width:0;max-width:100%;overflow-wrap:anywhere;text-align:center">Tachyon${{t.version ? ' ' + escapeHtml(t.version) : ''}}</strong><span style="color:${{t.online ? '#74e3ac' : '#f2bc6b'}}">${{label}}</span></div><div class="tachyonAction">${{button}}</div></div>`;
|
||||
}}
|
||||
|
||||
function render(list) {{
|
||||
|
||||
Reference in new issue
Block a user