fix: check node.yaml for success, ignore env.list exit code
This commit is contained in:
parent
8484ca46a7
commit
f7689b4d6a
1 changed files with 19 additions and 15 deletions
|
|
@ -78,12 +78,12 @@ func InstallNode(node state.Node, apiToken, apiHost, labels string) error {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// 6. Run setup.sh
|
// 6. Run setup.sh (ignore env.list error, check for real success)
|
||||||
fmt.Printf("[%s] Running setup...\n", node.Name)
|
fmt.Printf("[%s] Running setup...\n", node.Name)
|
||||||
cmd = exec.Command("bash", filepath.Join(DeployTo, "setup.sh"),
|
// Use +e to prevent premature exit on env.list sed failure
|
||||||
"--batch", "--token", apiToken, "--cloud", cloudFromHost(apiHost),
|
cmd = exec.Command("bash", "-c",
|
||||||
"--custom-ngx-build",
|
fmt.Sprintf("set +e; bash %s/setup.sh --batch --token %s --cloud %s --custom-ngx-build",
|
||||||
)
|
DeployTo, apiToken, cloudFromHost(apiHost)))
|
||||||
cmd.Dir = DeployTo
|
cmd.Dir = DeployTo
|
||||||
|
|
||||||
logFile, _ := os.Create(filepath.Join(DeployTo, "install.log"))
|
logFile, _ := os.Create(filepath.Join(DeployTo, "install.log"))
|
||||||
|
|
@ -96,6 +96,19 @@ func InstallNode(node state.Node, apiToken, apiHost, labels string) error {
|
||||||
if logFile != nil {
|
if logFile != nil {
|
||||||
logFile.Close()
|
logFile.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Success check: node.yaml exists = node registered
|
||||||
|
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.RemoveAll(instanceDir)
|
||||||
|
os.Rename(DeployTo, instanceDir)
|
||||||
|
fmt.Printf("[%s] Done. Installed to %s\n", node.Name, instanceDir)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Failed: show log
|
||||||
if runErr != nil {
|
if runErr != nil {
|
||||||
if data, _ := os.ReadFile(filepath.Join(DeployTo, "install.log")); len(data) > 0 {
|
if data, _ := os.ReadFile(filepath.Join(DeployTo, "install.log")); len(data) > 0 {
|
||||||
lines := strings.Split(string(data), "\n")
|
lines := strings.Split(string(data), "\n")
|
||||||
|
|
@ -107,16 +120,7 @@ func InstallNode(node state.Node, apiToken, apiHost, labels string) error {
|
||||||
}
|
}
|
||||||
return fmt.Errorf("setup failed: %v", runErr)
|
return fmt.Errorf("setup failed: %v", runErr)
|
||||||
}
|
}
|
||||||
|
return fmt.Errorf("node registration failed — no node.yaml found")
|
||||||
// 6. Move /opt/wallarm → /opt/fw/{name}/wallarm
|
|
||||||
os.MkdirAll(BaseDir+"/"+node.Name, 0755)
|
|
||||||
os.RemoveAll(instanceDir)
|
|
||||||
if err := os.Rename(DeployTo, instanceDir); err != nil {
|
|
||||||
return fmt.Errorf("move to instance dir: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("[%s] Done. Installed to %s\n", node.Name, instanceDir)
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func copyNginx(dir string) {
|
func copyNginx(dir string) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue