Skip to content

Commit

Permalink
Windows: Add check if admin helper service is running
Browse files Browse the repository at this point in the history
Admin helper service is created and started when installer is used.
Some of the issue we are getting is user directly try to use crc
from command line and see if the openshift routes are mapped in hosts
file. This PR is help to detect if the service is running and it doesn't
need any privilage permission but it doesn't create or start this
service because that need administrator privilages.
  • Loading branch information
praveenkumar committed Mar 28, 2022
1 parent ace3a50 commit 44b868a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/crc/constants/constants_windows.go
Expand Up @@ -6,4 +6,5 @@ const (
TapSocketPath = ""
DaemonHTTPNamedPipe = `\\.\pipe\crc-http`
DaemonTaskName = "crcDaemon"
AdminHelperServiceName = "CodeReadyContainersAdminHelper"
)
11 changes: 11 additions & 0 deletions pkg/crc/preflight/preflight_checks_windows.go
Expand Up @@ -183,3 +183,14 @@ func removeCrcVM() (err error) {
logging.Debug("'crc' VM is removed")
return nil
}

func checkIfAdminHelperService() error {
stdout, stderr, err := powershell.Execute(fmt.Sprintf("(Get-Service %s).Status", constants.AdminHelperServiceName))
if err != nil {
return fmt.Errorf("%s service is not present %v: %s", constants.AdminHelperServiceName, err, stderr)
}
if strings.TrimSpace(stdout) != "Running" {
return fmt.Errorf("%s service is not running", constants.AdminHelperServiceName)
}
return nil
}
13 changes: 13 additions & 0 deletions pkg/crc/preflight/preflight_windows.go
Expand Up @@ -135,6 +135,18 @@ var daemonTaskChecks = []Check{
},
}

var adminHelperServiceCheks = []Check{
{
configKeySuffix: "check-admin-helper-service-running",
checkDescription: "Checking admin helper service is running",
check: checkIfAdminHelperService,
fixDescription: "Make sure you installed the crc using installer",
flags: NoFix,

labels: labels{Os: Windows},
},
}

var errReboot = errors.New("Please reboot your system and run 'crc setup' to complete the setup process")

func username() string {
Expand Down Expand Up @@ -181,6 +193,7 @@ func getChecks(bundlePath string, preset crcpreset.Preset) []Check {
checks = append(checks, bundleCheck(bundlePath, preset))
checks = append(checks, genericCleanupChecks...)
checks = append(checks, daemonTaskChecks...)
checks = append(checks, adminHelperServiceCheks...)
return checks
}

Expand Down

0 comments on commit 44b868a

Please sign in to comment.