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
|
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) {
|
func (server *Server) ResetConfig(key string) {
|
||||||
fcfg := &freezer.ConfigKeyValuePair{
|
fcfg := &freezer.ConfigKeyValuePair{
|
||||||
Key: proto.String(key),
|
Key: proto.String(key),
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ const (
|
||||||
type KeyValuePair struct {
|
type KeyValuePair struct {
|
||||||
Key string
|
Key string
|
||||||
Value string
|
Value string
|
||||||
|
Reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// A Murmur server instance
|
// A Murmur server instance
|
||||||
|
|
@ -363,7 +364,11 @@ func (server *Server) handlerLoop() {
|
||||||
|
|
||||||
// Disk freeze config update
|
// Disk freeze config update
|
||||||
case kvp := <-server.cfgUpdate:
|
case kvp := <-server.cfgUpdate:
|
||||||
|
if !kvp.Reset {
|
||||||
server.UpdateConfig(kvp.Key, kvp.Value)
|
server.UpdateConfig(kvp.Key, kvp.Value)
|
||||||
|
} else {
|
||||||
|
server.ResetConfig(kvp.Key)
|
||||||
|
}
|
||||||
|
|
||||||
// Server registration update
|
// Server registration update
|
||||||
// Tick every hour + a minute offset based on the server id.
|
// 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",
|
RegisterSSHCmd("start",
|
||||||
StartServerCmd,
|
StartServerCmd,
|
||||||
"<id>",
|
"<id>",
|
||||||
"Starts the server with the given id")
|
"Starts the server")
|
||||||
RegisterSSHCmd("stop",
|
RegisterSSHCmd("stop",
|
||||||
StopServerCmd,
|
StopServerCmd,
|
||||||
"<id>",
|
"<id>",
|
||||||
"Stops the server with the given id")
|
"Stops the server")
|
||||||
RegisterSSHCmd("restart",
|
RegisterSSHCmd("restart",
|
||||||
RestartServerCmd,
|
RestartServerCmd,
|
||||||
"<id>",
|
"<id>",
|
||||||
"Restarts the server with the given id")
|
"Restarts the server")
|
||||||
RegisterSSHCmd("supw",
|
RegisterSSHCmd("supw",
|
||||||
SetSuperUserPasswordCmd,
|
SetSuperUserPasswordCmd,
|
||||||
"<id> <password>",
|
"<id> <password>",
|
||||||
"Set the SuperUser password for server with the given id")
|
"Set the SuperUser password")
|
||||||
RegisterSSHCmd("setconf",
|
RegisterSSHCmd("setconf",
|
||||||
SetConfCmd,
|
SetConfCmd,
|
||||||
"<id> <key> <value>",
|
"<id> <key> <value>",
|
||||||
"Set a config value for the server with the given id")
|
"Set a config value for the key")
|
||||||
RegisterSSHCmd("getconf",
|
RegisterSSHCmd("getconf",
|
||||||
GetConfCmd,
|
GetConfCmd,
|
||||||
"<id> <key>",
|
"<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"))
|
pemBytes, err := ioutil.ReadFile(filepath.Join(Args.DataDir, "key.pem"))
|
||||||
if err != nil {
|
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))
|
reply.WriteString(fmt.Sprintf("[%v] %v = %v\r\n", serverId, key, value))
|
||||||
return nil
|
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