mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 12:00:55 +00:00
Added method to register Pre/Post signal handlers
This commit is contained in:
parent
fc4801494d
commit
eb50221a15
@ -162,9 +162,7 @@ func (srv *Server) handleSignals() {
|
||||
|
||||
signal.Notify(
|
||||
srv.sigChan,
|
||||
syscall.SIGHUP,
|
||||
syscall.SIGINT,
|
||||
syscall.SIGTERM,
|
||||
hookableSignals...,
|
||||
)
|
||||
|
||||
pid := syscall.Getpid()
|
||||
@ -290,3 +288,19 @@ func (srv *Server) fork() (err error) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// RegisterSignalHook registers a function to be run PreSignal or PostSignal for a given signal.
|
||||
func (srv *Server) RegisterSignalHook(ppFlag int, sig os.Signal, f func()) (err error) {
|
||||
if ppFlag != PreSignal && ppFlag != PostSignal {
|
||||
err = fmt.Errorf("Invalid ppFlag argument. Must be either grace.PreSignal or grace.PostSignal.")
|
||||
return
|
||||
}
|
||||
for _, s := range hookableSignals {
|
||||
if s == sig {
|
||||
srv.SignalHooks[ppFlag][sig] = append(srv.SignalHooks[ppFlag][sig], f)
|
||||
return
|
||||
}
|
||||
}
|
||||
err = fmt.Errorf("Signal '%v' is not supported.", sig)
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user