Files
fn_registry/bash/functions/pipelines/install_systemd_service.md
T
egutierrez c7ae46f86c 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>
2026-04-24 14:02:54 +02:00

2.9 KiB

name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, params, output, tested, tests, test_file_path, file_path
name kind lang domain version purity signature description tags uses_functions uses_types returns returns_optional error_type imports params output tested tests test_file_path file_path
install_systemd_service pipeline bash pipelines 1.0.0 impure install_systemd_service --name <N> --exec <PATH> [opts] -> json 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/.
systemd
service
local
infra
pipeline
install
systemd_local_install_unit_bash_infra
systemd_local_enable_bash_infra
systemd_local_start_bash_infra
systemd_local_status_bash_infra
false error_go_core
name desc
--name nombre del servicio (sin sufijo .service)
name desc
--exec ruta absoluta al binario/script para ExecStart=
name desc
--workdir WorkingDirectory (default: dirname del --exec)
name desc
--user User del servicio (default: usuario actual, id -un)
name desc
--description Description del unit (default: '<name> service')
name desc
--env Variable de entorno en formato KEY=VAL (repetible)
name desc
--after After= del unit (default: network.target)
name desc
--restart Restart= del unit (default: on-failure)
name desc
--type Type= del unit (default: simple)
JSON consolidado con subkeys install, enable, start y status de cada paso del pipeline. false
bash/functions/pipelines/install_systemd_service.sh

Ejemplo

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):

{
  "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.