feat(bash/infra): servicios systemd locales — 6 funciones atómicas + 1 pipeline
Nuevas primitivas para gestionar servicios systemd del sistema desde
el registry (antes solo había versiones remotas via SSH para deploy VPS):
bash/functions/infra/
systemd_local_install_unit — escribir unit en /etc/systemd/system + daemon-reload
systemd_local_enable — systemctl enable
systemd_local_start — systemctl start + MainPID
systemd_local_restart — systemctl restart + MainPID
systemd_local_status — ActiveState/SubState/pid/enabled + journal tail (no sudo)
systemd_local_uninstall — stop + disable + rm unit + daemon-reload (idempotente)
bash/functions/pipelines/
install_systemd_service — pipeline que compone las anteriores; args
--name --exec [--workdir --user --env KEY=VAL
--after --restart --type]
Requisito: sudo sin password para systemctl + escritura en /etc/systemd/system/.
En WSL: systemd=true en /etc/wsl.conf.
Registrado sqlite_api como servicio del sistema con este pipeline, queda
vivo al arrancar WSL. Dashboard ya no necesita arrancar la API manualmente.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
---
|
||||
name: install_systemd_service
|
||||
kind: pipeline
|
||||
lang: bash
|
||||
domain: pipelines
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "install_systemd_service --name <N> --exec <PATH> [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]
|
||||
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: '<name> 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 <name>`.
|
||||
- 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.
|
||||
Reference in New Issue
Block a user