mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-26 13:59:44 +01:00
Merge pull request #12 from jlatt/on-restart
notify clients when the server shuts down
This commit is contained in:
commit
5e6fa07975
@ -16,6 +16,7 @@ import (
|
|||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -57,7 +58,7 @@ func NewServer(config *Config) *Server {
|
|||||||
timeout: make(chan *Client, 16),
|
timeout: make(chan *Client, 16),
|
||||||
}
|
}
|
||||||
|
|
||||||
signal.Notify(server.signals, os.Interrupt, os.Kill)
|
signal.Notify(server.signals, syscall.SIGINT, syscall.SIGHUP)
|
||||||
|
|
||||||
server.loadChannels()
|
server.loadChannels()
|
||||||
|
|
||||||
@ -138,14 +139,20 @@ func (server *Server) processCommand(cmd Command) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (server *Server) Shutdown() {
|
||||||
|
server.db.Close()
|
||||||
|
for _, client := range server.clients {
|
||||||
|
client.Reply(RplNotice(server, client, "shutting down"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (server *Server) Run() {
|
func (server *Server) Run() {
|
||||||
done := false
|
done := false
|
||||||
for !done {
|
for !done {
|
||||||
select {
|
select {
|
||||||
case <-server.signals:
|
case <-server.signals:
|
||||||
server.db.Close()
|
server.Shutdown()
|
||||||
done = true
|
done = true
|
||||||
continue
|
|
||||||
|
|
||||||
case conn := <-server.newConns:
|
case conn := <-server.newConns:
|
||||||
NewClient(server, conn)
|
NewClient(server, conn)
|
||||||
|
Loading…
Reference in New Issue
Block a user