shutdown.go 588 Bytes
Newer Older
Jeromy's avatar
Jeromy committed
1 2 3
package commands

import (
4 5
	cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"

Steven Allen's avatar
Steven Allen committed
6
	"github.com/ipfs/go-ipfs-cmds"
Jeromy's avatar
Jeromy committed
7 8 9
)

var daemonShutdownCmd = &cmds.Command{
Steven Allen's avatar
Steven Allen committed
10
	Helptext: cmds.HelpText{
Jeromy's avatar
Jeromy committed
11 12
		Tagline: "Shut down the ipfs daemon",
	},
keks's avatar
keks committed
13
	Run: func(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment) error {
14
		nd, err := cmdenv.GetNode(env)
Jeromy's avatar
Jeromy committed
15
		if err != nil {
keks's avatar
keks committed
16
			return err
Jeromy's avatar
Jeromy committed
17 18
		}

19
		if !nd.IsDaemon {
Steven Allen's avatar
Steven Allen committed
20
			return cmds.Errorf(cmds.ErrClient, "daemon not running")
Jeromy's avatar
Jeromy committed
21 22
		}

23
		if err := nd.Close(); err != nil {
Jeromy's avatar
Jeromy committed
24 25
			log.Error("error while shutting down ipfs daemon:", err)
		}
keks's avatar
keks committed
26 27

		return nil
Jeromy's avatar
Jeromy committed
28 29
	},
}