Skip to content

Commit 3d48d5a

Browse files
committed
Implement ipfs shutdown command
License: MIT Signed-off-by: Jeromy <[email protected]>
1 parent e5529cd commit 3d48d5a

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

core/commands/root.go

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ var rootSubcommands = map[string]*cmds.Command{
126126
"version": VersionCmd,
127127
"bitswap": BitswapCmd,
128128
"filestore": FileStoreCmd,
129+
"shutdown": daemonShutdownCmd,
129130
}
130131

131132
// RootRO is the readonly version of Root

core/commands/shutdown.go

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package commands
2+
3+
import (
4+
"fmt"
5+
6+
cmds "github.com/ipfs/go-ipfs/commands"
7+
)
8+
9+
var daemonShutdownCmd = &cmds.Command{
10+
Helptext: cmds.HelpText{
11+
Tagline: "Shut down the ipfs daemon",
12+
},
13+
Run: func(req cmds.Request, res cmds.Response) {
14+
nd, err := req.InvocContext().GetNode()
15+
if err != nil {
16+
res.SetError(err, cmds.ErrNormal)
17+
return
18+
}
19+
20+
if nd.LocalMode() {
21+
res.SetError(fmt.Errorf("daemon not running"), cmds.ErrClient)
22+
return
23+
}
24+
25+
if err := nd.Process().Close(); err != nil {
26+
log.Error("error while shutting down ipfs daemon:", err)
27+
}
28+
},
29+
}

test/sharness/t0023-shutdown.sh

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2017 Jeromy Johnson
4+
# MIT Licensed; see the LICENSE file in this repository.
5+
#
6+
7+
test_description="Test shutdown command"
8+
9+
. lib/test-lib.sh
10+
11+
test_init_ipfs
12+
13+
test_launch_ipfs_daemon
14+
15+
test_expect_success "shutdown succeeds" '
16+
ipfs shutdown
17+
'
18+
19+
test_expect_success "daemon no longer running" '
20+
test_expect_code 1 kill -0 $IPFS_PID
21+
'
22+
23+
test_launch_ipfs_daemon --offline
24+
25+
test_expect_success "shutdown succeeds" '
26+
ipfs shutdown
27+
'
28+
29+
test_expect_success "daemon no longer running" '
30+
test_expect_code 1 kill -0 $IPFS_PID
31+
'
32+
test_done

0 commit comments

Comments
 (0)