mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 18:37:45 +08:00
upgrade shutdown command to the new commands lib
License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
This commit is contained in:
parent
4bca53e0c9
commit
8bcf6f48d9
@ -138,7 +138,7 @@ var rootSubcommands = map[string]*cmds.Command{
|
||||
"update": lgc.NewCommand(ExternalBinary()),
|
||||
"urlstore": urlStoreCmd,
|
||||
"version": lgc.NewCommand(VersionCmd),
|
||||
"shutdown": lgc.NewCommand(daemonShutdownCmd),
|
||||
"shutdown": daemonShutdownCmd,
|
||||
}
|
||||
|
||||
// RootRO is the readonly version of Root
|
||||
|
||||
@ -3,31 +3,28 @@ package commands
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
cmds "gx/ipfs/QmNueRyPRQiV7PUEpnP4GgGLuK1rKQLaRW7sfPvUetYig1/go-ipfs-cmds"
|
||||
"gx/ipfs/QmdE4gMduCKCGAcczM2F5ioYDfdeKuPix138wrES1YSr7f/go-ipfs-cmdkit"
|
||||
|
||||
cmds "github.com/ipfs/go-ipfs/commands"
|
||||
)
|
||||
|
||||
var daemonShutdownCmd = &cmds.Command{
|
||||
Helptext: cmdkit.HelpText{
|
||||
Tagline: "Shut down the ipfs daemon",
|
||||
},
|
||||
Run: func(req cmds.Request, res cmds.Response) {
|
||||
nd, err := req.InvocContext().GetNode()
|
||||
Run: func(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment) {
|
||||
nd, err := GetNode(env)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
re.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
if nd.LocalMode() {
|
||||
res.SetError(fmt.Errorf("daemon not running"), cmdkit.ErrClient)
|
||||
re.SetError(fmt.Errorf("daemon not running"), cmdkit.ErrClient)
|
||||
return
|
||||
}
|
||||
|
||||
if err := nd.Process().Close(); err != nil {
|
||||
log.Error("error while shutting down ipfs daemon:", err)
|
||||
}
|
||||
|
||||
res.SetOutput(nil)
|
||||
},
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user