wire up signal handlers for sighup
Cette révision appartient à :
Parent
b6111fb9d9
révision
68e66964a5
3 fichiers modifiés avec 47 ajouts et 0 suppressions
2
main.go
2
main.go
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/ewhal/nyaa/db"
|
||||
"github.com/ewhal/nyaa/router"
|
||||
"github.com/ewhal/nyaa/util/log"
|
||||
"github.com/ewhal/nyaa/util/signals"
|
||||
|
||||
"net/http"
|
||||
"os"
|
||||
|
@ -54,6 +55,7 @@ func main() {
|
|||
}
|
||||
db.ORM, _ = db.GormInit(conf)
|
||||
initI18N()
|
||||
go signals.Handle()
|
||||
RunServer(conf)
|
||||
}
|
||||
}
|
||||
|
|
38
util/signals/unix.go
Fichier normal
38
util/signals/unix.go
Fichier normal
|
@ -0,0 +1,38 @@
|
|||
// +build !win32
|
||||
|
||||
package signals
|
||||
|
||||
import (
|
||||
"github.com/ewhal/nyaa/router"
|
||||
"github.com/ewhal/nyaa/util/log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func handleReload() {
|
||||
log.Info("Got SIGHUP")
|
||||
router.ReloadTemplates()
|
||||
log.Info("reloaded templates")
|
||||
|
||||
}
|
||||
|
||||
// Handle signals
|
||||
// returns when done
|
||||
func Handle() {
|
||||
chnl := make(chan os.Signal)
|
||||
signal.Notify(chnl, syscall.SIGHUP)
|
||||
for {
|
||||
sig, ok := <-chnl
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
switch sig {
|
||||
case syscall.SIGHUP:
|
||||
handleReload()
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
7
util/signals/win32.go
Fichier normal
7
util/signals/win32.go
Fichier normal
|
@ -0,0 +1,7 @@
|
|||
// +build win32
|
||||
|
||||
package signals
|
||||
|
||||
func Handle() {
|
||||
// windows has no sighup LOOOOL, this does nothing
|
||||
}
|
Référencer dans un nouveau ticket