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
This commit is contained in:
@@ -13,6 +13,12 @@ pub struct RegisterAppRequest {
|
||||
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 {
|
||||
@@ -84,3 +90,13 @@ 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,
|
||||
}
|
||||
|
||||
@@ -45,6 +45,8 @@ pub async fn register_app_handler(
|
||||
restart_policy,
|
||||
app_type,
|
||||
description: payload.description,
|
||||
custom_executable: payload.custom_executable,
|
||||
use_npm_start: payload.use_npm_start,
|
||||
};
|
||||
|
||||
match state.app_manager.register_app(config) {
|
||||
@@ -193,3 +195,30 @@ pub async fn scan_processes_handler() -> Result<Json<ApiResponse<ProcessScanResp
|
||||
total,
|
||||
})))
|
||||
}
|
||||
|
||||
pub async fn health_handler(
|
||||
State(state): State<Arc<ApiState>>,
|
||||
) -> Result<Json<ApiResponse<HealthResponse>>, StatusCode> {
|
||||
use std::path::Path;
|
||||
|
||||
let config_path = "config/monitored_apps.json";
|
||||
let config_exists = Path::new(config_path).exists();
|
||||
|
||||
let apps = state.app_manager.list_apps();
|
||||
let apps_count = apps.len();
|
||||
|
||||
let mut systemd_services = Vec::new();
|
||||
for app_name in &apps {
|
||||
let service_name = format!("siax-app-{}.service", app_name);
|
||||
systemd_services.push(service_name);
|
||||
}
|
||||
|
||||
Ok(Json(ApiResponse::success(HealthResponse {
|
||||
status: "ok".to_string(),
|
||||
config_loaded: config_exists,
|
||||
config_path: config_path.to_string(),
|
||||
apps_count,
|
||||
systemd_services,
|
||||
version: env!("CARGO_PKG_VERSION").to_string(),
|
||||
})))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user