Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
sleep 90
- name: Verify that configuration was reloaded hitless
run: |
if [ $( kubectl logs haproxy | grep "process started with pid" | wc -l) -ne 2 ]; then
if [ $( kubectl logs haproxy | grep "process started : pid" | wc -l) -ne 2 ]; then
exit 1
fi
if [ "$(kubectl logs haproxy | grep -E -c 'process [0-9]+ terminated')" -ne 1 ]; then
Expand All @@ -93,7 +93,7 @@ jobs:
sleep 90
- name: Verify that configuration was reloaded hitless
run: |
if [ $( kubectl logs haproxy | grep "process started with pid" | wc -l) -ne 3 ]; then
if [ $( kubectl logs haproxy | grep "process started : pid" | wc -l) -ne 3 ]; then
exit 1
fi
if [ "$(kubectl logs haproxy | grep -E -c 'process [0-9]+ terminated')" -ne 2 ]; then
Expand Down
24 changes: 12 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func main() {
}

if utils.DisableReload() {
log.Notice("reload disabled, no watches added")
log.Notice("reload disabled : no watches added")
} else {
if err := fswatch.Add(watchPath); err != nil {
log.Notice(fmt.Sprintf("watch failed : %v", err))
Expand Down Expand Up @@ -88,7 +88,7 @@ func main() {
log.Alert(err.Error())
case sig := <-sigs:
// handle SIGINT, SIGTERM, SIGUSR1 and propagate it to child process
log.Notice(fmt.Sprintf("received singal %d", sig))
log.Notice(fmt.Sprintf("received singal : %d", sig))

if len(cmds) == 0 {
// received termination suddenly before child process was even started
Expand All @@ -99,21 +99,21 @@ func main() {
terminated = true

// propagate signal to child processes
l.RLock()
for i := range cmds {
if cmds[i].Process != nil {
if err := cmds[i].Process.Signal(sig); err != nil {
log.Warning(fmt.Sprintf("propagating signal %d to process %d failed", sig, cmds[i].Process.Pid))
log.Warning(fmt.Sprintf("propagating signal %d to process %d failed : %s", sig, cmds[i].Process.Pid, err.Error()))
}
}
}
l.RUnlock()
}
}
}

func runInstance() {

log.Notice("starting validation")

// validate the config by using the "-c" flag
argsValidate := append(os.Args[1:], "-c")
cmdValidate := exec.Command(executable, argsValidate...)
Expand All @@ -122,7 +122,7 @@ func runInstance() {
cmdValidate.Env = utils.LoadEnvFile()

if err := cmdValidate.Run(); err != nil {
log.Warning("validate failed: " + err.Error())
log.Warning("validate failed : " + err.Error())
// exit if the config is invalid and no other process is running
if len(cmds) == 0 {
os.Exit(1)
Expand All @@ -132,20 +132,20 @@ func runInstance() {

// launch the actual haproxy including the previous pids to terminate
args := os.Args[1:]
l.RLock()
if len(cmds) > 0 {
args = append(args, []string{"-x", utils.LookupHAProxySocketPath(), "-sf"}...)
args = append(args, pids()...)
}
l.RUnlock()

log.Notice("validate successful : starting process...")

cmd := exec.Command(executable, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Env = utils.LoadEnvFile()

if err := cmd.AsyncRun(); err != nil {
log.Warning("process starting failed: " + err.Error())
log.Warning("process starting failed : " + err.Error())
}
go func(cmd *exec.Cmd) {
<-cmd.Terminated
Expand All @@ -158,13 +158,13 @@ func runInstance() {

// remove the process from tracking
l.Lock()
defer l.Unlock()
for i := range cmds {
if cmds[i].Process.Pid == cmd.Process.Pid {
cmds = append(cmds[:i], cmds[i+1:]...)
break
}
}
l.Unlock()

// exit if there are no more processes running
if len(cmds) == 0 {
Expand All @@ -176,11 +176,11 @@ func runInstance() {
}
}(cmd)

log.Notice(fmt.Sprintf("process started with pid %d and status %s", cmd.Process.Pid, cmd.Status()))
log.Notice(fmt.Sprintf("process started : pid %d status %s", cmd.Process.Pid, cmd.Status()))

l.Lock()
defer l.Unlock()
cmds = append(cmds, cmd)
l.Unlock()
}

// pids returns the PID list
Expand Down