Implement ipfs shutdown command
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Apr 27, 2017 at 19:04 UTC
adb555c3eba9ce59aeac29c36ea78b239e096373
3 files changed
+66
core/commands/root.go
+1
@@ -126,6 +126,7 @@ var rootSubcommands = map[string]*cmds.Command{
126
"version": VersionCmd,
127
"bitswap": BitswapCmd,
128
"filestore": FileStoreCmd,
129
+ "shutdown": daemonShutdownCmd,
130
}
131
132
// RootRO is the readonly version of Root
core/commands/shutdown.go
new
+29
@@ -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
new
+36
@@ -0,0 +1,36 @@
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
+ for i in $(test_seq 1 100)
31
+ do
32
+ go-sleep 100ms
33
+ ! kill -0 $IPFS_PID 2>/dev/null && return
34
+ done
35
+'
36
+test_done