Skip to content

Commit

Permalink
Merge pull request #1103 from travisperson/bug/init-with-daemon
Browse files Browse the repository at this point in the history
Check to see if the daemon is currently running
  • Loading branch information
jbenet committed Apr 21, 2015
2 parents 33fab22 + 676fd50 commit 1bac12f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cmd/ipfs/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions test/sharness/t0020-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,16 @@ test_expect_success "ipfs init output looks good" '
test_cmp expected actual_init
'

test_init_ipfs

test_launch_ipfs_daemon

test_expect_success "ipfs init should not run while daemon is running" '
test_must_fail ipfs init 2> daemon_running_err &&
EXPECT="Error: ipfs daemon is running. please stop it to run this command" &&
grep "$EXPECT" daemon_running_err
'

test_kill_ipfs_daemon

test_done

0 comments on commit 1bac12f

Please sign in to comment.