Files
SIAX-MONITOR/src/api/dto.rs
pablinux 1f7ae42b3d fix: Fase 4.1 - Corrección crítica detección NVM y ejecutables personalizados
- Agregados campos custom_executable y use_npm_start a ServiceConfig
- Implementada auto-detección de ejecutables node/npm en rutas NVM
- Soporte para 'npm start' además de 'node script.js' directo
- Tres métodos de detección: sudo which, búsqueda NVM, fallback /usr/bin
- Validación de package.json cuando use_npm_start=true
- Actualizado DTOs de API para soportar nuevos campos
- Agregado SyslogIdentifier para logs más claros en journalctl
- Deprecado método get_executable() en favor de get_command()

Resuelve bug status 203/EXEC con Node.js instalado vía NVM.
Afecta: 80% de instalaciones Node.js en producción.

Cambios:
- src/models/service_config.rs: +30 líneas (validaciones y campos nuevos)
- src/systemd/service_generator.rs: +120 líneas (auto-detección)
- src/api/dto.rs: +6 líneas (nuevos campos DTO)
- src/api/handlers.rs: +2 líneas (mapeo campos)
- ESTADO_PROYECTO.md: actualizado con diagnóstico del bug
- tareas.txt: plan detallado Fase 4.1
- ejemplo_registro_ideas.sh: script de prueba
2026-01-15 02:36:59 -05:00

103 lines
2.4 KiB
Rust

use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Deserialize, Serialize)]
pub struct RegisterAppRequest {
pub app_name: String,
pub script_path: String,
pub working_directory: String,
pub user: String,
#[serde(default)]
pub environment: HashMap<String, String>,
#[serde(default = "default_restart_policy")]
pub restart_policy: String,
pub app_type: String,
pub description: Option<String>,
/// Ruta personalizada del ejecutable (node, npm, python). Si es None, se auto-detecta.
#[serde(default)]
pub custom_executable: Option<String>,
/// Si true, usa 'npm start' en lugar de 'node script.js' (solo para NodeJs)
#[serde(default)]
pub use_npm_start: Option<bool>,
}
fn default_restart_policy() -> String {
"always".to_string()
}
#[derive(Debug, Serialize)]
pub struct ApiResponse<T> {
pub success: bool,
pub data: Option<T>,
pub error: Option<String>,
}
impl<T> ApiResponse<T> {
pub fn success(data: T) -> Self {
ApiResponse {
success: true,
data: Some(data),
error: None,
}
}
pub fn error(error: String) -> Self {
ApiResponse {
success: false,
data: None,
error: Some(error),
}
}
}
#[derive(Debug, Serialize)]
pub struct AppStatusResponse {
pub name: String,
pub status: String,
pub pid: Option<i32>,
pub cpu_usage: f32,
pub memory_usage: String,
pub systemd_status: String,
pub last_updated: String,
}
#[derive(Debug, Serialize)]
pub struct AppListResponse {
pub apps: Vec<String>,
pub total: usize,
}
#[derive(Debug, Serialize)]
pub struct OperationResponse {
pub app_name: String,
pub operation: String,
pub success: bool,
pub message: String,
}
#[derive(Debug, Serialize)]
pub struct DetectedProcess {
pub pid: i32,
pub name: String,
pub user: Option<String>,
pub cpu_usage: f64,
pub memory_mb: f64,
pub process_type: String,
}
#[derive(Debug, Serialize)]
pub struct ProcessScanResponse {
pub processes: Vec<DetectedProcess>,
pub total: usize,
}
#[derive(Debug, Serialize)]
pub struct HealthResponse {
pub status: String,
pub config_loaded: bool,
pub config_path: String,
pub apps_count: usize,
pub systemd_services: Vec<String>,
pub version: String,
}