fix: handle error cases in starting a new vector container
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/codeskyblue/go-sh"
|
"github.com/codeskyblue/go-sh"
|
||||||
)
|
)
|
||||||
@@ -45,6 +46,18 @@ func ContainerExists(containerID string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ContainerWaitTilReady will wait timeout seconds and then check if a container is running
|
||||||
|
// returning an error if it is not running at the end of the timeout
|
||||||
|
func ContainerWaitTilReady(containerID string, timeout time.Duration) error {
|
||||||
|
time.Sleep(timeout)
|
||||||
|
|
||||||
|
if !ContainerIsRunning(containerID) {
|
||||||
|
return fmt.Errorf("Container %s is not running", containerID)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// CopyFromImage copies a file from named image to destination
|
// CopyFromImage copies a file from named image to destination
|
||||||
func CopyFromImage(appName string, image string, source string, destination string) error {
|
func CopyFromImage(appName string, image string, source string, destination string) error {
|
||||||
if !VerifyImage(image) {
|
if !VerifyImage(image) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/dokku/dokku/plugins/common"
|
"github.com/dokku/dokku/plugins/common"
|
||||||
)
|
)
|
||||||
@@ -108,19 +109,28 @@ func CommandVectorStart(vectorImage string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !common.ContainerExists(vectorContainerName) {
|
if common.ContainerExists(vectorContainerName) {
|
||||||
return startVectorContainer(vectorImage)
|
if common.ContainerIsRunning(vectorContainerName) {
|
||||||
|
common.LogVerbose("Vector container is running")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
common.LogVerbose("Starting vector container")
|
||||||
|
if !common.ContainerStart(vectorContainerName) {
|
||||||
|
return errors.New("Unable to start vector container")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err := startVectorContainer(vectorImage); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if common.ContainerIsRunning(vectorContainerName) {
|
common.LogVerbose("Waiting for 10 seconds")
|
||||||
common.LogVerbose("Container already running")
|
if err := common.ContainerWaitTilReady(vectorContainerName, 10*time.Second); err != nil {
|
||||||
return nil
|
return errors.New("Vector container did not start properly, run logs:vector-logs for more details")
|
||||||
}
|
|
||||||
|
|
||||||
if !common.ContainerStart(vectorContainerName) {
|
|
||||||
return errors.New("Unable to start vector container")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
common.LogVerbose("Vector container is running")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user