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 30, 2018
1 parent 57f4d92 commit 5dd4844
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 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 @@ -112,6 +115,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 @@ -500,3 +504,16 @@ 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()))
}
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 5dd4844

Please sign in to comment.