提交 adb555c3 作者: Jeromy

Implement ipfs shutdown command

License: MIT
Signed-off-by: 's avatarJeromy <jeromyj@gmail.com>
上级 5ef2f42d
......@@ -126,6 +126,7 @@ var rootSubcommands = map[string]*cmds.Command{
"version": VersionCmd,
"bitswap": BitswapCmd,
"filestore": FileStoreCmd,
"shutdown": daemonShutdownCmd,
}
// RootRO is the readonly version of Root
......
package commands
import (
"fmt"
cmds "github.com/ipfs/go-ipfs/commands"
)
var daemonShutdownCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Shut down the ipfs daemon",
},
Run: func(req cmds.Request, res cmds.Response) {
nd, err := req.InvocContext().GetNode()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
if nd.LocalMode() {
res.SetError(fmt.Errorf("daemon not running"), cmds.ErrClient)
return
}
if err := nd.Process().Close(); err != nil {
log.Error("error while shutting down ipfs daemon:", err)
}
},
}
#!/bin/sh
#
# Copyright (c) 2017 Jeromy Johnson
# MIT Licensed; see the LICENSE file in this repository.
#
test_description="Test shutdown command"
. lib/test-lib.sh
test_init_ipfs
test_launch_ipfs_daemon
test_expect_success "shutdown succeeds" '
ipfs shutdown
'
test_expect_success "daemon no longer running" '
test_expect_code 1 kill -0 $IPFS_PID
'
test_launch_ipfs_daemon --offline
test_expect_success "shutdown succeeds" '
ipfs shutdown
'
test_expect_success "daemon no longer running" '
for i in $(test_seq 1 100)
do
go-sleep 100ms
! kill -0 $IPFS_PID 2>/dev/null && return
done
'
test_done
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论