Skip to content

Commit

Permalink
Forcing the containe to stop during a rebind
Browse files Browse the repository at this point in the history
FlUxIuS committed Dec 4, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 030d8d5 commit 41dc4ee
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions go/rfswift/dock/rfdock.go
Original file line number Diff line number Diff line change
@@ -1600,18 +1600,36 @@ func UpdateMountBinding(containerName string, source string, target string, add
// Stop the container
cli, err := client.NewClientWithOpts(client.FromEnv)
if err != nil {
common.PrintErrorMessage(fmt.Errorf("Error when instanciating a client"))
common.PrintErrorMessage(fmt.Errorf("Error when instantiating a client"))
os.Exit(1)
}
common.PrintInfoMessage("Stopping the container...")

// Attempt graceful stop
err = cli.ContainerStop(ctx, containerID, container.StopOptions{Timeout: &timeout})
if err != nil {
common.PrintErrorMessage(fmt.Errorf("Failed to stop the container"))
os.Exit(1)
}
common.PrintSuccessMessage(fmt.Sprintf("Container '%s' stopped", containerID))
if err != nil {
common.PrintErrorMessage(fmt.Errorf("Failed to stop the container gracefully: %v", err))
}

// Check if the container is still running
containerJSON, err := cli.ContainerInspect(ctx, containerID)
if err != nil {
common.PrintErrorMessage(fmt.Errorf("Error inspecting container: %v", err))
os.Exit(1)
}
if containerJSON.State.Running {
common.PrintWarningMessage("Container is still running. Forcing stop...")
err = cli.ContainerKill(ctx, containerID, "SIGKILL")
if err != nil {
common.PrintErrorMessage(fmt.Errorf("Failed to force stop the container: %v", err))
os.Exit(1)
}
common.PrintSuccessMessage("Container forcibly stopped.")
} else {
common.PrintSuccessMessage(fmt.Sprintf("Container '%s' stopped", containerID))
}

// The rest of your function logic continues here
common.PrintInfoMessage("Determining hostconfig.json path...")
configPath, err := GetHostConfigPath(containerID)
if err != nil {

0 comments on commit 41dc4ee

Please sign in to comment.