1
0
Fork 0
forked from External/grumble

Remove ctl.go and ctlrpc.go files from the repo.

This commit is contained in:
Mikkel Krautz 2011-11-10 00:48:10 +01:00
parent 90272faad5
commit 83499e9fa1
2 changed files with 0 additions and 166 deletions

92
ctl.go
View file

@ -1,92 +0,0 @@
// 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"
"net/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(Args.CtlNet, Args.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)
}
}

View file

@ -1,74 +0,0 @@
// 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 "errors"
type ControlRPC struct {
}
type KeyValuePair struct {
Id int64
Key string
Value string
}
// Start a server
func (c *ControlRPC) Start(Id int64, out *int64) error {
server, exists := servers[Id]
if !exists {
return errors.New("no such server")
}
_ = server
return nil
}
// Stop a server
func (c *ControlRPC) Stop(Id int64, out *int) error {
server, exists := servers[Id]
if !exists {
return errors.New("no such server")
}
_ = server
return nil
}
// Set SuperUser password
func (c *ControlRPC) SetSuperUserPassword(in *KeyValuePair, out *int64) error {
server, exists := servers[in.Id]
if !exists {
return errors.New("no such server")
}
server.SetSuperUserPassword(in.Value)
*out = in.Id
return nil
}
// Set a config value
func (c *ControlRPC) SetConfig(in *KeyValuePair, out *KeyValuePair) error {
server, exists := servers[in.Id]
if !exists {
return errors.New("no such server")
}
server.cfg.Set(in.Key, in.Value)
server.cfgUpdate <- in
out.Id = in.Id
out.Key = in.Key
out.Value = in.Value
return nil
}
// Get a config value
func (c *ControlRPC) GetConfig(in *KeyValuePair, out *KeyValuePair) error {
server, exists := servers[in.Id]
if !exists {
return errors.New("no such server")
}
out.Id = in.Id
out.Key = in.Key
out.Value = server.cfg.StringValue(in.Key)
return nil
}