|
@@ -89,7 +89,7 @@ type endlessServer struct {
|
|
|
NewServer returns an intialized endlessServer Object. Calling Serve on it will
|
|
|
actually "start" the server.
|
|
|
*/
|
|
|
-func NewServer(addr string, handler http.Handler) (srv *endlessServer) {
|
|
|
+func NewServer(addr string, handler http.Handler, fn func()) (srv *endlessServer) {
|
|
|
runningServerReg.Lock()
|
|
|
defer runningServerReg.Unlock()
|
|
|
if !flag.Parsed() {
|
|
@@ -109,7 +109,9 @@ func NewServer(addr string, handler http.Handler) (srv *endlessServer) {
|
|
|
isChild: isChild,
|
|
|
SignalHooks: map[int]map[os.Signal][]func(){
|
|
|
PRE_SIGNAL: map[os.Signal][]func(){
|
|
|
- syscall.SIGHUP: []func(){},
|
|
|
+ syscall.SIGHUP: []func(){
|
|
|
+ fn,
|
|
|
+ },
|
|
|
syscall.SIGUSR1: []func(){},
|
|
|
syscall.SIGUSR2: []func(){},
|
|
|
syscall.SIGINT: []func(){},
|
|
@@ -146,8 +148,8 @@ ListenAndServe listens on the TCP network address addr and then calls Serve
|
|
|
with handler to handle requests on incoming connections. Handler is typically
|
|
|
nil, in which case the DefaultServeMux is used.
|
|
|
*/
|
|
|
-func ListenAndServe(addr string, handler http.Handler) error {
|
|
|
- server := NewServer(addr, handler)
|
|
|
+func ListenAndServe(addr string, handler http.Handler, fn func()) error {
|
|
|
+ server := NewServer(addr, handler, fn)
|
|
|
return server.ListenAndServe()
|
|
|
}
|
|
|
|
|
@@ -158,8 +160,8 @@ private key for the server must be provided. If the certificate is signed by a
|
|
|
certificate authority, the certFile should be the concatenation of the server's
|
|
|
certificate followed by the CA's certificate.
|
|
|
*/
|
|
|
-func ListenAndServeTLS(addr string, certFile string, keyFile string, handler http.Handler) error {
|
|
|
- server := NewServer(addr, handler)
|
|
|
+func ListenAndServeTLS(addr string, certFile string, keyFile string, handler http.Handler, destoryfn func()) error {
|
|
|
+ server := NewServer(addr, handler, destoryfn)
|
|
|
return server.ListenAndServeTLS(certFile, keyFile)
|
|
|
}
|
|
|
|
|
@@ -418,7 +420,7 @@ func (srv *endlessServer) hammerTime(d time.Duration) {
|
|
|
func (srv *endlessServer) fork() (err error) {
|
|
|
runningServerReg.Lock()
|
|
|
defer runningServerReg.Unlock()
|
|
|
-
|
|
|
+
|
|
|
// only one server isntance should fork!
|
|
|
if runningServersForked {
|
|
|
return errors.New("Another process already forked. Ignoring this one.")
|