From bec73c00288956541293621ec1526cd4f371737d Mon Sep 17 00:00:00 2001 From: vmorganp <31448722+vmorganp@users.noreply.github.com> Date: Sat, 4 Mar 2023 17:23:16 -0700 Subject: [PATCH] fix sleep/stop method conflicts --- src/group.go | 10 +++++----- src/lazytainer.go | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/group.go b/src/group.go index 002328f..1aa4ddd 100644 --- a/src/group.go +++ b/src/group.go @@ -24,7 +24,7 @@ type LazyGroup struct { netInterface string // which network interface to watch traffic on. By default this is eth0 but can sometimes vary pollRate uint16 // how frequently to poll traffic statistics ports []uint16 // list of ports, which happens to also be a 16 bit range, how convenient! - stopMethod string // whether to stop or pause the container + sleepMethod string // whether to stop or pause the container } func (lg LazyGroup) MainLoop() { @@ -85,13 +85,13 @@ func (lg LazyGroup) stopContainers() { dockerClient, err := client.NewClientWithOpts(client.FromEnv) check(err) for _, c := range lg.getContainers() { - if lg.stopMethod == "stop" || lg.stopMethod == "" { + if lg.sleepMethod == "stop" || lg.sleepMethod == "" { if err := dockerClient.ContainerStop(context.Background(), c.ID, nil); err != nil { fmt.Printf("ERROR: Unable to stop container %s: %s\n", c.Names[0], err) } else { infoLogger.Println("stopped container ", c.Names[0]) } - } else if lg.stopMethod == "pause" { + } else if lg.sleepMethod == "pause" { if err := dockerClient.ContainerPause(context.Background(), c.ID); err != nil { fmt.Printf("ERROR: Unable to pause container %s: %s\n", c.Names[0], err) } else { @@ -106,13 +106,13 @@ func (lg LazyGroup) startContainers() { dockerClient, err := client.NewClientWithOpts(client.FromEnv) check(err) for _, c := range lg.getContainers() { - if lg.stopMethod == "stop" || lg.stopMethod == "" { + if lg.sleepMethod == "stop" || lg.sleepMethod == "" { if err := dockerClient.ContainerStart(context.Background(), c.ID, types.ContainerStartOptions{}); err != nil { fmt.Printf("ERROR: Unable to start container %s: %s\n", c.Names[0], err) } else { infoLogger.Println("started container ", c.Names[0]) } - } else if lg.stopMethod == "pause" { + } else if lg.sleepMethod == "pause" { if err := dockerClient.ContainerUnpause(context.Background(), c.ID); err != nil { fmt.Printf("ERROR: Unable to unpause container %s: %s\n", c.Names[0], err) } else { diff --git a/src/lazytainer.go b/src/lazytainer.go index 9e30da7..13b71d7 100644 --- a/src/lazytainer.go +++ b/src/lazytainer.go @@ -122,13 +122,13 @@ func configureFromLabels() map[string]LazyGroup { debugLogger.Println("Using default pollRate of 30 because " + prefix + groupName + ".pollRate was not set") } - // configure stopMethod - stopMethod := "stop" - labelValueAsString, exists = labels[prefix+groupName+".stopMethod"] + // configure sleepMethod + sleepMethod := "stop" + labelValueAsString, exists = labels[prefix+groupName+".sleepMethod"] if exists { - stopMethod = labelValueAsString + sleepMethod = labelValueAsString } else { - debugLogger.Println("Using default stopMethod of stop because " + prefix + groupName + ".stopMethod was not set") + debugLogger.Println("Using default sleepMethod of stop because " + prefix + groupName + ".sleepMethod was not set") } groups[groupName] = LazyGroup{ @@ -138,7 +138,7 @@ func configureFromLabels() map[string]LazyGroup { netInterface: netInterface, pollRate: pollRate, ports: ports, - stopMethod: stopMethod, + sleepMethod: sleepMethod, } } }