feat: funciones Go de deploy — systemd, VPS setup, deploy remoto
Nuevas funciones infra para deploy sin Docker: generación de units systemd (pura), instalación/restart/status de servicios remotos via SSH, setup inicial de VPS (crear dirs, usuario, permisos), y pipelines de deploy completo (setup_vps_app, deploy_app_remote). Incluye tipo DeployConfig con la configuración de deploy por app.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package infra
|
||||
|
||||
import "fmt"
|
||||
|
||||
// SystemdInstall sube un unit file al host remoto, hace daemon-reload, enable y restart.
|
||||
// Idempotente: si el unit ya existe, lo reemplaza.
|
||||
func SystemdInstall(conn SSHConn, unitName, unitContent string) error {
|
||||
// Escribir a archivo temporal y mover a /etc/systemd/system/
|
||||
tmpPath := fmt.Sprintf("/tmp/%s.service", unitName)
|
||||
destPath := fmt.Sprintf("/etc/systemd/system/%s.service", unitName)
|
||||
|
||||
writeCmd := fmt.Sprintf("cat > %s << 'UNIT_EOF'\n%sUNIT_EOF", tmpPath, unitContent)
|
||||
_, stderr, code, err := SSHExec(conn, writeCmd)
|
||||
if err != nil {
|
||||
return fmt.Errorf("systemd_install: ssh write: %w", err)
|
||||
}
|
||||
if code != 0 {
|
||||
return fmt.Errorf("systemd_install: write unit file: %s", stderr)
|
||||
}
|
||||
|
||||
// Mover a systemd y aplicar
|
||||
cmds := fmt.Sprintf("sudo mv %s %s && sudo systemctl daemon-reload && sudo systemctl enable %s && sudo systemctl restart %s",
|
||||
tmpPath, destPath, unitName, unitName)
|
||||
|
||||
_, stderr, code, err = SSHExec(conn, cmds)
|
||||
if err != nil {
|
||||
return fmt.Errorf("systemd_install: ssh exec: %w", err)
|
||||
}
|
||||
if code != 0 {
|
||||
return fmt.Errorf("systemd_install: %s", stderr)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user