forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_ctl_restart.go
70 lines (59 loc) · 1.74 KB
/
cmd_ctl_restart.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
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package client
import (
"time"
"golang.org/x/net/context"
"github.com/keybase/cli"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
keybase1 "github.com/keybase/client/go/protocol"
)
func NewCmdCtlRestart(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "restart",
Usage: "Restart the background keybase service",
Action: func(c *cli.Context) {
cl.ChooseCommand(&CmdCtlRestart{libkb.NewContextified(g)}, "restart", c)
cl.SetForkCmd(libcmdline.NoFork)
cl.SetNoStandalone()
},
}
}
type CmdCtlRestart struct {
libkb.Contextified
}
func (s *CmdCtlRestart) ParseArgv(ctx *cli.Context) error {
return nil
}
func (s *CmdCtlRestart) Run() error {
configCli, err := GetConfigClient(s.G())
if err != nil {
return err
}
config, err := configCli.GetConfig(context.TODO(), 0)
if err != nil {
return err
}
cli, err := GetCtlClient(s.G())
if err != nil {
return err
}
if err = cli.Stop(context.TODO(), keybase1.StopArg{ExitCode: keybase1.ExitCode_RESTART}); err != nil {
s.G().Log.Warning("Stop failed: %s", err)
return err
}
// If the watchdog or launchd started this process, it will do the restarting.
// Otherwise we have to.
if config.ForkType != keybase1.ForkType_WATCHDOG && config.ForkType != keybase1.ForkType_LAUNCHD {
// Wait a few seconds before the server stops
s.G().Log.Info("Delaying for shutdown...")
time.Sleep(2 * time.Second)
s.G().Log.Info("Restart")
_, err = ForkServer(s.G(), s.G().Env.GetCommandLine(), config.ForkType)
}
return err
}
func (s *CmdCtlRestart) GetUsage() libkb.Usage {
return libkb.Usage{}
}