From 2c8eb5bba3ad49cd97e983a84de5a5701ce7e743 Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Thu, 3 Feb 2022 09:59:30 +1000 Subject: [PATCH 1/2] fix: make the run log file unique so that it does not get overwritten --- pkg/containerengine/docker.go | 4 ++-- pkg/containerengine/podman.go | 4 ++-- pkg/utils/paths.go | 10 ++++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/pkg/containerengine/docker.go b/pkg/containerengine/docker.go index 79d9ad579..17c2fe413 100644 --- a/pkg/containerengine/docker.go +++ b/pkg/containerengine/docker.go @@ -24,7 +24,6 @@ import ( "io" "log" "os/exec" - "path" "strings" "time" @@ -291,6 +290,7 @@ func (d *docker) Logger(stackPath string) ContainerLogger { if d.logger != nil { return d.logger } - d.logger = newSyslog(path.Join(utils.NitricLogDir(stackPath), "run.log")) + logPath, _ := utils.NewNitricLogFile(stackPath) + d.logger = newSyslog(logPath) return d.logger } diff --git a/pkg/containerengine/podman.go b/pkg/containerengine/podman.go index 46d19a8d3..ea3043b0f 100644 --- a/pkg/containerengine/podman.go +++ b/pkg/containerengine/podman.go @@ -22,7 +22,6 @@ import ( "fmt" "io" "os/exec" - "path" "strings" "time" @@ -131,7 +130,8 @@ func (p *podman) ContainerExec(containerName string, cmd []string, workingDir st } func (p *podman) Logger(stackPath string) ContainerLogger { - return &jsonfile{logPath: path.Join(utils.NitricLogDir(stackPath), "run.log")} + logPath, _ := utils.NewNitricLogFile(stackPath) + return &jsonfile{logPath: logPath} } type jsonfile struct { diff --git a/pkg/utils/paths.go b/pkg/utils/paths.go index 8e6ec0635..9a0946c55 100644 --- a/pkg/utils/paths.go +++ b/pkg/utils/paths.go @@ -86,3 +86,13 @@ func NitricConfigDir() string { func NitricLogDir(stackPath string) string { return path.Join(stackPath, ".nitric") } + +// NewNitricLogFile returns a path to a unique log file that does not exist. +func NewNitricLogFile(stackPath string) (string, error) { + tf, err := os.CreateTemp(NitricLogDir(stackPath), "run-*.log") + if err != nil { + return "", err + } + tf.Close() + return tf.Name(), nil +} From 81808b9f149d6c4d68c742adf3544a5097ff9c43 Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Thu, 3 Feb 2022 10:00:10 +1000 Subject: [PATCH 2/2] fix: Add a timeout to the minio.Stop() so that it gets killed --- pkg/run/minio.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/run/minio.go b/pkg/run/minio.go index 8b53acb35..3bd538a6b 100644 --- a/pkg/run/minio.go +++ b/pkg/run/minio.go @@ -19,6 +19,7 @@ import ( "fmt" "os" "path/filepath" + "time" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/mount" @@ -126,7 +127,8 @@ func (m *MinioServer) GetApiPort() int { } func (m *MinioServer) Stop() error { - return m.ce.Stop(m.cid, nil) + timeout := time.Second * 5 + return m.ce.Stop(m.cid, &timeout) } func NewMinio(dir string, name string) (*MinioServer, error) {