Configurador de servidor para diferentes SOs
  • Go 58.9%
  • Shell 41.1%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Valentín Pedrosa 83128509c6
All checks were successful
build / vet & test (push) Successful in 1m45s
build / build linux/arm64 (push) Successful in 1m20s
build / build linux/amd64 (push) Successful in 1m21s
fix(packages): install dma explicitly on Ubuntu >= 26.04
logwatch hard-depends on mail-transport-agent, so --no-install-recommends
alone still pulled postfix (running, inet_interfaces=all). dma (no daemon,
no open port) is now pre-seeded and named in the install so apt picks it as
the provider. Summary reflects the strategy. Spec 002 amended.

Claude-Session: https://claude.ai/code/session_01TA9mRRuGALMCVVKQnEBDpK
2026-08-28 10:26:54 +02:00
.claude/skills docs(specs): add Spec Kit constitution and specs for Go CLI migration 2026-08-28 06:59:36 +02:00
.github/workflows ci: use upload-artifact@v3, v4 rejects Forgejo (GHES check) 2026-08-28 10:25:31 +02:00
.specify docs(specs): add Spec Kit constitution and specs for Go CLI migration 2026-08-28 06:59:36 +02:00
cmd feat(cli): migrate setup.sh to Go (cobra + air) with full test coverage 2026-08-28 06:59:36 +02:00
internal fix(packages): install dma explicitly on Ubuntu >= 26.04 2026-08-28 10:26:54 +02:00
specs fix(packages): install dma explicitly on Ubuntu >= 26.04 2026-08-28 10:26:54 +02:00
.air.toml feat(cli): migrate setup.sh to Go (cobra + air) with full test coverage 2026-08-28 06:59:36 +02:00
.gitignore feat(cli): tee all terminal output to out.log next to the binary 2026-08-28 07:03:43 +02:00
go.mod feat(cli): migrate setup.sh to Go (cobra + air) with full test coverage 2026-08-28 06:59:36 +02:00
go.sum feat(cli): migrate setup.sh to Go (cobra + air) with full test coverage 2026-08-28 06:59:36 +02:00
main.go feat(cli): tee all terminal output to out.log next to the binary 2026-08-28 07:03:43 +02:00
main_test.go feat(cli): tee all terminal output to out.log next to the binary 2026-08-28 07:03:43 +02:00
README.md fix(packages): install dma explicitly on Ubuntu >= 26.04 2026-08-28 10:26:54 +02:00
setup.sh docs(specs): add Spec Kit constitution and specs for Go CLI migration 2026-08-28 06:59:36 +02:00

server-configurator

Herramienta DevOps (Go + cobra) que configura un servidor Contabo / Ubuntu 24.0426.04 para usarlo desde Coolify. Sustituye a setup.sh (v0.3.3), que se conserva en el repo como referencia hasta validar el binario en un servidor real.

Uso

# En el servidor, como root
./server-configurator setup --yes        # sin preguntas, reinicia al terminar
./server-configurator setup              # pregunta antes de tocar UFW y antes de reiniciar
./server-configurator setup --dry-run    # muestra comandos y ficheros, no ejecuta nada (no requiere root)
./server-configurator version

Pasos aplicados, en orden: zona horaria Europe/Madrid → alias update → actualización del sistema → UFW (22/80/443) → hardening sshd_config (con backup) → fail2ban (whitelist Coolify, baneos progresivos) → swap 8 GB + swappiness → paquetes de seguridad sin MTA → auditd → unattended-upgrades (01:30 / 02:00) → sysctl → limits → clave SSH de Coolify → logwatch → desactivación de servicios innecesarios → resumen → reinicio.

Es idempotente: puede ejecutarse varias veces.

Toda la salida de la terminal se guarda además en out.log, en la misma carpeta que el binario (se añade al final en cada ejecución, con una cabecera con fecha y argumentos).

Ubuntu 26.04 y la instalación no interactiva

En 26.04 el truco apt-mark hold postfix exim4 dma dejaba de funcionar: el resolutor de apt escogía otro proveedor de mail-transport-agent (courier-mta), cuyo debconf del certificado X.509 volvía interactiva la ejecución. La herramienta lee /etc/os-release y:

  • Ubuntu < 26.04 (24.04): mantiene la estrategia original de setup.sh (debconf-set-selections + apt-mark hold → instalar → apt-mark unhold), que ahí funciona.
  • Ubuntu ≥ 26.04 (o SO no detectado): logwatch tiene una dependencia dura de mail-transport-agent, así que un MTA es inevitable. Se instala explícitamente el mínimo, dma (sin demonio, sin puerto abierto, debconf preseedeado), junto con apt-listchanges y logwatch con --no-install-recommends. Así apt no elige postfix ni courier-mta.
  • En todos los casos, cada subproceso se ejecuta con DEBIAN_FRONTEND=noninteractive, NEEDRESTART_MODE=a y NEEDRESTART_SUSPEND=1 (internal/sys.NonInteractiveEnv).

Ver specs/002-noninteractive-apt/.

Desarrollo

go build -o server-configurator .
go test ./...                  # todo el código tiene tests (FS en memoria + runner falso)
air                            # live reload: recompila y ejecuta `setup --dry-run --yes`

Estructura:

main.go              entrada
cmd/                 comandos cobra (setup, version)
internal/sys/        Context, Runner (real / dry-run / fake), Summary, helpers de ficheros
internal/steps/      un fichero por paso + tests
internal/setup/      orden de pasos, comprobación de root, informe, reinicio
specs/               especificaciones Spec Kit (001 migración, 002 apt no interactivo)
.specify/            constitución y plantillas de Spec Kit

CI (GitHub Actions / Forgejo Actions)

.github/workflows/build.yml ejecuta gofmt/go vet/go test y construye binarios estáticos server-configurator-linux-{amd64,arm64} (con .sha256) como artefactos en cada push a main/dev, en tags v*, en PRs y manualmente. Corre en el runner con etiqueta go (imagen con el toolchain de Go ya instalado, sin setup-go) y solo usa actions/checkout, actions/cache (módulos y caché de build) y actions/upload-artifact, que Forgejo (≥ 7) resuelve desde github.com.

Este proyecto sigue Spec Kit: spec.mdplan.mdtasks.md → implementación. Commits con Conventional Commits.

Licencia

Copyright 20252026 Beebit Solutions SLU.