feat(2/daemon) --initialized
@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>
Brian Tiger Chow committed
Nov 16, 2014 at 13:32 UTC
061200452f4f4de5df364330ce7a0c7f343fd8a4
2 files changed
+34
-6
cmd/ipfs2/daemon.go
+29
-4
@@ -4,16 +4,20 @@ import (
4
"fmt"
5
"net/http"
6
7
+ manners "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/braintree/manners"
8
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
9
manet "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr/net"
9
- errors "github.com/jbenet/go-ipfs/util/errors"
10
-
11
- manners "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/braintree/manners"
10
cmds "github.com/jbenet/go-ipfs/commands"
11
cmdsHttp "github.com/jbenet/go-ipfs/commands/http"
12
core "github.com/jbenet/go-ipfs/core"
13
commands "github.com/jbenet/go-ipfs/core/commands2"
14
daemon "github.com/jbenet/go-ipfs/daemon2"
15
+ util "github.com/jbenet/go-ipfs/util"
16
+ errors "github.com/jbenet/go-ipfs/util/errors"
17
+)
18
+
19
+const (
20
+ initializedOptionKeyword = "initialized"
21
)
22
23
var daemonCmd = &cmds.Command{
@@ -28,12 +32,33 @@ the daemon.
32
`,
33
},
34
31
- Options: []cmds.Option{},
35
+ Options: []cmds.Option{
36
+ cmds.BoolOption(initializedOptionKeyword, "Initialize IPFS with default settings if not already initialized"),
37
+ },
38
Subcommands: map[string]*cmds.Command{},
39
Run: daemonFunc,
40
}
41
42
func daemonFunc(req cmds.Request) (interface{}, error) {
43
+
44
+ init, _, err := req.Option(initializedOptionKeyword).Bool()
45
+ if err != nil {
46
+ return nil, err
47
+ }
48
+ if init {
49
+
50
+ // now, FileExists is our best method of detecting whether IPFS is
51
+ // configured. Consider moving this into a config helper method
52
+ // `IsInitialized` where the quality of the signal can be improved over
53
+ // time, and many call-sites can benefit.
54
+ if !util.FileExists(req.Context().ConfigRoot) {
55
+ err := initWithDefaults(req.Context().ConfigRoot)
56
+ if err != nil {
57
+ return nil, errors.Wrap(err)
58
+ }
59
+ }
60
+ }
61
+
62
lock, err := daemon.Lock(req.Context().ConfigRoot)
63
if err != nil {
64
return nil, errors.Errorf("Couldn't obtain lock. Is another daemon already running?")
cmd/ipfs2/ipfs.go
+5
-2
@@ -97,8 +97,11 @@ func (d *cmdDetails) usesRepo() bool { return !d.doesNotUseRepo
97
// properties so that other code can make decisions about whether to invoke a
98
// command or return an error to the user.
99
var cmdDetailsMap = map[*cmds.Command]cmdDetails{
100
- initCmd: cmdDetails{doesNotUseConfigAsInput: true, cannotRunOnDaemon: true, doesNotUseRepo: true},
101
- daemonCmd: cmdDetails{cannotRunOnDaemon: true},
100
+ initCmd: cmdDetails{doesNotUseConfigAsInput: true, cannotRunOnDaemon: true, doesNotUseRepo: true},
101
+
102
+ // daemonCmd allows user to initialize the config. Thus, it may be called
103
+ // without using the config as input
104
+ daemonCmd: cmdDetails{doesNotUseConfigAsInput: true, cannotRunOnDaemon: true},
105
commandsClientCmd: cmdDetails{doesNotUseRepo: true},
106
commands.CommandsDaemonCmd: cmdDetails{doesNotUseRepo: true},
107
commands.DiagCmd: cmdDetails{cannotRunOnClient: true},