From 52b24a99026b001f04fb01a3c244031b4c299b8f Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 5 Dec 2018 23:24:25 -0800 Subject: [PATCH] default "weed server -filer" to same directory as -mdir --- weed/command/filer.go | 9 +++++++++ weed/command/server.go | 1 + weed/filer2/leveldb/leveldb_store.go | 2 ++ weed/notification/configuration.go | 2 +- weed/server/filer_server.go | 19 ++++++++++++++++--- 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/weed/command/filer.go b/weed/command/filer.go index c7cfd6cdc..f4d6f55a8 100644 --- a/weed/command/filer.go +++ b/weed/command/filer.go @@ -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) diff --git a/weed/command/server.go b/weed/command/server.go index eca405d9d..aaca5c724 100644 --- a/weed/command/server.go +++ b/weed/command/server.go @@ -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, ",") diff --git a/weed/filer2/leveldb/leveldb_store.go b/weed/filer2/leveldb/leveldb_store.go index 5f3427a3d..179107e2c 100644 --- a/weed/filer2/leveldb/leveldb_store.go +++ b/weed/filer2/leveldb/leveldb_store.go @@ -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 diff --git a/weed/notification/configuration.go b/weed/notification/configuration.go index 68c31af77..1a5dfed75 100644 --- a/weed/notification/configuration.go +++ b/weed/notification/configuration.go @@ -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 diff --git a/weed/server/filer_server.go b/weed/server/filer_server.go index 120d07414..9d70e4dac 100644 --- a/weed/server/filer_server.go +++ b/weed/server/filer_server.go @@ -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 + }