File tree 3 files changed +62
-0
lines changed
3 files changed +62
-0
lines changed Original file line number Diff line number Diff line change @@ -126,6 +126,7 @@ var rootSubcommands = map[string]*cmds.Command{
126
126
"version" : VersionCmd ,
127
127
"bitswap" : BitswapCmd ,
128
128
"filestore" : FileStoreCmd ,
129
+ "shutdown" : daemonShutdownCmd ,
129
130
}
130
131
131
132
// RootRO is the readonly version of Root
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments