/
cmd_ctl_stop.go
87 lines (76 loc) · 2.21 KB
/
cmd_ctl_stop.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
//go:build !darwin
// +build !darwin
package client
import (
"runtime"
"github.com/keybase/cli"
"github.com/keybase/client/go/install"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
"github.com/keybase/client/go/protocol/keybase1"
)
func NewCmdCtlStop(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "stop",
Usage: "Stop Keybase",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "shutdown",
Usage: "Only shutdown the background service",
},
},
Action: func(c *cli.Context) {
cl.ChooseCommand(newCmdCtlStop(g), "stop", c)
cl.SetForkCmd(libcmdline.NoFork)
cl.SetNoStandalone()
},
}
}
func newCmdCtlStop(g *libkb.GlobalContext) *CmdCtlStop {
return &CmdCtlStop{
Contextified: libkb.NewContextified(g),
}
}
type CmdCtlStop struct {
libkb.Contextified
shutdown bool
}
func (s *CmdCtlStop) ParseArgv(ctx *cli.Context) error {
s.shutdown = ctx.Bool("shutdown")
return nil
}
func (s *CmdCtlStop) Run() (err error) {
mctx := libkb.NewMetaContextTODO(s.G())
switch runtime.GOOS {
case "windows":
if s.shutdown {
mctx.Error("the `shutdown` parameter is not supported on windows")
}
mctx.Info("stopping the keybase file system")
install.StopAllButService(mctx, keybase1.ExitCode_OK)
cli, err := GetCtlClient(s.G())
if err != nil {
mctx.Error("failed to get ctl client for shutdown: %s", err)
return err
}
mctx.Info("stopping the keybase background services")
return cli.StopService(mctx.Ctx(), keybase1.StopServiceArg{ExitCode: keybase1.ExitCode_OK})
default:
// On Linux, StopAllButService depends on a running service to tell it
// what clients to shut down, so we can't call it directly from here,
// but need to go through the RPC first.
cli, err := GetCtlClient(s.G())
if err != nil {
return err
}
if s.shutdown {
return cli.StopService(mctx.Ctx(), keybase1.StopServiceArg{ExitCode: keybase1.ExitCode_OK})
}
return cli.Stop(mctx.Ctx(), keybase1.StopArg{ExitCode: keybase1.ExitCode_OK})
}
}
func (s *CmdCtlStop) GetUsage() libkb.Usage {
return libkb.Usage{}
}