2016-03-05 02:08:16 +03:00
|
|
|
package controller
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
2016-03-29 15:53:53 +03:00
|
|
|
"time"
|
2016-03-05 02:08:16 +03:00
|
|
|
|
2016-03-06 17:55:00 +03:00
|
|
|
"github.com/tidwall/tile38/controller/log"
|
2016-03-29 15:53:53 +03:00
|
|
|
"github.com/tidwall/tile38/controller/server"
|
2016-03-05 02:08:16 +03:00
|
|
|
)
|
|
|
|
|
2016-03-29 15:53:53 +03:00
|
|
|
func (c *Controller) cmdReadOnly(msg *server.Message) (res string, err error) {
|
|
|
|
start := time.Now()
|
|
|
|
vs := msg.Values[1:]
|
2016-03-05 02:08:16 +03:00
|
|
|
var arg string
|
2016-03-29 15:53:53 +03:00
|
|
|
var ok bool
|
|
|
|
if vs, arg, ok = tokenval(vs); !ok || arg == "" {
|
|
|
|
return "", errInvalidNumberOfArguments
|
2016-03-05 02:08:16 +03:00
|
|
|
}
|
2016-03-29 15:53:53 +03:00
|
|
|
if len(vs) != 0 {
|
|
|
|
return "", errInvalidNumberOfArguments
|
2016-03-05 02:08:16 +03:00
|
|
|
}
|
2016-03-29 15:53:53 +03:00
|
|
|
update := false
|
2016-03-05 02:08:16 +03:00
|
|
|
switch strings.ToLower(arg) {
|
|
|
|
default:
|
2016-03-29 15:53:53 +03:00
|
|
|
return "", errInvalidArgument(arg)
|
2016-03-05 02:08:16 +03:00
|
|
|
case "yes":
|
2017-09-30 04:11:05 +03:00
|
|
|
if !c.config.readOnly() {
|
2016-03-29 15:53:53 +03:00
|
|
|
update = true
|
2017-09-30 04:11:05 +03:00
|
|
|
c.config.setReadOnly(true)
|
2016-03-29 15:53:53 +03:00
|
|
|
log.Info("read only")
|
2016-03-05 02:08:16 +03:00
|
|
|
}
|
|
|
|
case "no":
|
2017-09-30 04:11:05 +03:00
|
|
|
if c.config.readOnly() {
|
2016-03-29 15:53:53 +03:00
|
|
|
update = true
|
2017-09-30 04:11:05 +03:00
|
|
|
c.config.setReadOnly(false)
|
2016-03-29 15:53:53 +03:00
|
|
|
log.Info("read write")
|
2016-03-05 02:08:16 +03:00
|
|
|
}
|
|
|
|
}
|
2016-03-29 15:53:53 +03:00
|
|
|
if update {
|
2017-09-30 04:11:05 +03:00
|
|
|
c.config.write(false)
|
2016-03-05 02:08:16 +03:00
|
|
|
}
|
2016-03-29 15:53:53 +03:00
|
|
|
return server.OKMessage(msg, start), nil
|
2016-03-05 02:08:16 +03:00
|
|
|
}
|