@@ -13,14 +13,16 @@ import (
13
13
"syscall"
14
14
"time"
15
15
16
+ "github.com/crc-org/crc/v2/pkg/crc/api/client"
17
+ "github.com/crc-org/crc/v2/pkg/crc/daemonclient"
18
+
16
19
"github.com/containers/gvisor-tap-vsock/pkg/types"
17
20
"github.com/containers/gvisor-tap-vsock/pkg/virtualnetwork"
18
21
"github.com/crc-org/crc/v2/pkg/crc/adminhelper"
19
22
"github.com/crc-org/crc/v2/pkg/crc/api"
20
23
"github.com/crc-org/crc/v2/pkg/crc/api/events"
21
24
crcConfig "github.com/crc-org/crc/v2/pkg/crc/config"
22
25
"github.com/crc-org/crc/v2/pkg/crc/constants"
23
- "github.com/crc-org/crc/v2/pkg/crc/daemonclient"
24
26
"github.com/crc-org/crc/v2/pkg/crc/logging"
25
27
"github.com/docker/go-units"
26
28
"github.com/gorilla/handlers"
@@ -29,18 +31,27 @@ import (
29
31
"github.com/spf13/cobra"
30
32
)
31
33
32
- var watchdog bool
34
+ var (
35
+ watchdog bool
36
+ daemonVersionSupplier func () (client.VersionResult , error )
37
+ )
33
38
34
39
func init () {
40
+ daemonVersionSupplier = func () (client.VersionResult , error ) {
41
+ return daemonclient .New ().APIClient .Version ()
42
+ }
35
43
daemonCmd .Flags ().BoolVar (& watchdog , "watchdog" , false , "Monitor stdin and shutdown the daemon if stdin is closed" )
36
44
rootCmd .AddCommand (daemonCmd )
37
45
}
38
46
39
- const hostVirtualIP = "192.168.127.254"
47
+ const (
48
+ hostVirtualIP = "192.168.127.254"
49
+ ErrDaemonAlreadyRunning = "daemon has been started in the background"
50
+ )
40
51
41
52
func checkDaemonVersion () (bool , error ) {
42
- if _ , err := daemonclient . New (). APIClient . Version (); err == nil {
43
- return true , errors .New ("daemon is already running" )
53
+ if _ , err := daemonVersionSupplier (); err == nil {
54
+ return true , errors .New (ErrDaemonAlreadyRunning )
44
55
}
45
56
return false , nil
46
57
}
@@ -52,7 +63,7 @@ var daemonCmd = &cobra.Command{
52
63
Hidden : true ,
53
64
RunE : func (_ * cobra.Command , _ []string ) error {
54
65
if running , _ := checkIfDaemonIsRunning (); running {
55
- return errors .New ("daemon is already running" )
66
+ return errors .New (ErrDaemonAlreadyRunning )
56
67
}
57
68
58
69
virtualNetworkConfig := types.Configuration {
0 commit comments