Async SSH for parallel status checks; Kuma 2 --base-path via CLI arg
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
32b4a98160
commit
8fdf3c8e4e
2 changed files with 12 additions and 9 deletions
|
|
@ -3,8 +3,7 @@ services:
|
|||
image: louislam/uptime-kuma:2
|
||||
security_opt:
|
||||
- apparmor=unconfined
|
||||
environment:
|
||||
- UPTIME_KUMA_BASE_PATH=/monitor
|
||||
command: ["node", "server/server.js", "--base-path=/monitor"]
|
||||
volumes:
|
||||
- kuma_data:/app/data
|
||||
ports:
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
import Fastify from 'fastify'
|
||||
import crypto from 'crypto'
|
||||
import { execSync } from 'child_process'
|
||||
import { exec, execSync } from 'child_process'
|
||||
import { promisify } from 'util'
|
||||
import { deployMap } from '../deploy-map.js'
|
||||
|
||||
const execAsync = promisify(exec)
|
||||
|
||||
const app = Fastify({ logger: true })
|
||||
const WEBHOOK_SECRET = process.env.WEBHOOK_SECRET || ''
|
||||
const SSH_KEY = process.env.SSH_KEY_PATH || '/root/.ssh/id_ed25519'
|
||||
|
|
@ -20,12 +23,13 @@ function verifySignature(body, signature) {
|
|||
return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(signature || ''))
|
||||
}
|
||||
|
||||
function sshGet(host, cmd) {
|
||||
async function sshGet(host, cmd) {
|
||||
try {
|
||||
return execSync(
|
||||
`ssh -i ${SSH_KEY} -o StrictHostKeyChecking=no -o ConnectTimeout=5 root@${host} "${cmd}"`,
|
||||
{ timeout: 15_000, encoding: 'utf8' }
|
||||
).trim()
|
||||
const { stdout } = await execAsync(
|
||||
`ssh -i ${SSH_KEY} -o StrictHostKeyChecking=no -o ConnectTimeout=2 root@${host} "${cmd}"`,
|
||||
{ timeout: 8_000 }
|
||||
)
|
||||
return stdout.trim()
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
|
|
@ -49,7 +53,7 @@ async function refreshStatus(repo) {
|
|||
if (!target) return null
|
||||
|
||||
const [current, latest] = await Promise.all([
|
||||
Promise.resolve(sshGet(target.host, `git -C ${target.path} rev-parse HEAD 2>/dev/null || echo not-deployed`)),
|
||||
sshGet(target.host, `git -C ${target.path} rev-parse HEAD 2>/dev/null || echo not-deployed`),
|
||||
getForgejoCommit(repo),
|
||||
])
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue