--- name: systemd_local_install_unit kind: function lang: bash domain: infra version: "1.0.0" purity: impure signature: "systemd_local_install_unit(name: string, unit_content: string) -> json" description: "Instala un unit file de systemd en /etc/systemd/system/.service y ejecuta daemon-reload. Requiere sudo sin password para install y systemctl. Sobrescribe si el unit ya existe." tags: [systemd, service, local, infra, wsl] uses_functions: [] uses_types: [] returns: [] returns_optional: false error_type: "error_go_core" imports: [] params: - name: name desc: "nombre del servicio sin sufijo (se añade .service automáticamente)" - name: unit_content desc: "contenido completo del archivo unit como texto (con secciones [Unit], [Service], [Install])" output: "JSON {name, path, installed:true}. Errores a stderr, exit 1." tested: false tests: [] test_file_path: "" file_path: "bash/functions/infra/systemd_local_install_unit.sh" --- ## Ejemplo ```bash source bash/functions/infra/systemd_local_install_unit.sh unit=$(cat <<'EOF' [Unit] Description=my service After=network.target [Service] Type=simple ExecStart=/usr/local/bin/my_service Restart=on-failure [Install] WantedBy=multi-user.target EOF ) systemd_local_install_unit "my_service" "$unit" # {"name":"my_service","path":"/etc/systemd/system/my_service.service","installed":true} ``` ## Notas - Usa `install -m 0644 -o root -g root` para escribir el unit con permisos correctos. - Llama a `sudo systemctl daemon-reload` al final — imprescindible para que systemd vea el unit. - No hace `enable` ni `start` — esas son funciones separadas (principio de composabilidad). - En WSL requiere `systemd=true` en `/etc/wsl.conf`.