Skip to content

Commit

Permalink
Don't halt project dev command if the sandbox is already running #471
Browse files Browse the repository at this point in the history
 - don't stop sandbox on quit unless we started it
  • Loading branch information
pmi authored and alansemenov committed Oct 2, 2023
1 parent 5afce11 commit 1603be8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions internal/app/commands/project/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func askToRunSandbox(c *cli.Context, projectData *common.ProjectData) {
if !processRunning {
if force || util.PromptBool(fmt.Sprintf("Do you want to start sandbox '%s'", projectData.Sandbox), true) {
// detach in continuous mode to release terminal window
err := sandbox.StartSandbox(c, sandboxData, continuous, devMode, debug, common.HTTP_PORT)
err, _ := sandbox.StartSandbox(c, sandboxData, continuous, devMode, debug, common.HTTP_PORT)
util.Fatal(err, "")
}

Expand All @@ -94,7 +94,7 @@ func askToRunSandbox(c *cli.Context, projectData *common.ProjectData) {
if force || util.PromptBool(fmt.Sprintf("Do you want to stop running sandbox '%s' and start '%s' instead", rData.Running, projectData.Sandbox), true) {
sandbox.StopSandbox(rData)
// detach in continuous mode to release terminal window
err := sandbox.StartSandbox(c, sandboxData, continuous, devMode, debug, common.HTTP_PORT)
err, _ := sandbox.StartSandbox(c, sandboxData, continuous, devMode, debug, common.HTTP_PORT)
util.Fatal(err, "")
}

Expand Down
7 changes: 5 additions & 2 deletions internal/app/commands/project/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func StartDevMode(c *cli.Context) {

sbox := sandbox.ReadSandboxFromProjectOrAsk(c, false)

err := sandbox.StartSandbox(c, sbox, true, true, true, common.HTTP_PORT)
err, usedExistingSandbox := sandbox.StartSandbox(c, sbox, true, true, true, common.HTTP_PORT)
if err != nil {
fmt.Fprintf(os.Stderr, "Restart sandbox '%s' in dev mode or stop it before running dev command\n", sbox.Name)
os.Exit(1)
Expand All @@ -37,7 +37,10 @@ func StartDevMode(c *cli.Context) {
fmt.Fprintln(os.Stderr)
fmt.Fprintln(os.Stderr, "Stopping project dev mode...")
fmt.Fprintln(os.Stderr)
sandbox.StopSandbox(common.ReadRuntimeData())
if !usedExistingSandbox {
// we started the sandbox, so we need to stop it too
sandbox.StopSandbox(common.ReadRuntimeData())
}
})

runGradleTask(projectData, devMessage, "dev")
Expand Down
12 changes: 6 additions & 6 deletions internal/app/commands/sandbox/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var Start = cli.Command{

sandbox := ReadSandboxFromProjectOrAsk(c, true)

err := StartSandbox(c, sandbox, c.Bool("detach"), c.Bool("dev"), c.Bool("debug"), uint16(c.Uint("http.port")))
err, _ := StartSandbox(c, sandbox, c.Bool("detach"), c.Bool("dev"), c.Bool("debug"), uint16(c.Uint("http.port")))
util.Fatal(err, "")

return nil
Expand Down Expand Up @@ -66,16 +66,16 @@ func ReadSandboxFromProjectOrAsk(c *cli.Context, useArguments bool) *Sandbox {
return sandbox
}

func StartSandbox(c *cli.Context, sandbox *Sandbox, detach, devMode, debug bool, httpPort uint16) error {
func StartSandbox(c *cli.Context, sandbox *Sandbox, detach, devMode, debug bool, httpPort uint16) (error, bool) {
force := common.IsForceMode(c)
rData := common.ReadRuntimeData()
isSandboxRunning := common.VerifyRuntimeData(&rData)

if isSandboxRunning {
if rData.Running == sandbox.Name && ((rData.Mode == common.MODE_DEV) == devMode) {
return nil
return nil, true
} else if !AskToStopSandbox(rData, force) {
return errors.New(fmt.Sprintf("Sandbox '%s' is already running in %s mode", rData.Running, rData.Mode))
return errors.New(fmt.Sprintf("Sandbox '%s' is already running in %s mode", rData.Running, rData.Mode)), true
}
} else {
ports := []uint16{httpPort, common.MGMT_PORT, common.INFO_PORT}
Expand All @@ -86,7 +86,7 @@ func StartSandbox(c *cli.Context, sandbox *Sandbox, detach, devMode, debug bool,
}
}
if len(unavailablePorts) > 0 {
return errors.New(fmt.Sprintf("Port(s) %v are not available, stop the app(s) using them first!\n", unavailablePorts))
return errors.New(fmt.Sprintf("Port(s) %v are not available, stop the app(s) using them first!\n", unavailablePorts)), false
}
}

Expand Down Expand Up @@ -115,7 +115,7 @@ func StartSandbox(c *cli.Context, sandbox *Sandbox, detach, devMode, debug bool,
} else {
fmt.Fprintf(os.Stdout, "Started sandbox '%s' in detached mode.\n", sandbox.Name)
}
return nil
return nil, false
}

func AskToStopSandbox(rData common.RuntimeData, force bool) bool {
Expand Down

0 comments on commit 1603be8

Please sign in to comment.