mirror of
https://github.com/mumble-voip/grumble.git
synced 2025-12-19 21:59:59 -08:00
Abstract away signal handling.
This commit is contained in:
parent
4e20111ff6
commit
b4e1155855
4 changed files with 44 additions and 18 deletions
6
Makefile
6
Makefile
|
|
@ -52,6 +52,12 @@ GOFILES = \
|
||||||
ctlrpc.go \
|
ctlrpc.go \
|
||||||
ctl.go
|
ctl.go
|
||||||
|
|
||||||
|
ifeq ($(GOOS),windows)
|
||||||
|
GOFILES += signal_windows.go
|
||||||
|
else
|
||||||
|
GOFILES += signal_unix.go
|
||||||
|
endif
|
||||||
|
|
||||||
.PHONY: grumble
|
.PHONY: grumble
|
||||||
grumble: pkg
|
grumble: pkg
|
||||||
$(GC) $(GCFLAGS) -o $(TARG).$(O) $(GOFILES)
|
$(GC) $(GCFLAGS) -o $(TARG).$(O) $(GOFILES)
|
||||||
|
|
|
||||||
19
grumble.go
19
grumble.go
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"sqlite"
|
"sqlite"
|
||||||
|
|
@ -233,6 +232,7 @@ func main() {
|
||||||
|
|
||||||
if len(servers) > 0 {
|
if len(servers) > 0 {
|
||||||
ticker := time.NewTicker(10e9) // 10 secs
|
ticker := time.NewTicker(10e9) // 10 secs
|
||||||
|
go SignalHandler()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
|
|
@ -243,23 +243,6 @@ func main() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case sig := <-signal.Incoming:
|
|
||||||
if sig != signal.SIGINT && sig != signal.SIGTERM {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
for sid, s := range servers {
|
|
||||||
err := s.FreezeToFile(filepath.Join(*datadir, fmt.Sprintf("%v", sid)))
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Unable to freeze server %v: %s", sid, err.String())
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Printf("Server %v frozen", sid)
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
29
signal_unix.go
Normal file
29
signal_unix.go
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
// 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 (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os/signal"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SignalHandler() {
|
||||||
|
for {
|
||||||
|
sig := <-signal.Incoming
|
||||||
|
if sig != signal.SIGINT && sig != signal.SIGTERM {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for sid, s := range servers {
|
||||||
|
err := s.FreezeToFile(filepath.Join(*datadir, fmt.Sprintf("%v", sid)))
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Unable to freeze server %v: %s", sid, err.String())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
log.Printf("Server %v frozen", sid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
8
signal_windows.go
Normal file
8
signal_windows.go
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
// 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
|
||||||
|
|
||||||
|
func SignalHandler() {
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue