Skip to content

Commit

Permalink
feat(2/daemon) --initialized
Browse files Browse the repository at this point in the history
@jbenet

now, ipfs can be built and executed in one step:
```
docker run jbenet/go-ipfs daemon --initialized
```

License: MIT
Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
  • Loading branch information
Brian Tiger Chow committed Nov 16, 2014
1 parent 7c61967 commit af3be64
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
32 changes: 28 additions & 4 deletions cmd/ipfs2/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ import (
"fmt"
"net/http"

manners "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/braintree/manners"
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
manet "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr/net"
errors "github.com/jbenet/go-ipfs/util/errors"

manners "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/braintree/manners"
cmds "github.com/jbenet/go-ipfs/commands"
cmdsHttp "github.com/jbenet/go-ipfs/commands/http"
core "github.com/jbenet/go-ipfs/core"
commands "github.com/jbenet/go-ipfs/core/commands2"
daemon "github.com/jbenet/go-ipfs/daemon2"
util "github.com/jbenet/go-ipfs/util"
errors "github.com/jbenet/go-ipfs/util/errors"
)

const (
initializedOptionKeyword = "initialized"
)

var daemonCmd = &cmds.Command{
Expand All @@ -28,12 +32,32 @@ the daemon.
`,
},

Options: []cmds.Option{},
Options: []cmds.Option{
cmds.BoolOption(initializedOptionKeyword, "Initialize IPFS with default settings if not already initialized"),
},
Subcommands: map[string]*cmds.Command{},
Run: daemonFunc,
}

func daemonFunc(req cmds.Request) (interface{}, error) {

init, _, err := req.Option(initializedOptionKeyword).Bool()
if err != nil {
return nil, err
}
if init {

// now, FileExists is our best method of detecting whether IPFS is
// configured. Consider moving this into a config helper method
// `IsInitialized` the quality of the signal can be improved over time.
if !util.FileExists(req.Context().ConfigRoot) {
err := initWithDefaults(req.Context().ConfigRoot)
if err != nil {
return nil, errors.Wrap(err)
}
}
}

lock, err := daemon.Lock(req.Context().ConfigRoot)
if err != nil {
return nil, errors.Errorf("Couldn't obtain lock. Is another daemon already running?")
Expand Down
7 changes: 5 additions & 2 deletions cmd/ipfs2/ipfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@ func (d *cmdDetails) usesRepo() bool { return !d.doesNotUseRepo
// properties so that other code can make decisions about whether to invoke a
// command or return an error to the user.
var cmdDetailsMap = map[*cmds.Command]cmdDetails{
initCmd: cmdDetails{doesNotUseConfigAsInput: true, cannotRunOnDaemon: true, doesNotUseRepo: true},
daemonCmd: cmdDetails{cannotRunOnDaemon: true},
initCmd: cmdDetails{doesNotUseConfigAsInput: true, cannotRunOnDaemon: true, doesNotUseRepo: true},

// daemonCmd allows user to initialize the config. Thus, it may be called
// without using the config as input
daemonCmd: cmdDetails{doesNotUseConfigAsInput: true, cannotRunOnDaemon: true},
commandsClientCmd: cmdDetails{doesNotUseRepo: true},
commands.CommandsDaemonCmd: cmdDetails{doesNotUseRepo: true},
commands.DiagCmd: cmdDetails{cannotRunOnClient: true},
Expand Down

0 comments on commit af3be64

Please sign in to comment.