default "weed server -filer" to same directory as -mdir

This commit is contained in:
Chris Lu 2018-12-05 23:24:25 -08:00
parent fb43a9d7b9
commit 52b24a9902
5 changed files with 29 additions and 4 deletions

View file

@ -32,6 +32,9 @@ type FilerOptions struct {
dirListingLimit *int
dataCenter *string
enableNotification *bool
// default leveldb directory, used in "weed server" mode
defaultLevelDbDirectory *string
}
func init() {
@ -88,6 +91,11 @@ func (fo *FilerOptions) startFiler() {
publicVolumeMux = http.NewServeMux()
}
defaultLevelDbDirectory := "./filerdb"
if fo.defaultLevelDbDirectory != nil {
defaultLevelDbDirectory = *fo.defaultLevelDbDirectory + "/filerdb"
}
fs, nfs_err := weed_server.NewFilerServer(defaultMux, publicVolumeMux, &weed_server.FilerOption{
Masters: strings.Split(*f.masters, ","),
Collection: *fo.collection,
@ -98,6 +106,7 @@ func (fo *FilerOptions) startFiler() {
SecretKey: *fo.secretKey,
DirListingLimit: *fo.dirListingLimit,
DataCenter: *fo.dataCenter,
DefaultLevelDbDir: defaultLevelDbDirectory,
})
if nfs_err != nil {
glog.Fatalf("Filer startup error: %v", nfs_err)

View file

@ -144,6 +144,7 @@ func runServer(cmd *Command, args []string) bool {
if err := util.TestFolderWritable(*masterMetaFolder); err != nil {
glog.Fatalf("Check Meta Folder (-mdir=\"%s\") Writable: %s", *masterMetaFolder, err)
}
filerOptions.defaultLevelDbDirectory = masterMetaFolder
if *serverWhiteListOption != "" {
serverWhiteList = strings.Split(*serverWhiteListOption, ",")

View file

@ -33,11 +33,13 @@ func (store *LevelDBStore) Initialize(configuration weed_util.Configuration) (er
}
func (store *LevelDBStore) initialize(dir string) (err error) {
glog.Infof("filer store dir: %s", dir)
if err := weed_util.TestFolderWritable(dir); err != nil {
return fmt.Errorf("Check Level Folder %s Writable: %s", dir, err)
}
if store.db, err = leveldb.OpenFile(dir, nil); err != nil {
glog.Infof("filer store open dir %s: %v", dir, err)
return
}
return

View file

@ -31,7 +31,7 @@ func LoadConfiguration(config *viper.Viper) {
if config.GetBool(store.GetName() + ".enabled") {
viperSub := config.Sub(store.GetName())
if err := store.Initialize(viperSub); err != nil {
glog.Fatalf("Failed to initialize store for %s: %+v",
glog.Fatalf("Failed to initialize notification for %s: %+v",
store.GetName(), err)
}
Queue = store

View file

@ -2,6 +2,7 @@ package weed_server
import (
"net/http"
"os"
"github.com/chrislusf/seaweedfs/weed/filer2"
_ "github.com/chrislusf/seaweedfs/weed/filer2/cassandra"
@ -30,6 +31,7 @@ type FilerOption struct {
SecretKey string
DirListingLimit int
DataCenter string
DefaultLevelDbDir string
}
type FilerServer struct {
@ -52,9 +54,16 @@ func NewFilerServer(defaultMux, readonlyMux *http.ServeMux, option *FilerOption)
go fs.filer.KeepConnectedToMaster()
LoadConfiguration("filer", true)
LoadConfiguration("notification", false)
v := viper.GetViper()
if !LoadConfiguration("filer", false) {
v.Set("leveldb.enabled", true)
v.Set("leveldb.dir", option.DefaultLevelDbDir)
_, err := os.Stat(option.DefaultLevelDbDir)
if os.IsNotExist(err) {
os.MkdirAll(option.DefaultLevelDbDir, 0755)
}
}
LoadConfiguration("notification", false)
fs.filer.LoadConfiguration(v)
@ -73,7 +82,7 @@ func (fs *FilerServer) jwt(fileId string) security.EncodedJwt {
return security.GenJwt(fs.secret, fileId)
}
func LoadConfiguration(configFileName string, required bool) {
func LoadConfiguration(configFileName string, required bool) (loaded bool) {
// find a filer store
viper.SetConfigName(configFileName) // name of config file (without extension)
@ -93,7 +102,11 @@ func LoadConfiguration(configFileName string, required bool) {
"\nOr use this command to generate the default toml file\n"+
" weed scaffold -config=%s -output=.\n\n\n",
configFileName, configFileName, configFileName)
} else {
return false
}
}
return true
}