feat: add data directory (#910)
Signed-off-by: Gaius <gaius.qi@gmail.com>
This commit is contained in:
parent
029c4eea36
commit
9800a211da
|
|
@ -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"`
|
||||
|
||||
|
|
|
|||
|
|
@ -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"`
|
||||
|
|
|
|||
|
|
@ -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{
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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...)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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"))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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 的时候比较有用
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
# # 数据服务地址
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue