add a way to reset the root password.

pull/17/head
John Shahid 2013-11-05 16:30:02 -05:00
parent 4a62e98f24
commit cba71b00da
2 changed files with 15 additions and 1 deletions
src
coordinator
server

View File

@ -18,6 +18,10 @@ import (
"time"
)
const (
DEFAULT_ROOT_PWD = "root"
)
// The raftd server is a combination of the Raft server and an HTTP
// server which acts as the transport.
type RaftServer struct {
@ -144,7 +148,7 @@ func (s *RaftServer) SaveClusterAdminUser(u *clusterAdmin) error {
func (s *RaftServer) CreateRootUser() error {
u := &clusterAdmin{CommonUser{"root", "", false}}
u.changePassword("root")
u.changePassword(DEFAULT_ROOT_PWD)
return s.SaveClusterAdminUser(u)
}

View File

@ -16,6 +16,7 @@ import (
"runtime"
"strconv"
"syscall"
"time"
)
const (
@ -72,6 +73,7 @@ func startProfiler(filename *string) error {
func main() {
fileName := flag.String("config", "config.json.sample", "Config file")
wantsVersion := flag.Bool("v", false, "Get version number")
resetRootPassword := flag.Bool("reset-root", false, fmt.Sprintf("Reset root password to %s", coordinator.DEFAULT_ROOT_PWD))
pidFile := flag.String("pidfile", "", "the pid file")
cpuProfiler := flag.String("cpuprofile", "", "filename where cpu profile data will be written")
@ -101,6 +103,14 @@ func main() {
go func() {
raftServer.ListenAndServe(config.SeedServers, false)
}()
if *resetRootPassword {
time.Sleep(2 * time.Second) // wait for the raft server to join the cluster
if err := raftServer.CreateRootUser(); err != nil {
panic(err)
}
}
os.MkdirAll(config.DataDir, 0744)
log.Println("Opening database at ", config.DataDir)
db, err := datastore.NewLevelDbDatastore(config.DataDir)