提交 e12edd20 作者: Brian Tiger Chow

fix(daemon) ensure IPFS is initialized before starting the daemon

License: MIT
Signed-off-by: 's avatarBrian Tiger Chow <brian@perfmode.com>
上级 e24b09f8
......@@ -46,19 +46,9 @@ the daemon.
}
func daemonFunc(req cmds.Request) (interface{}, error) {
ctx := req.Context()
cfg, err := ctx.GetConfig()
if err != nil {
return nil, err
}
// make sure we construct online node.
ctx.Online = true
node, err := ctx.GetNode()
if err != nil {
return nil, err
}
// first, whether user has provided the initialization flag. we may be
// running in an uninitialized state.
initialize, _, err := req.Option(initOptionKwd).Bool()
if err != nil {
return nil, err
......@@ -77,12 +67,32 @@ func daemonFunc(req cmds.Request) (interface{}, error) {
}
}
// To ensure that IPFS has been initialized, fetch the config. Do this
// _before_ acquiring the daemon lock so the user gets an appropriate error
// message.
// NB: It's safe to read the config without the daemon lock, but not safe
// to write.
ctx := req.Context()
cfg, err := ctx.GetConfig()
if err != nil {
return nil, err
}
// acquire the daemon lock _before_ constructing a node. we need to make
// sure we are permitted to access the resources (datastore, etc.)
lock, err := daemon.Lock(req.Context().ConfigRoot)
if err != nil {
return nil, debugerror.Errorf("Couldn't obtain lock. Is another daemon already running?")
}
defer lock.Close()
// make sure we construct online node.
ctx.Online = true
node, err := ctx.GetNode()
if err != nil {
return nil, err
}
addr, err := ma.NewMultiaddr(cfg.Addresses.API)
if err != nil {
return nil, err
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论