Skip to content

Commit

Permalink
feat: add data directory (#910)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi authored Dec 9, 2021
1 parent 193c30c commit 02b898b
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 15 deletions.
3 changes: 0 additions & 3 deletions client/config/dfget.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ type ClientOption struct {
// ShowProgress shows progress bar, it's conflict with `--console`.
ShowProgress bool `yaml:"show-progress,omitempty" mapstructure:"show-progress,omitempty"`

// DaemonSockPath is dfget daemon socket path.
DaemonSockPath string `yaml:"daemonSockPath,omitempty" mapstructure:"daemonSockPath,omitempty"`

// LogDir is log directory of dfget.
LogDir string `yaml:"logDir,omitempty" mapstructure:"logDir,omitempty"`

Expand Down
1 change: 1 addition & 0 deletions client/config/peerhost.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type DaemonOption struct {
WorkHome string `mapstructure:"workHome" yaml:"workHome"`
CacheDir string `mapstructure:"cacheDir" yaml:"cacheDir"`
LogDir string `mapstructure:"logDir" yaml:"logDir"`
DataDir string `mapstructure:"dataDir" yaml:"dataDir"`
KeepStorage bool `mapstructure:"keepStorage" yaml:"keepStorage"`

Scheduler SchedulerOption `mapstructure:"scheduler" yaml:"scheduler"`
Expand Down
3 changes: 3 additions & 0 deletions client/config/peerhost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ func TestPeerHostOption_Load(t *testing.T) {
Duration: 60000000000,
},
WorkHome: "/tmp/dragonfly/dfdaemon/",
DataDir: "/var/lib/dragonfly/",
LogDir: "/var/log/dragonfly/",
CacheDir: "/var/cache/dragonfly/",
KeepStorage: false,
Scheduler: SchedulerOption{
Manager: ManagerOption{
Expand Down
3 changes: 3 additions & 0 deletions client/config/testdata/config/daemon.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
aliveTime: 0s
gcInterval: 1m0s
workHome: /tmp/dragonfly/dfdaemon/
dataDir: /var/lib/dragonfly/
logDir: /var/log/dragonfly/
cacheDir: /var/cache/dragonfly/
keepStorage: false
scheduler:
manager:
Expand Down
4 changes: 4 additions & 0 deletions cmd/dfget/cmd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ func initDaemonDfpath(cfg *config.DaemonOption) (dfpath.Dfpath, error) {
options = append(options, dfpath.WithLogDir(cfg.LogDir))
}

if cfg.DataDir != "" {
options = append(options, dfpath.WithDataDir(cfg.DataDir))
}

return dfpath.New(options...)
}

Expand Down
2 changes: 0 additions & 2 deletions cmd/dfget/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ func init() {

flagSet.String("log-dir", dfgetConfig.LogDir, "Dfget log directory")

flagSet.String("daemon-sock-path", dfgetConfig.DaemonSockPath, "The socket path of dfget daemon")

// Bind cmd flags
if err := viper.BindPFlags(flagSet); err != nil {
panic(errors.Wrap(err, "bind dfget flags to viper"))
Expand Down
5 changes: 5 additions & 0 deletions docs/en/deployment/configuration/dfget.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ cacheDir: ""
# in macos(just for testing), default value is /Users/$USER/.dragonfly/logs
logDir: ""

# dataDir is the download data storage directory
# in linux, default value is /var/bin/dragonfly
# in macos(just for testing), default value is /Users/$USER/.dragonfly/data
dataDir: ""

# when daemon exit, keep peer task data or not
# it is usefully when upgrade daemon service, all local cache will be saved
# default is false
Expand Down
5 changes: 5 additions & 0 deletions docs/zh-CN/deployment/configuration/cdn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ base:
# 默认值:disk
storageMode: disk

# cdn 日志目录
# linux 上默认目录 /var/log/dragonfly
# macos(仅开发、测试), 默认目录是 /Users/$USER/.dragonfly/logs
logDir: ""

# CDN 连接的 manager,可以不指定。
# 各项配置默认值如下。如果 addr 为空字符串,CDN将不会连接manager。
manager:
Expand Down
26 changes: 18 additions & 8 deletions docs/zh-CN/deployment/configuration/dfget.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,25 @@ aliveTime: 0s
# daemon gc 间隔
gcInterval: 1m0s

# daemon 数据目录
# linux 上默认目录为 $HOME/.dragonfly/dfget-daemon/
# macos(仅开发、测试), 默认目录是 /Users/$USER/.dragonfly/dfdaemon/
dataDir: /var/lib/dragonfly

# daemon 工作目录
# linux 上默认目录 $HOME/.dragonfly/dfget-daemon/
# macos(仅开发、测试), 默认目录是 /Users/$USER/.dragonfly/dfdaemon/
workHome: /var/lib/dragonfly
# linux 上默认目录 /usr/local/dragonfly
# macos(仅开发、测试), 默认目录是 /Users/$USER/.dragonfly
workHome: ""

# daemon 动态配置缓存目录
# linux 上默认目录 /var/cache/dragonfly
# macos(仅开发、测试), 默认目录是 /Users/$USER/.dragonfly/cache
cacheDir: ""

# daemon 日志目录
# linux 上默认目录 /var/log/dragonfly
# macos(仅开发、测试), 默认目录是 /Users/$USER/.dragonfly/logs
logDir: ""

# daemon 数据目录
# linux 上默认目录为 /var/lib/dragonfly
# macos(仅开发、测试), 默认目录是 /Users/$USER/.dragonfly/data/
dataDir: ""

# 当 daemon 退出是, 是否保存缓存数据
# 保留缓存数据在升级 daemon 的时候比较有用
Expand Down
10 changes: 9 additions & 1 deletion docs/zh-CN/deployment/configuration/scheduler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ server:
# ListenPort is the ip and port scheduler server listens on.
# default: 8002
port:
# daemon 动态配置缓存目录
# linux 上默认目录 /var/cache/dragonfly
# macos(仅开发、测试), 默认目录是 /Users/$USER/.dragonfly/cache
cacheDir: ""

# daemon 日志目录
# linux 上默认目录 /var/log/dragonfly
# macos(仅开发、测试), 默认目录是 /Users/$USER/.dragonfly/logs
logDir: ""

# 动态数据配置
dynConfig:
Expand Down Expand Up @@ -123,7 +132,6 @@ jaeger: ""
# tracer 中使用的 service-name
# 默认值:dragonfly-cdn
service-name: dragonfly-scheduler

# 开启数据收集服务
# metrics:
# # 数据服务地址
Expand Down
9 changes: 8 additions & 1 deletion internal/dfpath/dfpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,27 @@ func WithLogDir(dir string) Option {
}
}

// WithDataDir set download data directory
func WithDataDir(dir string) Option {
return func(d *dfpath) {
d.dataDir = dir
}
}

// New returns a new dfpath interface
func New(options ...Option) (Dfpath, error) {
cache.Do(func() {
d := &dfpath{
workHome: DefaultWorkHome,
cacheDir: DefaultCacheDir,
logDir: DefaultLogDir,
dataDir: DefaultDataDir,
}

for _, opt := range options {
opt(d)
}

d.dataDir = filepath.Join(d.workHome, "data")
d.pluginDir = filepath.Join(d.workHome, "plugins")
d.daemonSockPath = filepath.Join(d.workHome, "daemon.sock")
d.daemonLockPath = filepath.Join(d.workHome, "daemon.lock")
Expand Down
1 change: 1 addition & 0 deletions internal/dfpath/dfpath_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ var DefaultWorkHome = filepath.Join(basic.HomeDir, ".dragonfly")
var DefaultCacheDir = filepath.Join(DefaultWorkHome, "cache")
var DefaultConfigDir = filepath.Join(DefaultWorkHome, "config")
var DefaultLogDir = filepath.Join(DefaultWorkHome, "logs")
var DefaultDataDir = filepath.Join(DefaultWorkHome, "data")
1 change: 1 addition & 0 deletions internal/dfpath/dfpath_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ var DefaultWorkHome = "/usr/local/dragonfly"
var DefaultCacheDir = "/var/cache/dragonfly"
var DefaultConfigDir = "/etc/dragonfly"
var DefaultLogDir = "/var/log/dragonfly"
var DefaultDataDir = "/var/lib/dragonfly"
4 changes: 4 additions & 0 deletions internal/dfpath/dfpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func TestNew(t *testing.T) {
assert.Equal(d.WorkHome(), DefaultWorkHome)
assert.Equal(d.CacheDir(), DefaultCacheDir)
assert.Equal(d.LogDir(), DefaultLogDir)
assert.Equal(d.DataDir(), DefaultDataDir)
},
},
{
Expand All @@ -49,6 +50,7 @@ func TestNew(t *testing.T) {
assert.Equal(d.WorkHome(), DefaultWorkHome)
assert.Equal(d.CacheDir(), DefaultCacheDir)
assert.Equal(d.LogDir(), DefaultLogDir)
assert.Equal(d.DataDir(), DefaultDataDir)
},
},
{
Expand All @@ -61,6 +63,7 @@ func TestNew(t *testing.T) {
assert.Equal(d.WorkHome(), DefaultWorkHome)
assert.Equal(d.CacheDir(), DefaultCacheDir)
assert.Equal(d.LogDir(), DefaultLogDir)
assert.Equal(d.DataDir(), DefaultDataDir)
},
},
{
Expand All @@ -73,6 +76,7 @@ func TestNew(t *testing.T) {
assert.Equal(d.WorkHome(), DefaultWorkHome)
assert.Equal(d.CacheDir(), DefaultCacheDir)
assert.Equal(d.LogDir(), DefaultLogDir)
assert.Equal(d.DataDir(), DefaultDataDir)
},
},
}
Expand Down

0 comments on commit 02b898b

Please sign in to comment.