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: 4 additions & 0 deletions haproxy/haproxy_cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ func runCommand(sd *lib.Shutdown, cmdPath string, args ...string) (*exec.Cmd, er
sd.Done()
return nil, errors.Wrapf(err, "error starting %s", file)
}
if cmd.Process == nil {
sd.Done()
return nil, errors.Wrapf(err, "Process '%s' could not be started", file)
}
exited := uint32(0)
go func() {
defer sd.Done()
Expand Down
25 changes: 25 additions & 0 deletions haproxy/haproxy_cmd/cmd_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package haproxy_cmd

import (
"testing"

"github.com/criteo/haproxy-consul-connect/lib"
"github.com/stretchr/testify/assert"
)

func Test_runCommand_ok(t *testing.T) {
t.Parallel()
sd := lib.NewShutdown()
cmd, err := runCommand(sd, "ls", ".")
assert.NoError(t, err)
cmd.Wait()
}

func Test_runCommand_nok_wrong_path(t *testing.T) {
t.Parallel()
sd := lib.NewShutdown()
cmd, err := runCommand(sd, "/path/to/nowhere/that/can/be/found/myExec", "--help")
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "no such file or directory")
assert.Nil(t, cmd)
}
14 changes: 13 additions & 1 deletion haproxy/haproxy_cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net"
"net/http"
"os"
"time"

"github.com/criteo/haproxy-consul-connect/haproxy/dataplane"
Expand All @@ -29,8 +30,11 @@ func Start(sd *lib.Shutdown, cfg Config) (*dataplane.Dataplane, error) {
if err != nil {
return nil, err
}
if haCmd.Process == nil {
return nil, fmt.Errorf("%s was not started", cfg.HAProxyPath)
}

_, err = runCommand(sd,
cmd, err := runCommand(sd,
cfg.DataplanePath,
"--scheme", "unix",
"--socket-path", cfg.DataplaneSock,
Expand All @@ -41,9 +45,17 @@ func Start(sd *lib.Shutdown, cfg Config) (*dataplane.Dataplane, error) {
"--userlist", "controller",
"--transaction-dir", cfg.DataplaneTransactionDir,
)
cleanupHAProxy := func() {
haCmd.Process.Signal(os.Kill)
}
if err != nil {
cleanupHAProxy()
return nil, err
}
if cmd.Process == nil {
cleanupHAProxy()
return nil, fmt.Errorf("%s failed to start", cfg.DataplanePath)
}

dataplaneClient := dataplane.New(
"http://unix-sock",
Expand Down