add command line varible -i to ignore the existing configuration

This commit is contained in:
Xiang Li 2013-06-28 15:04:05 -07:00
parent f67115b935
commit 430f5d50e3

14
etcd.go
View File

@ -46,6 +46,7 @@ var clientCAFile string
var dirPath string
var ignore bool
func init() {
flag.BoolVar(&verbose, "v", false, "verbose logging")
@ -66,6 +67,8 @@ func init() {
flag.StringVar(&clientKeyFile, "clientKey", "", "the key file of the client")
flag.StringVar(&dirPath, "d", "./", "the directory to store log and snapshot")
flag.BoolVar(&ignore, "i", false , "ignore the old configuration, create a new node")
}
// CONSTANTS
@ -392,6 +395,17 @@ func getInfo(path string) *Info {
// Read in the server info if available.
infoPath := fmt.Sprintf("%s/info", path)
// delete the old configuration if exist
if ignore {
logPath := fmt.Sprintf("%s/log", path)
snapshotPath := fmt.Sprintf("%s/snapshotPath", path)
os.Remove(infoPath)
os.Remove(logPath)
os.RemoveAll(snapshotPath)
}
if file, err := os.Open(infoPath); err == nil {
if content, err := ioutil.ReadAll(file); err != nil {
fatal("Unable to read info: %v", err)