feat: start per-instance NGINX with status endpoint before setup.sh

This commit is contained in:
admin 2026-08-01 17:18:19 +00:00
parent c38535398d
commit a1d71b3eac

View file

@ -31,9 +31,41 @@ func InstallNode(node state.Node, apiToken, apiHost, labels string) error {
instanceDir := filepath.Join(BaseDir, node.Name, "wallarm") instanceDir := filepath.Join(BaseDir, node.Name, "wallarm")
installerPath := filepath.Join(BaseDir, "wallarm-aio.sh") installerPath := filepath.Join(BaseDir, "wallarm-aio.sh")
// 1. Per-instance NGINX // 1. Per-instance NGINX: copy binary, write config, start
nginxDir := filepath.Join(instanceDir, "nginx")
copyNginx(instanceDir) copyNginx(instanceDir)
// Write nginx.conf for this instance
port := "80"
if idx := strings.LastIndex(node.Address, ":"); idx != -1 {
port = node.Address[idx+1:]
}
nginxConf := filepath.Join(nginxDir, "conf", "nginx.conf")
os.MkdirAll(filepath.Dir(nginxConf), 0755)
os.WriteFile(nginxConf, []byte(fmt.Sprintf(`
worker_processes auto;
pid %s/nginx.pid;
error_log %s/error.log;
events { worker_connections 10240; }
http {
access_log %s/access.log;
server {
listen %s;
server_name _;
allow 127.0.0.0/8;
deny all;
wallarm_mode off;
access_log off;
location /wallarm-status { wallarm_status on; }
}
}
`, nginxDir, nginxDir, nginxDir, port)), 0644)
// Start NGINX for this instance
exec.Command(filepath.Join(nginxDir, "sbin", "nginx"),
"-c", nginxConf, "-p", nginxDir).Run()
fmt.Printf("[%s] NGINX started on port %s\n", node.Name, port)
// 2. Download AIO once // 2. Download AIO once
if _, err := os.Stat(installerPath); os.IsNotExist(err) { if _, err := os.Stat(installerPath); os.IsNotExist(err) {
fmt.Printf("[%s] Downloading installer...\n", node.Name) fmt.Printf("[%s] Downloading installer...\n", node.Name)