mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-01 10:49:24 +08:00
Merge pull request #3884 from ipfs/feat/shutdown-cmd
Implement ipfs shutdown command
This commit is contained in:
@ -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
29
core/commands/shutdown.go
Normal 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
36
test/sharness/t0023-shutdown.sh
Executable 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
|
Reference in New Issue
Block a user