1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-08-02 16:08:31 +00:00

Close server on SIGUSR1, 'kickclients' for rebalancing

This commit is contained in:
Kane York 2015-11-19 17:49:48 -08:00
parent 62c9659430
commit 38972364fb
3 changed files with 93 additions and 6 deletions

View file

@ -7,6 +7,7 @@ import (
"github.com/gorilla/websocket"
"runtime"
"strings"
"strconv"
)
func commandLineConsole() {
@ -88,6 +89,41 @@ func commandLineConsole() {
return "Usage: authorizeeveryone [ on | off ]", nil
})
shell.Register("kickclients", func(args ...string) (string, error) {
if len(args) == 0 {
return "Please enter either a count or a fraction of clients to kick.", nil
}
input, err := strconv.ParseFloat(args[0], 64)
if err != nil {
return "Argument must be a number", err
}
var count int
if input >= 1 {
count = int(input)
} else {
server.GlobalSubscriptionLock.RLock()
count = int(float64(len(server.GlobalSubscriptionInfo)) * input)
server.GlobalSubscriptionLock.RUnlock()
}
msg := server.ClientMessage{ Arguments: &server.CloseRebalance }
server.GlobalSubscriptionLock.RLock()
defer server.GlobalSubscriptionLock.RUnlock()
kickCount := 0
for i, cl := range server.GlobalSubscriptionInfo {
if i >= count {
break
}
select {
case cl.MessageChannel <- msg:
case <-cl.MsgChannelIsDone:
}
kickCount++
}
return fmt.Sprintf("Kicked %d clients", kickCount), nil
})
shell.Register("panic", func(args ...string) (string, error) {
go func() {
panic("requested panic")