fix: bypass setup.sh, register node directly + pick-module
This commit is contained in:
parent
57e0c8798a
commit
cbe6d51ac6
1 changed files with 18 additions and 41 deletions
|
|
@ -78,31 +78,23 @@ func InstallNode(node state.Node, apiToken, apiHost, labels string) error {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// 6. Run setup.sh (remove set -e to survive env.list deletion)
|
// 6. Load Wallarm NGINX module + register node
|
||||||
fmt.Printf("[%s] Running setup...\n", node.Name)
|
fmt.Printf("[%s] Configuring NGINX module...\n", node.Name)
|
||||||
// Patch out set -e so the script doesn't exit on env.list error
|
exec.Command("bash", filepath.Join(DeployTo, "pick-module.sh")).Run()
|
||||||
exec.Command("sed", "-i", "s/^set -e/set +e/", filepath.Join(DeployTo, "setup.sh")).Run()
|
|
||||||
cmd = exec.Command("bash", filepath.Join(DeployTo, "setup.sh"),
|
fmt.Printf("[%s] Registering node...\n", node.Name)
|
||||||
"--batch", "--token", apiToken, "--cloud", cloudFromHost(apiHost),
|
registerCmd := exec.Command(filepath.Join(DeployTo, "register-node"),
|
||||||
"--custom-ngx-build",
|
"-token", apiToken,
|
||||||
|
"-host", apiHost,
|
||||||
)
|
)
|
||||||
cmd.Dir = DeployTo
|
registerCmd.Dir = DeployTo
|
||||||
|
|
||||||
logFile, _ := os.Create(filepath.Join(DeployTo, "install.log"))
|
out, regErr := registerCmd.CombinedOutput()
|
||||||
if logFile != nil {
|
if regErr != nil {
|
||||||
cmd.Stdout = logFile
|
return fmt.Errorf("register: %w\n%s", regErr, string(out))
|
||||||
cmd.Stderr = logFile
|
|
||||||
}
|
|
||||||
runErr := cmd.Run()
|
|
||||||
close(done) // stop env.list keeper
|
|
||||||
if logFile != nil {
|
|
||||||
logFile.Close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Success check: node.yaml exists = node registered
|
// 7. Move /opt/wallarm → /opt/fw/{name}/wallarm
|
||||||
nodeYaml := filepath.Join(DeployTo, "etc", "wallarm", "node.yaml")
|
|
||||||
if _, err := os.Stat(nodeYaml); err == nil {
|
|
||||||
// Move /opt/wallarm → /opt/fw/{name}/wallarm
|
|
||||||
os.MkdirAll(filepath.Join(BaseDir, node.Name), 0755)
|
os.MkdirAll(filepath.Join(BaseDir, node.Name), 0755)
|
||||||
os.RemoveAll(instanceDir)
|
os.RemoveAll(instanceDir)
|
||||||
os.Rename(DeployTo, instanceDir)
|
os.Rename(DeployTo, instanceDir)
|
||||||
|
|
@ -110,21 +102,6 @@ func InstallNode(node state.Node, apiToken, apiHost, labels string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Failed: show log
|
|
||||||
if runErr != nil {
|
|
||||||
if data, _ := os.ReadFile(filepath.Join(DeployTo, "install.log")); len(data) > 0 {
|
|
||||||
lines := strings.Split(string(data), "\n")
|
|
||||||
s := len(lines) - 5
|
|
||||||
if s < 0 {
|
|
||||||
s = 0
|
|
||||||
}
|
|
||||||
return fmt.Errorf("%s", strings.Join(lines[s:], "\n"))
|
|
||||||
}
|
|
||||||
return fmt.Errorf("setup failed: %v", runErr)
|
|
||||||
}
|
|
||||||
return fmt.Errorf("node registration failed — no node.yaml found")
|
|
||||||
}
|
|
||||||
|
|
||||||
func copyNginx(dir string) {
|
func copyNginx(dir string) {
|
||||||
dst := filepath.Join(dir, "nginx", "sbin", "nginx")
|
dst := filepath.Join(dir, "nginx", "sbin", "nginx")
|
||||||
if _, err := os.Stat(dst); err == nil {
|
if _, err := os.Stat(dst); err == nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue