Skip to content

Commit

Permalink
Windows: Check if daemon process is already running
Browse files Browse the repository at this point in the history
Without this PR following scenario happen
- User installed the crc first time and do the setup
- As part of the setup crc daemon is started by task schedular
- User reboot
- Tray autostart with reboot but `crc setup --check-only` fails
because daemon task is not running.

With this PR, check for daemon task running should first validate
if an existing process of `crc daemon` is running and the version
it get from the api should be same as the binary then task running
check succeed. So this PR will makes `crc setup --check-only` work
again with tray autostart.
  • Loading branch information
praveenkumar committed Mar 31, 2022
1 parent 4582375 commit 161a6be
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/crc/preflight/preflight_checks_common.go
Expand Up @@ -8,10 +8,12 @@ import (
"github.com/code-ready/crc/pkg/crc/adminhelper"
"github.com/code-ready/crc/pkg/crc/cluster"
"github.com/code-ready/crc/pkg/crc/constants"
"github.com/code-ready/crc/pkg/crc/daemonclient"
"github.com/code-ready/crc/pkg/crc/logging"
"github.com/code-ready/crc/pkg/crc/machine/bundle"
"github.com/code-ready/crc/pkg/crc/preset"
"github.com/code-ready/crc/pkg/crc/validation"
"github.com/code-ready/crc/pkg/crc/version"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -144,3 +146,15 @@ func removeOldLogs() error {
}
return nil
}

func isDaemonRunningWithReleasedVersion() bool {
ver, err := daemonclient.New().APIClient.Version()
if err != nil {
return false
}
if ver.CrcVersion != version.GetCRCVersion() {
logging.Debugf("Daemon is running with %s version but binary version is %s", ver.CrcVersion, version.GetCRCVersion())
return false
}
return true
}
3 changes: 3 additions & 0 deletions pkg/crc/preflight/preflight_daemon_task_check_windows.go
Expand Up @@ -111,6 +111,9 @@ func removeDaemonTask() error {
}

func checkIfDaemonTaskRunning() error {
if isDaemonRunningWithReleasedVersion() {
return nil
}
stdout, stderr, err := powershell.Execute(fmt.Sprintf(`(Get-ScheduledTask -TaskName "%s").State`, constants.DaemonTaskName))
if err != nil {
logging.Debugf("%s task is not running: %v : %s", constants.DaemonTaskName, err, stderr)
Expand Down

0 comments on commit 161a6be

Please sign in to comment.