Skip to content

Commit

Permalink
fix sleep/stop method conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
vmorganp committed Mar 5, 2023
1 parent 7640eb1 commit bec73c0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions src/lazytainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -138,7 +138,7 @@ func configureFromLabels() map[string]LazyGroup {
netInterface: netInterface,
pollRate: pollRate,
ports: ports,
stopMethod: stopMethod,
sleepMethod: sleepMethod,
}
}
}
Expand Down

0 comments on commit bec73c0

Please sign in to comment.