Skip to content

Commit

Permalink
Fix bug: first run of node (docker)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zensey committed Apr 19, 2024
1 parent 7b8b956 commit 98b3dd0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 17 deletions.
29 changes: 20 additions & 9 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,25 @@ func NewController(m *model.UIModel, ui model.Gui_, a model.AppState) *Controlle
func (c *Controller) Start() {
//c.lg.Println("start")

restartBackendControl := func() {
restartBackendControl := func(afterInstall bool) {
fmt.Println("restartBackendControl>")

if c.runner != nil {
c.stopBackendControl()
fmt.Println("restartBackendControl stop>")
c.stopBackendControl(afterInstall)
fmt.Println("restartBackendControl stop>>>")
}
c.runner = NewBackend(c.model.Config.Backend, c.model, c.ui)

c.model.SwitchState(model.UIStateInitial)
c.startBackendControl()
}
restartBackendControl()
c.model.Bus2.Subscribe("backend", restartBackendControl)
restartBackendControl(false)

onBackendChange := func() {
restartBackendControl(false)
}
c.model.Bus2.Subscribe("backend", onBackendChange)

c.model.UIBus.SubscribeAsync("install-dlg-exit", func(id int) {
fmt.Println("install-dlg-exit>", id, c.model.State)
Expand All @@ -66,7 +74,7 @@ func (c *Controller) Start() {
case model.UIStateInstallFinished:
c.model.SwitchState(model.UIStateInitial)
// restart controller as it stops after installation
restartBackendControl()
restartBackendControl(true)

case model.UIStateInstallError:
c.ui.CloseUI()
Expand All @@ -88,7 +96,7 @@ func (c *Controller) Start() {

func (c *Controller) Shutdown() {
c.lg.Println("Shutdown >")
c.stopBackendControl()
c.stopBackendControl(false)

// TODO: unsubscribe
}
Expand All @@ -99,10 +107,12 @@ func (c *Controller) TriggerAction(action string) {

/////////////////////////////////////////////////////////////////////////

func (c *Controller) stopBackendControl() {
func (c *Controller) stopBackendControl(afterInstall bool) {
c.lg.Println("stop")

c.action <- model.ActionStop
if !afterInstall {
c.action <- model.ActionStop
}
c.wg.Wait()
}

Expand Down Expand Up @@ -158,7 +168,7 @@ func (c *Controller) startBackendControl() {
startNode()

case act := <-c.action:
// log.Println("<-", act)
log.Println("<-", act)

switch act {
case model.ActionCheck:
Expand All @@ -180,6 +190,7 @@ func (c *Controller) startBackendControl() {

case model.ActionStop:
c.runner.StopContainer()
log.Println("<- exit")
return

case model.ActionDisable:
Expand Down
32 changes: 24 additions & 8 deletions controller/docker/install_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,40 @@ import (
"bytes"
"fmt"

"github.com/mysteriumnetwork/myst-launcher/ctrl/util"
"github.com/mysteriumnetwork/myst-launcher/model"
"github.com/mysteriumnetwork/myst-launcher/utils"
"github.com/mysteriumnetwork/myst-launcher/platform"

)

func (c *Controller) tryInstallDocker() {
fmt.Println("TryInstallDocker>")

func (c *Docker_) TryInstallRuntime_() {

if c.model.Config.InitialState.Not1Not2() {
c.lg.Println("TryInstallRuntime_ !!!!2>")

c.model.SwitchState(model.UIStateInstallNeeded)

} else {
// begin install immediately
c.TryInstallRuntime()
}
}

func (c *Docker_) TryInstallRuntime() bool {
fmt.Println("TryInstallRuntime>")

mdl := c.model
ui := c.ui
//ui := c.ui
mgr, _ := platform.NewManager()
name := "Docker.dmg"

mdl.ResetProperties()
mdl.SwitchState(model.UIStateInstallInProgress)

executor := util.NewStepExecutor(mdl)
executor := NewStepExecutor(mdl)
executor.AddStep("CheckVTx", func() bool {
featuresOK, err := c.mgr.Features()
featuresOK, err := mgr.Features()
if err != nil {
c.lg.Println("Failed to query feature:", err)
return false
Expand All @@ -56,7 +73,6 @@ func (c *Controller) tryInstallDocker() {
})

executor.AddStep("DownloadFiles", func() bool {
name := "Docker.dmg"
url, err := utils.GetDockerDesktopLink()
if err != nil {
c.lg.Println("Couldn't get Docker Desktop link")
Expand All @@ -77,7 +93,7 @@ func (c *Controller) tryInstallDocker() {

executor.AddStep("InstallDocker", func() bool {
var buf bytes.Buffer
_, err = utils.CmdRun(&buf, "/usr/sbin/diskutil", "unmount", "/Volumes/Docker")
_, err := utils.CmdRun(&buf, "/usr/sbin/diskutil", "unmount", "/Volumes/Docker")
if err != nil {
c.lg.Println("Failed to run command:", err)
return false
Expand Down

0 comments on commit 98b3dd0

Please sign in to comment.