--- name: install_systemd_service kind: pipeline lang: bash domain: pipelines version: "1.0.0" purity: impure signature: "install_systemd_service --name --exec [opts] -> json" description: "Pipeline que registra una app como servicio systemd del sistema: genera el unit, lo instala en /etc/systemd/system/, hace daemon-reload, enable, start y devuelve status. Requiere sudo sin password para systemctl y escritura en /etc/systemd/system/." tags: [systemd, service, local, infra, pipeline, install, pendiente-usar] uses_functions: - systemd_local_install_unit_bash_infra - systemd_local_enable_bash_infra - systemd_local_start_bash_infra - systemd_local_status_bash_infra uses_types: [] returns: [] returns_optional: false error_type: "error_go_core" imports: [] params: - name: --name desc: "nombre del servicio (sin sufijo .service)" - name: --exec desc: "ruta absoluta al binario/script para ExecStart=" - name: --workdir desc: "WorkingDirectory (default: dirname del --exec)" - name: --user desc: "User del servicio (default: usuario actual, id -un)" - name: --description desc: "Description del unit (default: ' service')" - name: --env desc: "Variable de entorno en formato KEY=VAL (repetible)" - name: --after desc: "After= del unit (default: network.target)" - name: --restart desc: "Restart= del unit (default: on-failure)" - name: --type desc: "Type= del unit (default: simple)" output: "JSON consolidado con subkeys install, enable, start y status de cada paso del pipeline." tested: false tests: [] test_file_path: "" file_path: "bash/functions/pipelines/install_systemd_service.sh" --- ## Ejemplo ```bash source bash/functions/pipelines/install_systemd_service.sh install_systemd_service \ --name sqlite_api \ --exec /home/egutierrez/fn_registry/projects/fn_monitoring/apps/sqlite_api/sqlite_api \ --workdir /home/egutierrez/fn_registry/projects/fn_monitoring/apps/sqlite_api \ --env FN_REGISTRY_ROOT=/home/egutierrez/fn_registry \ --description "fn_registry sqlite_api (read-only HTTP API)" ``` Salida (resumida): ```json { "install": {"name":"sqlite_api","path":"/etc/systemd/system/sqlite_api.service","installed":true}, "enable": {"name":"sqlite_api","enabled":true}, "start": {"name":"sqlite_api","started":true,"pid":12345}, "status": {"name":"sqlite_api","active":"active","sub":"running","enabled":"enabled","pid":12345,"logs":["..."]} } ``` ## Requisitos - `systemd` activo en la máquina (en WSL: `systemd=true` en `/etc/wsl.conf`). - `sudo` sin password para `systemctl` y escritura en `/etc/systemd/system/`. ## Notas - Idempotente: si el unit ya existe, se sobrescribe y systemd se recarga. - Para desinstalar usar `systemd_local_uninstall `. - Orden determinista de Environment= (uno por línea, en el orden pasado en CLI). - El pipeline NO compila el binario — se asume que `--exec` apunta a un ejecutable ya listo.