forked from External/grumble
Add clearconf option to ssh admin.
This commit is contained in:
parent
d59392b89a
commit
9ee6172b04
3 changed files with 41 additions and 8 deletions
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
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.
|
||||
|
|
|
|||
39
ssh.go
39
ssh.go
|
|
@ -57,27 +57,31 @@ func RunSSH() {
|
|||
RegisterSSHCmd("start",
|
||||
StartServerCmd,
|
||||
"<id>",
|
||||
"Starts the server with the given id")
|
||||
"Starts the server")
|
||||
RegisterSSHCmd("stop",
|
||||
StopServerCmd,
|
||||
"<id>",
|
||||
"Stops the server with the given id")
|
||||
"Stops the server")
|
||||
RegisterSSHCmd("restart",
|
||||
RestartServerCmd,
|
||||
"<id>",
|
||||
"Restarts the server with the given id")
|
||||
"Restarts the server")
|
||||
RegisterSSHCmd("supw",
|
||||
SetSuperUserPasswordCmd,
|
||||
"<id> <password>",
|
||||
"Set the SuperUser password for server with the given id")
|
||||
"Set the SuperUser password")
|
||||
RegisterSSHCmd("setconf",
|
||||
SetConfCmd,
|
||||
"<id> <key> <value>",
|
||||
"Set a config value for the server with the given id")
|
||||
"Set a config value for the key")
|
||||
RegisterSSHCmd("getconf",
|
||||
GetConfCmd,
|
||||
"<id> <key>",
|
||||
"Get a config value for the server with the given id")
|
||||
"Get the config value identified by key")
|
||||
RegisterSSHCmd("clearconf",
|
||||
ClearConfCmd,
|
||||
"<id> <key>",
|
||||
"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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue