Fix busy binary reinstall and add per-node log viewing.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
orohi
2026-07-29 04:31:09 +03:00
co-authored by Cursor
parent 2d8b1d4438
commit 1fb87f5f6c
10 changed files with 222 additions and 19 deletions
+7 -2
View File
@@ -75,6 +75,7 @@ CREATE TABLE IF NOT EXISTS nodes (
install_mode TEXT NOT NULL DEFAULT 'auto',
last_error TEXT NOT NULL DEFAULT '',
install_log TEXT NOT NULL DEFAULT '',
runtime_log TEXT NOT NULL DEFAULT '',
agent_version TEXT NOT NULL DEFAULT '',
last_seen_at TIMESTAMPTZ,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
@@ -95,8 +96,12 @@ CREATE TABLE IF NOT EXISTS node_protocols (
CREATE INDEX IF NOT EXISTS idx_node_protocols_protocol ON node_protocols(protocol_id);
`
_, err := db.Exec(schema)
return err
if _, err := db.Exec(schema); err != nil {
return err
}
// Additive migrations for existing deployments.
_, _ = db.Exec(`ALTER TABLE nodes ADD COLUMN IF NOT EXISTS runtime_log TEXT NOT NULL DEFAULT ''`)
return nil
}
func SeedAdmin(db *sql.DB, cfg *config.Config) error {
+16 -5
View File
@@ -20,7 +20,7 @@ func scanNode(scanner interface {
err := scanner.Scan(
&n.ID, &n.Name, &n.Host, &n.SSHPort, &n.SSHUser, &n.SSHAuthType, &n.SSHSecretEnc,
&n.NodePort, &n.SecretKey, &status, &n.InstallMode, &n.LastError, &n.InstallLog,
&n.AgentVersion, &lastSeen, &n.CreatedAt, &n.UpdatedAt,
&n.RuntimeLog, &n.AgentVersion, &lastSeen, &n.CreatedAt, &n.UpdatedAt,
)
if err != nil {
return nil, err
@@ -36,7 +36,7 @@ func scanNode(scanner interface {
const nodeColumns = `
id, name, host, ssh_port, ssh_user, ssh_auth_type, ssh_secret_enc,
node_port, secret_key, status, install_mode, last_error, install_log,
agent_version, last_seen_at, created_at, updated_at`
runtime_log, agent_version, last_seen_at, created_at, updated_at`
func CreateNode(db *sql.DB, n *models.Node) error {
if n.ID == uuid.Nil {
@@ -52,13 +52,13 @@ func CreateNode(db *sql.DB, n *models.Node) error {
INSERT INTO nodes (
id, name, host, ssh_port, ssh_user, ssh_auth_type, ssh_secret_enc,
node_port, secret_key, status, install_mode, last_error, install_log,
agent_version, last_seen_at, created_at, updated_at
runtime_log, agent_version, last_seen_at, created_at, updated_at
) VALUES (
$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17
$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18
)`,
n.ID, n.Name, n.Host, n.SSHPort, n.SSHUser, n.SSHAuthType, n.SSHSecretEnc,
n.NodePort, n.SecretKey, string(n.Status), n.InstallMode, n.LastError, n.InstallLog,
n.AgentVersion, n.LastSeenAt, n.CreatedAt, n.UpdatedAt,
n.RuntimeLog, n.AgentVersion, n.LastSeenAt, n.CreatedAt, n.UpdatedAt,
)
return err
}
@@ -114,6 +114,17 @@ WHERE id = $1`, id, strings.TrimRight(chunk, "\n"))
return err
}
func SetNodeRuntimeLog(db *sql.DB, id uuid.UUID, logText string) error {
// Cap stored log size to keep DB rows reasonable.
const max = 200_000
if len(logText) > max {
logText = logText[len(logText)-max:]
}
_, err := db.Exec(`
UPDATE nodes SET runtime_log = $2, updated_at = NOW() WHERE id = $1`, id, logText)
return err
}
func MarkNodeSeen(db *sql.DB, id uuid.UUID, version string, status models.NodeStatus) error {
_, err := db.Exec(`
UPDATE nodes