Skip to content

Commit

Permalink
make sure the minikube is not running
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravindra Ratnawat committed Nov 2, 2018
1 parent 8256665 commit be3ffbc
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ import (
"time"

"github.com/blang/semver"
"github.com/docker/machine/libmachine"
"github.com/docker/machine/libmachine/drivers"
"github.com/docker/machine/libmachine/host"
"github.com/docker/machine/libmachine/state"
"github.com/golang/glog"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -111,6 +114,7 @@ func runStart(cmd *cobra.Command, args []string) {
}

api, err := machine.NewAPIClient()
ensureNotRunning(api, constants.DefaultMachineName)
if err != nil {
fmt.Fprintf(os.Stderr, "Error getting client: %v\n", err)
os.Exit(1)
Expand Down Expand Up @@ -463,3 +467,17 @@ func saveConfigToFile(data []byte, file string) error {
}
return nil
}

func ensureNotRunning(client libmachine.API, machineName string) {

hostVm, err := client.Load(machineName)

if err != nil {
fmt.Fprintln(os.Stderr, fmt.Sprintf(err.Error()))
os.Exit(1)
}
if drivers.MachineInState(hostVm.Driver, state.Running)() && hostVm.DriverName != "generic" {
fmt.Fprintln(os.Stdout, fmt.Sprintf("The '%s' VM is already running.", machineName))
os.Exit(0)
}
}

0 comments on commit be3ffbc

Please sign in to comment.