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

import (
	"fmt"

6 7
	cmds "gx/ipfs/QmPTfgFTo9PFr1PvPKyKoeMgBvYPh6cX3aDP7DHKVbnCbi/go-ipfs-cmds"
	"gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit"
Jeromy's avatar
Jeromy committed
8 9 10
)

var daemonShutdownCmd = &cmds.Command{
Jan Winkelmann's avatar
Jan Winkelmann committed
11
	Helptext: cmdkit.HelpText{
Jeromy's avatar
Jeromy committed
12 13
		Tagline: "Shut down the ipfs daemon",
	},
14 15
	Run: func(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment) {
		nd, err := GetNode(env)
Jeromy's avatar
Jeromy committed
16
		if err != nil {
17
			re.SetError(err, cmdkit.ErrNormal)
Jeromy's avatar
Jeromy committed
18 19 20 21
			return
		}

		if nd.LocalMode() {
22
			re.SetError(fmt.Errorf("daemon not running"), cmdkit.ErrClient)
Jeromy's avatar
Jeromy committed
23 24 25 26 27 28 29 30
			return
		}

		if err := nd.Process().Close(); err != nil {
			log.Error("error while shutting down ipfs daemon:", err)
		}
	},
}