mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
server: rehash on SIGHUP
This commit is contained in:
parent
1812edb2db
commit
ef437348cf
@ -83,6 +83,7 @@ type Server struct {
|
|||||||
rehashMutex sync.Mutex
|
rehashMutex sync.Mutex
|
||||||
accountRegistration *AccountRegistration
|
accountRegistration *AccountRegistration
|
||||||
signals chan os.Signal
|
signals chan os.Signal
|
||||||
|
rehashSignal chan os.Signal
|
||||||
whoWas *WhoWasList
|
whoWas *WhoWasList
|
||||||
isupport *ISupportList
|
isupport *ISupportList
|
||||||
checkIdent bool
|
checkIdent bool
|
||||||
@ -91,7 +92,6 @@ type Server struct {
|
|||||||
var (
|
var (
|
||||||
SERVER_SIGNALS = []os.Signal{
|
SERVER_SIGNALS = []os.Signal{
|
||||||
syscall.SIGINT,
|
syscall.SIGINT,
|
||||||
syscall.SIGHUP, // eventually we expect to use HUP to reload config
|
|
||||||
syscall.SIGTERM,
|
syscall.SIGTERM,
|
||||||
syscall.SIGQUIT,
|
syscall.SIGQUIT,
|
||||||
}
|
}
|
||||||
@ -134,6 +134,7 @@ func NewServer(configFilename string, config *Config) *Server {
|
|||||||
newConns: make(chan clientConn),
|
newConns: make(chan clientConn),
|
||||||
operators: config.Operators(),
|
operators: config.Operators(),
|
||||||
signals: make(chan os.Signal, len(SERVER_SIGNALS)),
|
signals: make(chan os.Signal, len(SERVER_SIGNALS)),
|
||||||
|
rehashSignal: make(chan os.Signal, 1),
|
||||||
whoWas: NewWhoWasList(config.Limits.WhowasEntries),
|
whoWas: NewWhoWasList(config.Limits.WhowasEntries),
|
||||||
checkIdent: config.Server.CheckIdent,
|
checkIdent: config.Server.CheckIdent,
|
||||||
}
|
}
|
||||||
@ -204,6 +205,7 @@ func NewServer(configFilename string, config *Config) *Server {
|
|||||||
|
|
||||||
// Attempt to clean up when receiving these signals.
|
// Attempt to clean up when receiving these signals.
|
||||||
signal.Notify(server.signals, SERVER_SIGNALS...)
|
signal.Notify(server.signals, SERVER_SIGNALS...)
|
||||||
|
signal.Notify(server.rehashSignal, syscall.SIGHUP)
|
||||||
|
|
||||||
server.setISupport()
|
server.setISupport()
|
||||||
|
|
||||||
@ -279,6 +281,13 @@ func (server *Server) Run() {
|
|||||||
server.Shutdown()
|
server.Shutdown()
|
||||||
done = true
|
done = true
|
||||||
|
|
||||||
|
case <-server.rehashSignal:
|
||||||
|
// eventually we expect to use HUP to reload config
|
||||||
|
err := server.rehash()
|
||||||
|
if err != nil {
|
||||||
|
Log.error.Println("Failed to rehash:", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
case conn := <-server.newConns:
|
case conn := <-server.newConns:
|
||||||
go NewClient(server, conn.Conn, conn.IsTLS)
|
go NewClient(server, conn.Conn, conn.IsTLS)
|
||||||
|
|
||||||
@ -874,16 +883,15 @@ func operHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// REHASH
|
// rehash reloads the config and applies the changes from the config file.
|
||||||
func rehashHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
func (server *Server) rehash() error {
|
||||||
// only let one REHASH go on at a time
|
// only let one REHASH go on at a time
|
||||||
server.rehashMutex.Lock()
|
server.rehashMutex.Lock()
|
||||||
|
|
||||||
config, err := LoadConfig(server.configFilename)
|
config, err := LoadConfig(server.configFilename)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
client.Send(nil, server.name, ERR_UNKNOWNERROR, client.nick, "REHASH", fmt.Sprintf("Error rehashing config file: %s", err.Error()))
|
return fmt.Errorf("Error rehashing config file: %s", err.Error())
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO(dan): burst CAP DEL for sasl
|
//TODO(dan): burst CAP DEL for sasl
|
||||||
@ -913,7 +921,7 @@ func rehashHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
|||||||
for _, sClient := range server.clients.ByNick {
|
for _, sClient := range server.clients.ByNick {
|
||||||
for _, tokenline := range newISupportReplies {
|
for _, tokenline := range newISupportReplies {
|
||||||
// ugly trickery ahead
|
// ugly trickery ahead
|
||||||
sClient.Send(nil, client.server.name, RPL_ISUPPORT, append([]string{sClient.nick}, tokenline...)...)
|
sClient.Send(nil, server.name, RPL_ISUPPORT, append([]string{sClient.nick}, tokenline...)...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -931,14 +939,12 @@ func rehashHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
|||||||
server.listenerEventActMutex.Lock()
|
server.listenerEventActMutex.Lock()
|
||||||
if exists {
|
if exists {
|
||||||
// update old listener
|
// update old listener
|
||||||
fmt.Println("refreshing", addr)
|
|
||||||
server.listeners[addr].Events <- ListenerEvent{
|
server.listeners[addr].Events <- ListenerEvent{
|
||||||
Type: UpdateListener,
|
Type: UpdateListener,
|
||||||
NewConfig: tlsListeners[addr],
|
NewConfig: tlsListeners[addr],
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// destroy nonexistent listener
|
// destroy nonexistent listener
|
||||||
fmt.Println("destroying", addr)
|
|
||||||
server.listeners[addr].Events <- ListenerEvent{
|
server.listeners[addr].Events <- ListenerEvent{
|
||||||
Type: DestroyListener,
|
Type: DestroyListener,
|
||||||
}
|
}
|
||||||
@ -953,14 +959,23 @@ func rehashHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
|||||||
_, exists := server.listeners[newaddr]
|
_, exists := server.listeners[newaddr]
|
||||||
if !exists {
|
if !exists {
|
||||||
// make new listener
|
// make new listener
|
||||||
fmt.Println("creating", newaddr)
|
|
||||||
server.createListener(newaddr, tlsListeners)
|
server.createListener(newaddr, tlsListeners)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
server.rehashMutex.Unlock()
|
server.rehashMutex.Unlock()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
client.Send(nil, server.name, RPL_REHASHING, client.nick, "ircd.yaml", "Rehashing")
|
// REHASH
|
||||||
|
func rehashHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
||||||
|
err := server.rehash()
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
client.Send(nil, server.name, RPL_REHASHING, client.nick, "ircd.yaml", "Rehashing")
|
||||||
|
} else {
|
||||||
|
client.Send(nil, server.name, ERR_UNKNOWNERROR, client.nick, "REHASH", err.Error())
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user