fix: keep env.list alive with background goroutine during setup.sh

This commit is contained in:
admin 2026-08-01 18:37:17 +00:00
parent 0922102226
commit 8484ca46a7

View file

@ -6,6 +6,7 @@ import (
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strings" "strings"
"time"
"git.sechpoint.app/customer-engineering/wallarm/internal/state" "git.sechpoint.app/customer-engineering/wallarm/internal/state"
) )
@ -61,15 +62,25 @@ func InstallNode(node state.Node, apiToken, apiHost, labels string) error {
return fmt.Errorf("extract: %w\n%s", err, string(out)) return fmt.Errorf("extract: %w\n%s", err, string(out))
} }
// 5. Patch setup.sh: make env.list sed commands non-fatal (file gets deleted during nginx test) // 5. Fix: recreate env.list in background while setup.sh runs
setupPath := filepath.Join(DeployTo, "setup.sh") done := make(chan struct{})
exec.Command("sed", "-i", go func() {
`s|\(/opt/wallarm/env.list\)|\1 2>/dev/null || true|g`, defer close(done)
setupPath).Run() for {
select {
case <-done:
return
default:
os.WriteFile(filepath.Join(DeployTo, "env.list"),
[]byte("# wallarm env\n"), 0644)
time.Sleep(500 * time.Millisecond)
}
}
}()
// 6. Run setup.sh // 6. Run setup.sh
fmt.Printf("[%s] Running setup...\n", node.Name) fmt.Printf("[%s] Running setup...\n", node.Name)
cmd = exec.Command("bash", setupPath, cmd = exec.Command("bash", filepath.Join(DeployTo, "setup.sh"),
"--batch", "--token", apiToken, "--cloud", cloudFromHost(apiHost), "--batch", "--token", apiToken, "--cloud", cloudFromHost(apiHost),
"--custom-ngx-build", "--custom-ngx-build",
) )
@ -81,6 +92,7 @@ func InstallNode(node state.Node, apiToken, apiHost, labels string) error {
cmd.Stderr = logFile cmd.Stderr = logFile
} }
runErr := cmd.Run() runErr := cmd.Run()
close(done) // stop env.list keeper
if logFile != nil { if logFile != nil {
logFile.Close() logFile.Close()
} }