spinuptui 1.2.0-alpha.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -11
- package/README.md +2 -8
- package/package.json +1 -1
- package/src/api/client.ts +15 -0
- package/src/api/types.ts +3 -0
- package/src/config.ts +0 -23
- package/src/dev/mockClient.ts +30 -7
- package/src/index.tsx +17 -16
- package/src/lib/appUpdate.ts +7 -33
- package/src/lib/cliOffline.ts +418 -0
- package/src/lib/offline.test.ts +181 -0
- package/src/lib/offline.ts +422 -0
- package/src/ui/App.tsx +7 -11
- package/src/ui/Details.tsx +1 -1
- package/src/ui/Explain.tsx +2 -15
- package/src/ui/Header.tsx +0 -2
- package/src/ui/Help.tsx +3 -2
- package/src/ui/components.tsx +2 -1
- package/src/ui/offlineRun.tsx +82 -0
- package/src/ui/store.tsx +7 -7
- package/src/ui/views/Browser.tsx +9 -1
- package/src/ui/views/Dashboard.tsx +3 -1
- package/src/ui/views/Search.tsx +4 -1
- package/src/ui/views/ServerActions.tsx +102 -7
- package/src/ui/views/SiteOffline.tsx +171 -0
- package/src/ui/views/Stacks.tsx +5 -1
- package/src/lib/appUpdate.test.ts +0 -26
- package/src/lib/beacon.test.ts +0 -140
- package/src/lib/beacon.ts +0 -349
- package/src/lib/beaconSetup.test.ts +0 -65
- package/src/lib/beaconSetup.ts +0 -143
- package/src/lib/cliBeacon.ts +0 -290
- package/src/lib/prompt.ts +0 -47
- package/src/modules/beacon.ts +0 -51
- package/src/modules/contract.ts +0 -61
- package/src/modules/index.ts +0 -34
- package/src/ui/views/BeaconSetup.tsx +0 -268
- package/src/ui/views/Modules.tsx +0 -196
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
// Take a server's sites offline, and bring back exactly those sites later.
|
|
2
|
+
//
|
|
3
|
+
// For emergencies like an unpatched PHP remote-code-execution bug: SpinupWP's
|
|
4
|
+
// "disable site" removes the site's nginx server block, so port 80 returns an
|
|
5
|
+
// empty reply, 443 fails the TLS handshake, and no request reaches PHP (checked
|
|
6
|
+
// on a test box with direct-IP and --resolve requests too). Files, database,
|
|
7
|
+
// certificate, the PHP-FPM pool and the site's cron are all left in place.
|
|
8
|
+
//
|
|
9
|
+
// PHP is shared by every site on a server, so the usual unit is the server:
|
|
10
|
+
// one still-enabled site keeps the vulnerable binary reachable. Single sites
|
|
11
|
+
// can go offline too (one exposed site, or one client's site for reasons of its
|
|
12
|
+
// own); they're recorded under their server the same way. What this module
|
|
13
|
+
// disabled is recorded per server in `offline.json` (per account), and bringing
|
|
14
|
+
// a server back only re-enables those sites. A site someone had disabled for
|
|
15
|
+
// another reason stays disabled.
|
|
16
|
+
//
|
|
17
|
+
// Kuma: every monitor registered for the affected sites goes behind one manual
|
|
18
|
+
// maintenance window per server, so taking 30 sites down doesn't page 30 times.
|
|
19
|
+
// Best-effort both ways; Kuma being unreachable never blocks the API work.
|
|
20
|
+
|
|
21
|
+
import { existsSync, readFileSync } from "node:fs"
|
|
22
|
+
import { mkdir } from "node:fs/promises"
|
|
23
|
+
import { join } from "node:path"
|
|
24
|
+
import type { AppConfig, KumaMonitorRef } from "../config.ts"
|
|
25
|
+
import { profileDataDir } from "../config.ts"
|
|
26
|
+
import type { Event, Server, Site } from "../api/types.ts"
|
|
27
|
+
import type { SpinupWPClientLike } from "../api/client.ts"
|
|
28
|
+
import { ApiError } from "../api/client.ts"
|
|
29
|
+
import { withKuma } from "./uptimeKuma.ts"
|
|
30
|
+
|
|
31
|
+
// ---- State ----------------------------------------------------------------
|
|
32
|
+
|
|
33
|
+
export interface OfflineSite {
|
|
34
|
+
id: number
|
|
35
|
+
domain: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface OfflineRecord {
|
|
39
|
+
serverId: number
|
|
40
|
+
serverName: string
|
|
41
|
+
takenAt: string
|
|
42
|
+
// Only the sites this module disabled; the only ones "online" re-enables.
|
|
43
|
+
sites: OfflineSite[]
|
|
44
|
+
kumaMaintenanceId?: number
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface OfflineState {
|
|
48
|
+
servers: Record<string, OfflineRecord>
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function offlineStatePath(dir = profileDataDir()): string {
|
|
52
|
+
return join(dir, "offline.json")
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function loadOfflineState(dir = profileDataDir()): OfflineState {
|
|
56
|
+
try {
|
|
57
|
+
const path = offlineStatePath(dir)
|
|
58
|
+
if (!existsSync(path)) return { servers: {} }
|
|
59
|
+
const raw = JSON.parse(readFileSync(path, "utf8")) as Partial<OfflineState>
|
|
60
|
+
return { servers: raw.servers ?? {} }
|
|
61
|
+
} catch {
|
|
62
|
+
return { servers: {} }
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Read-modify-write, so a CLI run and the app working on different servers
|
|
67
|
+
// don't overwrite each other's records.
|
|
68
|
+
async function updateRecord(dir: string, serverId: number, fn: (r: OfflineRecord | undefined) => OfflineRecord | undefined): Promise<void> {
|
|
69
|
+
const state = loadOfflineState(dir)
|
|
70
|
+
const next = fn(state.servers[String(serverId)])
|
|
71
|
+
if (next) state.servers[String(serverId)] = next
|
|
72
|
+
else delete state.servers[String(serverId)]
|
|
73
|
+
await mkdir(dir, { recursive: true })
|
|
74
|
+
await Bun.write(offlineStatePath(dir), JSON.stringify(state, null, 2) + "\n")
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// ---- Event waiting ----------------------------------------------------------
|
|
78
|
+
|
|
79
|
+
const EVENT_DONE = new Set(["deployed", "completed", "finished", "success"])
|
|
80
|
+
const EVENT_FAIL = new Set(["failed", "errored", "error"])
|
|
81
|
+
|
|
82
|
+
export type EventOutcome = "done" | "failed" | "timeout"
|
|
83
|
+
|
|
84
|
+
// Wait on many events at once. One `GET /events` page covers the 100 newest,
|
|
85
|
+
// so a whole server (or fleet) costs one request per round instead of one per
|
|
86
|
+
// site; anything that has scrolled off that page is fetched individually. A
|
|
87
|
+
// timeout is reported as a timeout, never a failure: SpinupWP runs a server's
|
|
88
|
+
// events one at a time, so a big server's last site can sit queued a while.
|
|
89
|
+
export async function waitForEvents(
|
|
90
|
+
client: SpinupWPClientLike,
|
|
91
|
+
ids: number[],
|
|
92
|
+
opts: { timeoutMs?: number; pollMs?: number; onSettled?: (id: number, outcome: EventOutcome, event?: Event) => void } = {},
|
|
93
|
+
): Promise<Map<number, EventOutcome>> {
|
|
94
|
+
const timeoutMs = opts.timeoutMs ?? 15 * 60_000
|
|
95
|
+
const pollMs = opts.pollMs ?? 4000
|
|
96
|
+
const out = new Map<number, EventOutcome>()
|
|
97
|
+
const pending = new Set(ids)
|
|
98
|
+
const settle = (id: number, outcome: EventOutcome, ev?: Event) => {
|
|
99
|
+
pending.delete(id)
|
|
100
|
+
out.set(id, outcome)
|
|
101
|
+
opts.onSettled?.(id, outcome, ev)
|
|
102
|
+
}
|
|
103
|
+
const judge = (ev: Event) => {
|
|
104
|
+
if (!pending.has(ev.id)) return
|
|
105
|
+
if (EVENT_FAIL.has(ev.status)) settle(ev.id, "failed", ev)
|
|
106
|
+
else if (EVENT_DONE.has(ev.status) || ev.finished_at) settle(ev.id, "done", ev)
|
|
107
|
+
}
|
|
108
|
+
const deadline = Date.now() + timeoutMs
|
|
109
|
+
let apiErrs = 0
|
|
110
|
+
while (pending.size && Date.now() < deadline) {
|
|
111
|
+
await new Promise((r) => setTimeout(r, pollMs))
|
|
112
|
+
try {
|
|
113
|
+
const recent = await client.listEvents(1)
|
|
114
|
+
apiErrs = 0
|
|
115
|
+
const seen = new Set<number>()
|
|
116
|
+
for (const ev of recent) {
|
|
117
|
+
seen.add(ev.id)
|
|
118
|
+
judge(ev)
|
|
119
|
+
}
|
|
120
|
+
const oldest = recent.length ? Math.min(...recent.map((e) => e.id)) : Infinity
|
|
121
|
+
for (const id of [...pending]) {
|
|
122
|
+
if (seen.has(id) || id >= oldest) continue
|
|
123
|
+
judge(await client.getEvent(id))
|
|
124
|
+
}
|
|
125
|
+
} catch {
|
|
126
|
+
// A failed read isn't a failed event; give up only on a run of them.
|
|
127
|
+
if (++apiErrs >= 5) break
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
for (const id of pending) settle(id, "timeout")
|
|
131
|
+
return out
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// ---- Kuma -----------------------------------------------------------------
|
|
135
|
+
|
|
136
|
+
// Every monitor registered for a site: any numeric `*Id` on its ref, by the
|
|
137
|
+
// same convention the alerts toggle uses, so new monitor kinds are covered.
|
|
138
|
+
function monitorIdsFor(ref: KumaMonitorRef | undefined): number[] {
|
|
139
|
+
if (!ref) return []
|
|
140
|
+
return Object.entries(ref)
|
|
141
|
+
.filter((e): e is [string, number] => e[0].endsWith("Id") && typeof e[1] === "number")
|
|
142
|
+
.map(([, id]) => id)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export type KumaOutcome = "shielded" | "no_monitors" | "not_configured" | "failed" | "skipped"
|
|
146
|
+
|
|
147
|
+
async function shieldMonitors(cfg: AppConfig, server: Server, domains: string[], existingId?: number): Promise<{ outcome: KumaOutcome; id?: number; error?: string }> {
|
|
148
|
+
const conn = cfg.uptimeKuma
|
|
149
|
+
if (!conn) return { outcome: "not_configured" }
|
|
150
|
+
const ids = [...new Set(domains.flatMap((d) => monitorIdsFor(cfg.kumaMonitors[d])))]
|
|
151
|
+
if (!ids.length) return { outcome: "no_monitors" }
|
|
152
|
+
try {
|
|
153
|
+
const { result } = await withKuma(conn, async (kuma) => {
|
|
154
|
+
// A re-run after a partial one widens the window it already opened.
|
|
155
|
+
if (existingId != null) {
|
|
156
|
+
try {
|
|
157
|
+
await kuma.setMaintenanceMonitors(existingId, ids)
|
|
158
|
+
return existingId
|
|
159
|
+
} catch {
|
|
160
|
+
// Deleted in Kuma meanwhile; open a fresh one.
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const id = await kuma.addManualMaintenance(`Offline: ${server.name}`, "Sites taken offline from SpinupTUI. Removed automatically when they come back online.")
|
|
164
|
+
try {
|
|
165
|
+
await kuma.setMaintenanceMonitors(id, ids)
|
|
166
|
+
} catch (err) {
|
|
167
|
+
await kuma.deleteMaintenance(id).catch(() => {})
|
|
168
|
+
throw err
|
|
169
|
+
}
|
|
170
|
+
return id
|
|
171
|
+
})
|
|
172
|
+
return { outcome: "shielded", id: result }
|
|
173
|
+
} catch (err) {
|
|
174
|
+
return { outcome: "failed", error: (err as Error).message }
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// ---- Server lookup --------------------------------------------------------
|
|
179
|
+
|
|
180
|
+
export type ServerMatch = { ok: true; server: Server } | { ok: false; query: string; message: string; suggestions: string[] }
|
|
181
|
+
|
|
182
|
+
// Exact matches only (name, IP or id). A write that takes sites down must
|
|
183
|
+
// never act on a near-miss; a miss lists names that contain the query.
|
|
184
|
+
export function matchServer(servers: Server[], query: string): ServerMatch {
|
|
185
|
+
const q = query.trim().toLowerCase()
|
|
186
|
+
const hit = servers.find((s) => s.name.toLowerCase() === q || s.ip_address === q || String(s.id) === q)
|
|
187
|
+
if (hit) return { ok: true, server: hit }
|
|
188
|
+
const suggestions = servers.filter((s) => s.name.toLowerCase().includes(q)).map((s) => s.name).slice(0, 8)
|
|
189
|
+
return { ok: false, query, message: `No server named "${query}".`, suggestions }
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// ---- Take offline ---------------------------------------------------------
|
|
193
|
+
|
|
194
|
+
export interface OfflineServerResult {
|
|
195
|
+
serverId: number
|
|
196
|
+
serverName: string
|
|
197
|
+
// Disabled by this run.
|
|
198
|
+
disabled: string[]
|
|
199
|
+
// Already disabled before this run; left alone and not recorded.
|
|
200
|
+
alreadyOffline: string[]
|
|
201
|
+
failed: { domain: string; error: string }[]
|
|
202
|
+
kuma: KumaOutcome
|
|
203
|
+
kumaError?: string
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export interface OfflineOptions {
|
|
207
|
+
dir?: string
|
|
208
|
+
onProgress?: (line: string) => void
|
|
209
|
+
// False in Dev Mode: never talk to a real Kuma.
|
|
210
|
+
kuma?: boolean
|
|
211
|
+
timeoutMs?: number
|
|
212
|
+
pollMs?: number
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const errMsg = (err: unknown) => (err instanceof ApiError ? err.message : (err as Error).message)
|
|
216
|
+
|
|
217
|
+
export async function takeServerOffline(client: SpinupWPClientLike, cfg: AppConfig, server: Server, opts: OfflineOptions = {}): Promise<OfflineServerResult> {
|
|
218
|
+
const sites = await client.listSites(server.id)
|
|
219
|
+
const result = emptyOfflineResult(server)
|
|
220
|
+
result.alreadyOffline = sites.filter((s) => s.disabled_at).map((s) => s.domain)
|
|
221
|
+
const targets = sites.filter((s) => !s.disabled_at)
|
|
222
|
+
if (!targets.length) {
|
|
223
|
+
opts.onProgress?.(`${server.name}: every site is already offline`)
|
|
224
|
+
return result
|
|
225
|
+
}
|
|
226
|
+
return disableSites(client, cfg, server, targets, result, opts)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// One site. The rest of the server stays up, and so does its PHP: this
|
|
230
|
+
// protects that site, not the server.
|
|
231
|
+
export async function takeSiteOffline(client: SpinupWPClientLike, cfg: AppConfig, server: Server, siteId: number, opts: OfflineOptions = {}): Promise<OfflineServerResult> {
|
|
232
|
+
const site = (await client.listSites(server.id)).find((s) => s.id === siteId)
|
|
233
|
+
const result = emptyOfflineResult(server)
|
|
234
|
+
if (!site) throw new Error(`Site ${siteId} is no longer on ${server.name}.`)
|
|
235
|
+
if (site.disabled_at) {
|
|
236
|
+
result.alreadyOffline = [site.domain]
|
|
237
|
+
opts.onProgress?.(`${site.domain}: already offline`)
|
|
238
|
+
return result
|
|
239
|
+
}
|
|
240
|
+
return disableSites(client, cfg, server, [site], result, opts)
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function emptyOfflineResult(server: Server): OfflineServerResult {
|
|
244
|
+
return { serverId: server.id, serverName: server.name, disabled: [], alreadyOffline: [], failed: [], kuma: "skipped" }
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
async function disableSites(
|
|
248
|
+
client: SpinupWPClientLike,
|
|
249
|
+
cfg: AppConfig,
|
|
250
|
+
server: Server,
|
|
251
|
+
targets: Site[],
|
|
252
|
+
result: OfflineServerResult,
|
|
253
|
+
opts: OfflineOptions,
|
|
254
|
+
): Promise<OfflineServerResult> {
|
|
255
|
+
const dir = opts.dir ?? profileDataDir(cfg.profileId)
|
|
256
|
+
const say = opts.onProgress ?? (() => {})
|
|
257
|
+
|
|
258
|
+
const existing = loadOfflineState(dir).servers[String(server.id)]
|
|
259
|
+
if (opts.kuma !== false) {
|
|
260
|
+
const domains = [...new Set([...(existing?.sites ?? []).map((s) => s.domain), ...targets.map((s) => s.domain)])]
|
|
261
|
+
const k = await shieldMonitors(cfg, server, domains, existing?.kumaMaintenanceId)
|
|
262
|
+
result.kuma = k.outcome
|
|
263
|
+
if (k.error) result.kumaError = k.error
|
|
264
|
+
if (k.id != null) {
|
|
265
|
+
await updateRecord(dir, server.id, (r) => ({
|
|
266
|
+
...(r ?? { serverId: server.id, serverName: server.name, takenAt: new Date().toISOString(), sites: [] }),
|
|
267
|
+
kumaMaintenanceId: k.id,
|
|
268
|
+
}))
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// Record each site the moment its disable is accepted, before it finishes:
|
|
273
|
+
// if this process dies mid-run, "online" still knows to bring it back, and
|
|
274
|
+
// restoring a site that never went down is a harmless no-op.
|
|
275
|
+
const events = new Map<number, Site>()
|
|
276
|
+
for (const site of targets) {
|
|
277
|
+
try {
|
|
278
|
+
const { event_id } = await client.disableSite(site.id)
|
|
279
|
+
events.set(event_id, site)
|
|
280
|
+
await updateRecord(dir, server.id, (r) => {
|
|
281
|
+
const rec = r ?? { serverId: server.id, serverName: server.name, takenAt: new Date().toISOString(), sites: [] }
|
|
282
|
+
if (!rec.sites.some((s) => s.id === site.id)) rec.sites.push({ id: site.id, domain: site.domain })
|
|
283
|
+
return rec
|
|
284
|
+
})
|
|
285
|
+
say(`${site.domain}: going offline…`)
|
|
286
|
+
} catch (err) {
|
|
287
|
+
result.failed.push({ domain: site.domain, error: errMsg(err) })
|
|
288
|
+
say(`${site.domain}: ✕ ${errMsg(err)}`)
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
await waitForEvents(client, [...events.keys()], {
|
|
293
|
+
timeoutMs: opts.timeoutMs,
|
|
294
|
+
pollMs: opts.pollMs,
|
|
295
|
+
onSettled: (id, outcome, ev) => {
|
|
296
|
+
const site = events.get(id)!
|
|
297
|
+
if (outcome === "done") {
|
|
298
|
+
result.disabled.push(site.domain)
|
|
299
|
+
say(`${site.domain}: ✓ offline`)
|
|
300
|
+
} else if (outcome === "failed") {
|
|
301
|
+
const error = ev?.output?.trim() || "SpinupWP reported the disable as failed."
|
|
302
|
+
result.failed.push({ domain: site.domain, error })
|
|
303
|
+
say(`${site.domain}: ✕ ${error}`)
|
|
304
|
+
} else {
|
|
305
|
+
result.failed.push({ domain: site.domain, error: "Still queued at SpinupWP when we stopped waiting; it may yet complete. Re-run to check." })
|
|
306
|
+
say(`${site.domain}: … still queued at SpinupWP`)
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
})
|
|
310
|
+
return result
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// ---- Bring back online ----------------------------------------------------
|
|
314
|
+
|
|
315
|
+
export interface OnlineServerResult {
|
|
316
|
+
serverId: number
|
|
317
|
+
serverName: string
|
|
318
|
+
enabled: string[]
|
|
319
|
+
// Recorded, but already serving again (enabled by hand, say).
|
|
320
|
+
alreadyOnline: string[]
|
|
321
|
+
// Recorded, but deleted from SpinupWP since.
|
|
322
|
+
gone: string[]
|
|
323
|
+
failed: { domain: string; error: string }[]
|
|
324
|
+
// Nothing recorded for this server: this module didn't take it offline.
|
|
325
|
+
nothingRecorded: boolean
|
|
326
|
+
// Asked for by id but not taken offline by this module (siteIds only).
|
|
327
|
+
notRecorded: number[]
|
|
328
|
+
kumaWindowClosed: boolean
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// Bring back what this module took offline on a server: all of it, or only
|
|
332
|
+
// `siteIds` from it.
|
|
333
|
+
export async function bringServerOnline(
|
|
334
|
+
client: SpinupWPClientLike,
|
|
335
|
+
cfg: AppConfig,
|
|
336
|
+
serverId: number,
|
|
337
|
+
opts: OfflineOptions & { siteIds?: number[] } = {},
|
|
338
|
+
): Promise<OnlineServerResult> {
|
|
339
|
+
const dir = opts.dir ?? profileDataDir(cfg.profileId)
|
|
340
|
+
const say = opts.onProgress ?? (() => {})
|
|
341
|
+
const record = loadOfflineState(dir).servers[String(serverId)]
|
|
342
|
+
const result: OnlineServerResult = {
|
|
343
|
+
serverId,
|
|
344
|
+
serverName: record?.serverName ?? String(serverId),
|
|
345
|
+
enabled: [],
|
|
346
|
+
alreadyOnline: [],
|
|
347
|
+
gone: [],
|
|
348
|
+
failed: [],
|
|
349
|
+
nothingRecorded: !record,
|
|
350
|
+
notRecorded: opts.siteIds?.filter((id) => !record?.sites.some((s) => s.id === id)) ?? [],
|
|
351
|
+
kumaWindowClosed: false,
|
|
352
|
+
}
|
|
353
|
+
if (!record) return result
|
|
354
|
+
const wanted = opts.siteIds ? record.sites.filter((s) => opts.siteIds!.includes(s.id)) : record.sites
|
|
355
|
+
|
|
356
|
+
const live = new Map((await client.listSites(serverId)).map((s) => [s.id, s]))
|
|
357
|
+
const done = new Set<number>()
|
|
358
|
+
const events = new Map<number, OfflineSite>()
|
|
359
|
+
for (const rec of wanted) {
|
|
360
|
+
const site = live.get(rec.id)
|
|
361
|
+
if (!site) {
|
|
362
|
+
result.gone.push(rec.domain)
|
|
363
|
+
done.add(rec.id)
|
|
364
|
+
continue
|
|
365
|
+
}
|
|
366
|
+
if (!site.disabled_at) {
|
|
367
|
+
result.alreadyOnline.push(rec.domain)
|
|
368
|
+
done.add(rec.id)
|
|
369
|
+
continue
|
|
370
|
+
}
|
|
371
|
+
try {
|
|
372
|
+
const { event_id } = await client.enableSite(rec.id)
|
|
373
|
+
events.set(event_id, rec)
|
|
374
|
+
say(`${rec.domain}: coming back online…`)
|
|
375
|
+
} catch (err) {
|
|
376
|
+
result.failed.push({ domain: rec.domain, error: errMsg(err) })
|
|
377
|
+
say(`${rec.domain}: ✕ ${errMsg(err)}`)
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
await waitForEvents(client, [...events.keys()], {
|
|
382
|
+
timeoutMs: opts.timeoutMs,
|
|
383
|
+
pollMs: opts.pollMs,
|
|
384
|
+
onSettled: (id, outcome, ev) => {
|
|
385
|
+
const rec = events.get(id)!
|
|
386
|
+
if (outcome === "done") {
|
|
387
|
+
result.enabled.push(rec.domain)
|
|
388
|
+
done.add(rec.id)
|
|
389
|
+
say(`${rec.domain}: ✓ online`)
|
|
390
|
+
} else {
|
|
391
|
+
const error = outcome === "failed" ? ev?.output?.trim() || "SpinupWP reported the enable as failed." : "Still queued at SpinupWP when we stopped waiting. Re-run to check."
|
|
392
|
+
result.failed.push({ domain: rec.domain, error })
|
|
393
|
+
say(`${rec.domain}: ✕ ${error}`)
|
|
394
|
+
}
|
|
395
|
+
},
|
|
396
|
+
})
|
|
397
|
+
|
|
398
|
+
// Keep whatever didn't come back, so a re-run finishes the job. The Kuma
|
|
399
|
+
// window shrinks to the sites still offline, and closes once there are none
|
|
400
|
+
// (or none of them has monitors).
|
|
401
|
+
let left: OfflineSite[] = []
|
|
402
|
+
await updateRecord(dir, serverId, (r) => {
|
|
403
|
+
if (!r) return undefined
|
|
404
|
+
left = r.sites.filter((s) => !done.has(s.id))
|
|
405
|
+
return left.length ? { ...r, sites: left } : undefined
|
|
406
|
+
})
|
|
407
|
+
if (done.size && record.kumaMaintenanceId != null && cfg.uptimeKuma && opts.kuma !== false) {
|
|
408
|
+
const id = record.kumaMaintenanceId
|
|
409
|
+
const stillShielded = [...new Set(left.flatMap((s) => monitorIdsFor(cfg.kumaMonitors[s.domain])))]
|
|
410
|
+
if (stillShielded.length) {
|
|
411
|
+
await withKuma(cfg.uptimeKuma, (kuma) => kuma.setMaintenanceMonitors(id, stillShielded)).catch(() => {
|
|
412
|
+
// The restored sites stay quiet in Kuma until the rest come back.
|
|
413
|
+
})
|
|
414
|
+
} else {
|
|
415
|
+
result.kumaWindowClosed = await withKuma(cfg.uptimeKuma, (kuma) => kuma.deleteMaintenance(id))
|
|
416
|
+
.then(() => true)
|
|
417
|
+
.catch(() => false)
|
|
418
|
+
if (left.length) await updateRecord(dir, serverId, (r) => (r ? { ...r, kumaMaintenanceId: undefined } : r))
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
return result
|
|
422
|
+
}
|
package/src/ui/App.tsx
CHANGED
|
@@ -19,6 +19,7 @@ import { SiteUpdate } from "./views/SiteUpdate.tsx"
|
|
|
19
19
|
import { BulkWpUpdate } from "./views/BulkWpUpdate.tsx"
|
|
20
20
|
import { HttpsToggle } from "./views/HttpsToggle.tsx"
|
|
21
21
|
import { PurgeCache } from "./views/PurgeCache.tsx"
|
|
22
|
+
import { SiteOffline } from "./views/SiteOffline.tsx"
|
|
22
23
|
import { ReleaseNotes } from "./views/ReleaseNotes.tsx"
|
|
23
24
|
import { GrantKey } from "./views/GrantKey.tsx"
|
|
24
25
|
import { SudoConnect } from "./views/SudoConnect.tsx"
|
|
@@ -40,8 +41,6 @@ import { ProviderConnect } from "./views/ProviderConnect.tsx"
|
|
|
40
41
|
import { DnsRecords } from "./views/DnsRecords.tsx"
|
|
41
42
|
import { KumaSite } from "./views/KumaSite.tsx"
|
|
42
43
|
import { Accounts } from "./views/Accounts.tsx"
|
|
43
|
-
import { Modules } from "./views/Modules.tsx"
|
|
44
|
-
import { BeaconSetup } from "./views/BeaconSetup.tsx"
|
|
45
44
|
|
|
46
45
|
const MIN_SPLASH_MS = 1200
|
|
47
46
|
|
|
@@ -72,6 +71,7 @@ export function App() {
|
|
|
72
71
|
store.bulkWpGroup !== null ||
|
|
73
72
|
store.httpsToggleSite !== null ||
|
|
74
73
|
store.purgeCacheSite !== null ||
|
|
74
|
+
store.siteOfflineSite !== null ||
|
|
75
75
|
store.grantKeySite !== null ||
|
|
76
76
|
store.sudoConnectServer !== null ||
|
|
77
77
|
store.dbBackupSite !== null ||
|
|
@@ -89,8 +89,7 @@ export function App() {
|
|
|
89
89
|
store.dnsInventoryServer !== null ||
|
|
90
90
|
store.connectZoneTarget !== null ||
|
|
91
91
|
store.dnsRecordsTarget !== null ||
|
|
92
|
-
store.kumaSite !== null
|
|
93
|
-
store.beaconSetupOpen
|
|
92
|
+
store.kumaSite !== null
|
|
94
93
|
useEffect(() => {
|
|
95
94
|
store.setOverlayOpen(overlayActive)
|
|
96
95
|
}, [overlayActive, store])
|
|
@@ -149,6 +148,9 @@ export function App() {
|
|
|
149
148
|
// The purge-cache overlay owns the keyboard while open.
|
|
150
149
|
if (store.purgeCacheSite) return
|
|
151
150
|
|
|
151
|
+
// The take-site-offline overlay owns the keyboard while open.
|
|
152
|
+
if (store.siteOfflineSite) return
|
|
153
|
+
|
|
152
154
|
// The grant-SSH-key overlay owns the keyboard while open.
|
|
153
155
|
if (store.grantKeySite) return
|
|
154
156
|
|
|
@@ -203,9 +205,6 @@ export function App() {
|
|
|
203
205
|
// The site-monitoring (Uptime Kuma) overlay owns the keyboard while open.
|
|
204
206
|
if (store.kumaSite) return
|
|
205
207
|
|
|
206
|
-
// Beacon's guided setup (Modules tab) owns the keyboard while open.
|
|
207
|
-
if (store.beaconSetupOpen) return
|
|
208
|
-
|
|
209
208
|
// A (Shift+a): the Accounts overlay — the header advertises it from every tab.
|
|
210
209
|
if (key.shift && key.name === "a") return setShowAccounts(true)
|
|
211
210
|
|
|
@@ -222,8 +221,6 @@ export function App() {
|
|
|
222
221
|
return store.setRoute("search")
|
|
223
222
|
case "5":
|
|
224
223
|
return store.setRoute("events")
|
|
225
|
-
case "6":
|
|
226
|
-
return store.setRoute("modules")
|
|
227
224
|
case "r":
|
|
228
225
|
return void store.refresh()
|
|
229
226
|
case "?":
|
|
@@ -263,7 +260,6 @@ export function App() {
|
|
|
263
260
|
{store.route === "stacks" && <Stacks rows={contentRows} />}
|
|
264
261
|
{store.route === "search" && <Search rows={contentRows} />}
|
|
265
262
|
{store.route === "events" && <Events rows={contentRows} />}
|
|
266
|
-
{store.route === "modules" && <Modules rows={contentRows} />}
|
|
267
263
|
</box>
|
|
268
264
|
{showHelp && <HelpOverlay onClose={() => setShowHelp(false)} />}
|
|
269
265
|
{showExplain && <ExplainOverlay route={store.route} />}
|
|
@@ -274,6 +270,7 @@ export function App() {
|
|
|
274
270
|
{store.bulkWpGroup && <BulkWpUpdate />}
|
|
275
271
|
{store.httpsToggleSite && <HttpsToggle />}
|
|
276
272
|
{store.purgeCacheSite && <PurgeCache />}
|
|
273
|
+
{store.siteOfflineSite && <SiteOffline />}
|
|
277
274
|
{store.grantKeySite && <GrantKey />}
|
|
278
275
|
{store.sudoConnectServer && <SudoConnect />}
|
|
279
276
|
{store.dbBackupSite && <DbBackup />}
|
|
@@ -292,7 +289,6 @@ export function App() {
|
|
|
292
289
|
{store.connectZoneTarget && <ProviderConnect />}
|
|
293
290
|
{store.dnsRecordsTarget && <DnsRecords />}
|
|
294
291
|
{store.kumaSite && <KumaSite />}
|
|
295
|
-
{store.beaconSetupOpen && <BeaconSetup />}
|
|
296
292
|
{showAccounts && <Accounts onClose={() => setShowAccounts(false)} />}
|
|
297
293
|
<ToastStack />
|
|
298
294
|
</box>
|
package/src/ui/Details.tsx
CHANGED
package/src/ui/Explain.tsx
CHANGED
|
@@ -27,7 +27,7 @@ const GUIDES: Record<Route, Guide> = {
|
|
|
27
27
|
["Recent activity", "The latest deploys and operations"],
|
|
28
28
|
],
|
|
29
29
|
actions: [
|
|
30
|
-
["1–
|
|
30
|
+
["1–5", "Switch tabs"],
|
|
31
31
|
["r", "Refresh from the API"],
|
|
32
32
|
],
|
|
33
33
|
},
|
|
@@ -91,23 +91,10 @@ const GUIDES: Record<Route, Guide> = {
|
|
|
91
91
|
title: "Events",
|
|
92
92
|
summary: "A live feed of deploys, reboots, and operations across your account.",
|
|
93
93
|
actions: [
|
|
94
|
-
["1–
|
|
94
|
+
["1–5", "Switch tabs"],
|
|
95
95
|
["r", "Refresh"],
|
|
96
96
|
],
|
|
97
97
|
},
|
|
98
|
-
modules: {
|
|
99
|
-
title: "Modules",
|
|
100
|
-
summary: "Modules are the parts of SpinupTUI that keep working after you close it: paging you, running follow-ups, watching the fleet. Each card says what it does and whether it's set up on this machine.",
|
|
101
|
-
panes: [
|
|
102
|
-
["Modules", "Every module, with its status here: ● set up · ○ not set up · coming soon"],
|
|
103
|
-
["Detail", "What the selected module does, its health checks, and what to do next"],
|
|
104
|
-
],
|
|
105
|
-
actions: [
|
|
106
|
-
["⏎ / s", "Set up the selected module (Beacon: connect a Telegram bot)"],
|
|
107
|
-
["t", "Send a test page through Beacon"],
|
|
108
|
-
["1–6", "Switch tabs"],
|
|
109
|
-
],
|
|
110
|
-
},
|
|
111
98
|
}
|
|
112
99
|
|
|
113
100
|
export function ExplainOverlay({ route }: { route: Route }) {
|
package/src/ui/Header.tsx
CHANGED
|
@@ -15,7 +15,6 @@ const TABS: { route: Route; key: string; label: string }[] = [
|
|
|
15
15
|
{ route: "stacks", key: "3", label: "Stacks" },
|
|
16
16
|
{ route: "search", key: "4", label: "Search" },
|
|
17
17
|
{ route: "events", key: "5", label: "Events" },
|
|
18
|
-
{ route: "modules", key: "6", label: "Modules" },
|
|
19
18
|
]
|
|
20
19
|
|
|
21
20
|
// A one-line "what is this view, and what can I do here" subtitle per tab —
|
|
@@ -27,7 +26,6 @@ const SUBTITLES: Record<Route, string> = {
|
|
|
27
26
|
stacks: "Your fleet grouped by app type · d identify an app (SSH) · S find local copies on your disk",
|
|
28
27
|
search: "Jump to any server or site by name · Tab hands focus to the result's actions",
|
|
29
28
|
events: "Recent deploys, reboots, and operations across your account",
|
|
30
|
-
modules: "What keeps working after you close SpinupTUI · ⏎ set up the selected module",
|
|
31
29
|
}
|
|
32
30
|
|
|
33
31
|
// SpinupWP allows 60 API requests a minute. Show what's left of this minute so
|
package/src/ui/Help.tsx
CHANGED
|
@@ -15,7 +15,7 @@ type Section = { title: string; keys: [string, string][] }
|
|
|
15
15
|
const GLOBAL: Section = {
|
|
16
16
|
title: "Global",
|
|
17
17
|
keys: [
|
|
18
|
-
["1 …
|
|
18
|
+
["1 … 5", "Switch tabs"],
|
|
19
19
|
["r", "Refresh from the API"],
|
|
20
20
|
["/", "Global search"],
|
|
21
21
|
["A", "Switch SpinupWP accounts"],
|
|
@@ -37,13 +37,14 @@ const NAV: Section = {
|
|
|
37
37
|
["s", "SSH into the site"],
|
|
38
38
|
["h", "Server health (SSH)"],
|
|
39
39
|
["w", "Open in SpinupWP web app"],
|
|
40
|
-
["a", "Server actions (
|
|
40
|
+
["a", "Server actions (restart, take offline)"],
|
|
41
41
|
["c", "Create a new server"],
|
|
42
42
|
["C", "Clone this server to a new one"],
|
|
43
43
|
["S", "Connect sudo on the server"],
|
|
44
44
|
["u", "Update PHP version or WordPress core"],
|
|
45
45
|
["H", "Enable/disable HTTPS"],
|
|
46
46
|
["P", "Purge page + object cache"],
|
|
47
|
+
["O", "Take a site offline / bring it back"],
|
|
47
48
|
["K", "Grant SpinupTUI's SSH key (sudo)"],
|
|
48
49
|
["d", "Identify a site's app (SSH)"],
|
|
49
50
|
],
|
package/src/ui/components.tsx
CHANGED
|
@@ -463,11 +463,12 @@ export function siteGroups(isWordpress: boolean, isVanity: boolean): ActionGroup
|
|
|
463
463
|
remote.push(["H", "Toggle HTTPS"])
|
|
464
464
|
remote.push(["P", "Purge cache"])
|
|
465
465
|
remote.push(["M", "Monitoring"])
|
|
466
|
+
remote.push(["O", "Take offline"])
|
|
466
467
|
return [
|
|
467
468
|
{ title: "Open", items: [["o", "In browser"], ["w", "In SpinupWP"]] },
|
|
468
469
|
{ title: "Remote", items: remote },
|
|
469
470
|
{ title: "Local", items: local },
|
|
470
471
|
...(isVanity ? [{ title: "Vanity", items: [["R", "Refresh"]] as [string, string][] }] : []),
|
|
471
|
-
{ title: "Server", items: [["a", "
|
|
472
|
+
{ title: "Server", items: [["a", "Restart / offline"], ["h", "Health"]] },
|
|
472
473
|
]
|
|
473
474
|
}
|