fix: kill existing process on target port before starting nginx
This commit is contained in:
parent
4432855a2d
commit
bc66018af3
1 changed files with 16 additions and 7 deletions
|
|
@ -35,9 +35,14 @@ func InstallNode(node state.Node, apiToken, apiHost, labels string) error {
|
|||
os.RemoveAll(DeployTo)
|
||||
os.MkdirAll(DeployTo, 0755)
|
||||
|
||||
// 2. Per-instance NGINX into /opt/wallarm
|
||||
// 2. Kill any existing process on the target port, then start per-instance NGINX
|
||||
port := "80"
|
||||
if idx := strings.LastIndex(node.Address, ":"); idx != -1 {
|
||||
port = node.Address[idx+1:]
|
||||
}
|
||||
killPort(port)
|
||||
copyNginx(DeployTo)
|
||||
startNginx(DeployTo, node)
|
||||
startNginx(DeployTo, node, port)
|
||||
|
||||
// 3. Download AIO once
|
||||
if _, err := os.Stat(installerPath); os.IsNotExist(err) {
|
||||
|
|
@ -140,12 +145,8 @@ func GenerateSystemdTemplate() error { return nil }
|
|||
func RemoveNode(name string) error { return nil }
|
||||
func Status(name string) (string, error) { return "", nil }
|
||||
|
||||
func startNginx(dir string, node state.Node) {
|
||||
func startNginx(dir string, node state.Node, port string) {
|
||||
nginxDir := filepath.Join(dir, "nginx")
|
||||
port := "80"
|
||||
if idx := strings.LastIndex(node.Address, ":"); idx != -1 {
|
||||
port = node.Address[idx+1:]
|
||||
}
|
||||
confDir := filepath.Join(nginxDir, "conf")
|
||||
os.MkdirAll(confDir, 0755)
|
||||
confPath := filepath.Join(confDir, "nginx.conf")
|
||||
|
|
@ -173,3 +174,11 @@ http {
|
|||
fmt.Printf("[%s] NGINX started on port %s\n", node.Name, port)
|
||||
}
|
||||
}
|
||||
|
||||
func killPort(port string) {
|
||||
// Find and kill any process listening on the target port
|
||||
out, _ := exec.Command("fuser", "-k", port+"/tcp").CombinedOutput()
|
||||
if len(out) > 0 {
|
||||
fmt.Printf(" Killed existing process on port %s\n", port)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue