Fix busy binary reinstall and add per-node log viewing.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -223,6 +223,48 @@ func (s *Server) nodeDelete(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, "/admin/nodes?ok=deleted", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (s *Server) nodeFetchLogs(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := uuid.Parse(mux.Vars(r)["id"])
|
||||
if err != nil {
|
||||
http.Error(w, "invalid id", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
n, err := db.GetNode(s.DB, id)
|
||||
if err != nil || n == nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
var chunks []string
|
||||
stamp := time.Now().UTC().Format("2006-01-02 15:04:05 UTC")
|
||||
chunks = append(chunks, "=== fetched at "+stamp+" ===")
|
||||
|
||||
if agentLogs, err := nodeclient.FetchLogs(n, 300); err == nil {
|
||||
chunks = append(chunks, "---- agent API /api/v1/logs ----", agentLogs)
|
||||
} else {
|
||||
chunks = append(chunks, "---- agent API ----", "unavailable: "+err.Error())
|
||||
}
|
||||
|
||||
secret, err := secretbox.Decrypt(s.SecretKey, n.SSHSecretEnc)
|
||||
if err == nil && secret != "" {
|
||||
if dockerLogs, err := nodeinstall.FetchDockerLogs(n, secret, 300); err == nil {
|
||||
chunks = append(chunks, "---- docker / SSH ----", dockerLogs)
|
||||
} else {
|
||||
chunks = append(chunks, "---- docker / SSH ----", "unavailable: "+err.Error())
|
||||
}
|
||||
} else {
|
||||
chunks = append(chunks, "---- docker / SSH ----", "(no SSH credentials stored — only agent API logs)")
|
||||
}
|
||||
|
||||
full := strings.Join(chunks, "\n")
|
||||
if err := db.SetNodeRuntimeLog(s.DB, id, full); err != nil {
|
||||
log.Printf("save runtime log: %v", err)
|
||||
http.Redirect(w, r, "/admin/nodes/"+id.String()+"?err=logs_save", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, "/admin/nodes/"+id.String()+"#logs", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func (s *Server) runAutoInstall(id uuid.UUID) {
|
||||
n, err := db.GetNode(s.DB, id)
|
||||
if err != nil || n == nil {
|
||||
|
||||
Reference in New Issue
Block a user