diff --git a/freeze.go b/freeze.go index f4c2381..b844222 100644 --- a/freeze.go +++ b/freeze.go @@ -808,7 +808,8 @@ func (server *Server) UpdateConfig(key, value string) { server.numLogOps += 1 } -// Delete the config value identified by the given key from the datastore. +// Write to the freezelog that the config with key +// has been reset to its default value. func (server *Server) ResetConfig(key string) { fcfg := &freezer.ConfigKeyValuePair{ Key: proto.String(key), diff --git a/server.go b/server.go index 4e53831..0780245 100644 --- a/server.go +++ b/server.go @@ -51,6 +51,7 @@ const ( type KeyValuePair struct { Key string Value string + Reset bool } // A Murmur server instance @@ -363,7 +364,11 @@ func (server *Server) handlerLoop() { // Disk freeze config update case kvp := <-server.cfgUpdate: - server.UpdateConfig(kvp.Key, kvp.Value) + if !kvp.Reset { + server.UpdateConfig(kvp.Key, kvp.Value) + } else { + server.ResetConfig(kvp.Key) + } // Server registration update // Tick every hour + a minute offset based on the server id. diff --git a/ssh.go b/ssh.go index ecf1bd5..017f382 100644 --- a/ssh.go +++ b/ssh.go @@ -57,27 +57,31 @@ func RunSSH() { RegisterSSHCmd("start", StartServerCmd, "", - "Starts the server with the given id") + "Starts the server") RegisterSSHCmd("stop", StopServerCmd, "", - "Stops the server with the given id") + "Stops the server") RegisterSSHCmd("restart", RestartServerCmd, "", - "Restarts the server with the given id") + "Restarts the server") RegisterSSHCmd("supw", SetSuperUserPasswordCmd, " ", - "Set the SuperUser password for server with the given id") + "Set the SuperUser password") RegisterSSHCmd("setconf", SetConfCmd, " ", - "Set a config value for the server with the given id") + "Set a config value for the key") RegisterSSHCmd("getconf", GetConfCmd, " ", - "Get a config value for the server with the given id") + "Get the config value identified by key") + RegisterSSHCmd("clearconf", + ClearConfCmd, + " ", + "Resets the config value identified by key to its default value") pemBytes, err := ioutil.ReadFile(filepath.Join(Args.DataDir, "key.pem")) if err != nil { @@ -364,3 +368,26 @@ func GetConfCmd(reply SshCmdReply, args []string) error { reply.WriteString(fmt.Sprintf("[%v] %v = %v\r\n", serverId, key, value)) return nil } + +func ClearConfCmd(reply SshCmdReply, args []string) error { + if len(args) != 3 { + return errors.New("argument count mismatch") + } + + serverId, err := strconv.Atoi64(args[1]) + if err != nil { + return errors.New("bad server id") + } + + server, exists := servers[serverId] + if !exists { + return errors.New("no such server") + } + + key := args[2] + server.cfg.Reset(key) + server.cfgUpdate <- &KeyValuePair{Key: key, Reset: true} + + reply.WriteString(fmt.Sprintf("[%v] Cleared value for %v\r\n", serverId, key)) + return nil +} \ No newline at end of file