Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enter: start default services before executing subcommand #257

Merged
merged 15 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions internals/cli/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ func runDaemon(rcmd *cmdRun, ch chan os.Signal, ready chan<- func()) error {

logger.Debugf("activation done in %v", time.Now().Truncate(time.Millisecond).Sub(t0))

var autoStartReady chan struct{}
var stop chan struct{}

notifyReady := func() {
stop = make(chan struct{}, 1)
ready <- func() { close(stop) }
close(ready)
}

if !rcmd.Hold {
servopts := client.ServiceOptions{}
changeID, err := rcmd.client.AutoStart(&servopts)
Expand All @@ -202,13 +211,21 @@ func runDaemon(rcmd *cmdRun, ch chan os.Signal, ready chan<- func()) error {
} else {
logger.Noticef("Started default services with change %s.", changeID)
}
}

var stop chan struct{}
if ready != nil {
stop = make(chan struct{}, 1)
ready <- func() { close(stop) }
close(ready)
benhoyt marked this conversation as resolved.
Show resolved Hide resolved
if ready != nil {
// wait for the default services to start
autoStartReady = make(chan struct{}, 1)
go func() {
waitCmd := waitMixin{
rebornplusplus marked this conversation as resolved.
Show resolved Hide resolved
hideProgress: true,
}
waitCmd.setClient(rcmd.client)
waitCmd.wait(changeID)
rebornplusplus marked this conversation as resolved.
Show resolved Hide resolved
autoStartReady <- struct{}{}
}()
}
} else if ready != nil {
notifyReady()
}

out:
Expand All @@ -226,6 +243,8 @@ out:
d.SetDegradedMode(nil)
tic.Stop()
}
case <-autoStartReady:
notifyReady()
case <-stop:
break out
}
Expand Down
12 changes: 9 additions & 3 deletions internals/cli/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ var (

type waitMixin struct {
clientMixin
NoWait bool `long:"no-wait"`
skipAbort bool
NoWait bool `long:"no-wait"`
rebornplusplus marked this conversation as resolved.
Show resolved Hide resolved
skipAbort bool
hideProgress bool
}

var waitDescs = map[string]string{
Expand Down Expand Up @@ -64,7 +65,12 @@ func (wmx waitMixin) wait(id string) (*client.Change, error) {
}
}()

pb := progress.MakeProgressBar()
var pb progress.Meter
if wmx.hideProgress {
pb = progress.NullMeter{}
} else {
pb = progress.MakeProgressBar()
}
defer func() {
pb.Finished()
// Next two are not strictly needed for CLI, but
Expand Down