From e1f8dfa25a44f83b672f934efadb96cfd50a3eb5 Mon Sep 17 00:00:00 2001 From: Travis Person <travis.person@gmail.com> Date: Mon, 20 Apr 2015 17:21:13 -0700 Subject: [PATCH] Check to see if the daemon is currently running If the daemon is running we do not want to proceed with an an initialization. Return a client error telling the user to kill the daemon before proceeding with the command. --- cmd/ipfs/init.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cmd/ipfs/init.go b/cmd/ipfs/init.go index 66bdaf671..daab7f36f 100644 --- a/cmd/ipfs/init.go +++ b/cmd/ipfs/init.go @@ -35,6 +35,17 @@ var initCmd = &cmds.Command{ // name of the file? // TODO cmds.StringOption("event-logs", "l", "Location for machine-readable event logs"), }, + PreRun: func(req cmds.Request) error { + daemonLocked := fsrepo.LockedByOtherProcess(req.Context().ConfigRoot) + + log.Info("checking if daemon is running...") + if daemonLocked { + e := "ipfs daemon is running. please stop it to run this command" + return cmds.ClientError(e) + } + + return nil + }, Run: func(req cmds.Request, res cmds.Response) { force, _, err := req.Option("f").Bool() // if !found, it's okay force == false -- GitLab