1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-07-01 19:24:14 +08:00

Merge pull request #3884 from ipfs/feat/shutdown-cmd

Implement ipfs shutdown command
This commit is contained in:
Jeromy Johnson
2017-05-17 22:44:06 -07:00
committed by GitHub
3 changed files with 66 additions and 0 deletions

View File

@ -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

29
core/commands/shutdown.go Normal file
View File

@ -0,0 +1,29 @@
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)
}
},
}

36
test/sharness/t0023-shutdown.sh Executable file
View File

@ -0,0 +1,36 @@
#!/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