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.
Travis Person committed
Apr 20, 2015 at 17:21 UTC
e1f8dfa25a44f83b672f934efadb96cfd50a3eb5
1 file changed
+11
cmd/ipfs/init.go
+11
@@ -35,6 +35,17 @@ var initCmd = &cmds.Command{
35
// name of the file?
36
// TODO cmds.StringOption("event-logs", "l", "Location for machine-readable event logs"),
37
},
38
+ PreRun: func(req cmds.Request) error {
39
+ daemonLocked := fsrepo.LockedByOtherProcess(req.Context().ConfigRoot)
40
+
41
+ log.Info("checking if daemon is running...")
42
+ if daemonLocked {
43
+ e := "ipfs daemon is running. please stop it to run this command"
44
+ return cmds.ClientError(e)
45
+ }
46
+
47
+ return nil
48
+ },
49
Run: func(req cmds.Request, res cmds.Response) {
50
51
force, _, err := req.Option("f").Bool() // if !found, it's okay force == false