1
0
Fork 0
forked from External/grumble
grumble/ctl.go
2011-05-19 23:37:02 +02:00

92 lines
2 KiB
Go
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Copyright (c) 2011 The Grumble Authors
// The use of this source code is goverened by a BSD-style
// license that can be found in the LICENSE-file.
package main
import (
"log"
"rpc"
"strconv"
)
var CtlUsage = `grumble ctl
help
Show this help
start [id]
Start a server
stop [id]
Stop a server
supw [id] [password]
Set the SuperUser password for server with id
setconf [id] [key] [value]
Set a config value for server with id
getconf [id] [key] [value]
Get a config value for server with id
`
func GrumbleCtl(args []string) {
log.SetFlags(0)
if len(args) <= 1 || args[0] == "help" {
log.Printf(CtlUsage)
return
}
sid, _ := strconv.Atoi64(args[1])
client, err := rpc.Dial(*ctlnet, *ctladdr)
if err != nil {
log.Fatalf("Could not connect to control socket: %v", err)
}
switch args[0] {
case "start":
err := client.Call("ctl.Start", sid, nil)
if err != nil {
log.Fatalf("Unable to start: %v", err)
}
log.Printf("[%v] Started", sid)
case "stop":
err := client.Call("ctl.Stop", sid, nil)
if err != nil {
log.Fatalf("Unable to stop: %v", err)
}
log.Printf("[%v] Stopped", sid)
case "supw":
if len(args) < 3 {
return
}
err := client.Call("ctl.SetSuperUserPassword", &KeyValuePair{sid, "", args[2]}, nil)
if err != nil {
log.Fatalf("Unable to set SuperUser password: %v", err)
}
log.Printf("[%v] Set SuperUser password", sid)
case "setconf":
if len(args) < 4 {
return
}
result := &KeyValuePair{}
err := client.Call("ctl.SetConfig", &KeyValuePair{sid, args[2], args[3]}, result)
if err != nil {
log.Fatalf("Unable to set config: %v", err)
}
log.Printf("[%v] %v=%v", result.Id, result.Key, result.Value)
case "getconf":
if len(args) < 3 {
return
}
result := &KeyValuePair{}
err := client.Call("ctl.GetConfig", &KeyValuePair{sid, args[2], ""}, result)
if err != nil {
log.Fatalf("Unable to get config: %v", err)
}
log.Printf("[%v] %v=%v", result.Id, result.Key, result.Value)
}
}