feat: add data directory (#910)

Signed-off-by: Gaius <gaius.qi@gmail.com>
This commit is contained in:
Gaius 2021-12-09 19:18:25 +08:00
parent 029c4eea36
commit 9800a211da
No known key found for this signature in database
GPG Key ID: 8B4E5D1290FA2FFB
14 changed files with 62 additions and 15 deletions

View File

@ -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"`

View File

@ -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"`

View File

@ -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{

View File

@ -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:

View File

@ -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...)
}

View File

@ -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"))

View File

@ -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

View File

@ -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:

View File

@ -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 的时候比较有用

View File

@ -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:
@ -123,7 +132,6 @@ jaeger: ""
# tracer 中使用的 service-name
# 默认值dragonfly-cdn
service-name: dragonfly-scheduler
# 开启数据收集服务
# metrics:
# # 数据服务地址

View File

@ -78,6 +78,13 @@ 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() {
@ -85,13 +92,13 @@ func New(options ...Option) (Dfpath, error) {
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")

View File

@ -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")

View File

@ -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"

View File

@ -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)
},
},
{
@ -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)
},
},
{
@ -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)
},
},
{
@ -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)
},
},
}