Files
fn_registry/bash/functions/infra/systemd_local_install_unit.sh
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

33 lines
939 B
Bash

#!/usr/bin/env bash
# systemd_local_install_unit — Instala un unit file en /etc/systemd/system y recarga systemd.
set -euo pipefail
systemd_local_install_unit() {
local name="$1"
local unit_content="$2"
if [[ -z "$name" || -z "$unit_content" ]]; then
echo "systemd_local_install_unit: se requieren name y unit_content" >&2
return 1
fi
local unit_path="/etc/systemd/system/${name}.service"
local tmp
tmp="$(mktemp)"
printf '%s' "$unit_content" > "$tmp"
if ! sudo install -m 0644 -o root -g root "$tmp" "$unit_path"; then
rm -f "$tmp"
echo "systemd_local_install_unit: no se pudo instalar '$unit_path'" >&2
return 1
fi
rm -f "$tmp"
if ! sudo systemctl daemon-reload; then
echo "systemd_local_install_unit: daemon-reload falló" >&2
return 1
fi
printf '{"name":"%s","path":"%s","installed":true}\n' "$name" "$unit_path"
}