Skip to content

Commit

Permalink
Implement ipfs shutdown command
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jeromy <[email protected]>
  • Loading branch information
whyrusleeping committed Apr 28, 2017
1 parent e5529cd commit 331bc1b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions core/commands/shutdown.go
Original file line number Diff line number Diff line change
@@ -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)
}
},
}
32 changes: 32 additions & 0 deletions test/sharness/t0023-shutdown.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/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" '
test_expect_code 1 kill -0 $IPFS_PID
'
test_done

0 comments on commit 331bc1b

Please sign in to comment.