summaryrefslogtreecommitdiffstats
path: root/util/signals/unix.go
blob: f6f40850e58753de4edb134f0eb614842f30cdab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// +build !win32

package signals

import (
	"github.com/NyaaPantsu/nyaa/router"
	"github.com/NyaaPantsu/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, os.Interrupt)
	for {
		sig, ok := <-chnl
		if !ok {
			break
		}
		switch sig {
		case syscall.SIGHUP:
			handleReload()
			break
		case os.Interrupt:
			interrupted()
			return
		default:
			break
		}
	}
}

// unix implementation of interrupt
// called in interrupted()
func handleInterrupt() {
	// XXX: put unix specific cleanup here as needed
}