add vcs-* fields to debian/control
[debian/orchestra.git] / src / player / signal.go
1 /* signal.go
2  *
3  * Signal Handlers
4  */
5
6 package main
7
8 import (
9         "os/signal"
10         "os"
11         "syscall"
12         "fmt"
13         o "orchestra"
14 )
15
16
17 // handle the signals.  By default, we ignore everything, but the
18 // three terminal signals, HUP, INT, TERM, we want to explicitly
19 // handle.
20 func signalHandler() {
21         for {
22                 sig := <-signal.Incoming
23
24                 ux, ok := sig.(os.UnixSignal)
25                 if !ok {
26                         o.Warn("Couldn't handle signal %s, Coercion failed", sig)
27                         continue
28                 }
29
30                 switch int(ux) {
31                 case syscall.SIGHUP:
32                         o.Warn("Reloading Configuration")
33                         reloadScores <- 1
34                 case syscall.SIGINT:
35                         fmt.Fprintln(os.Stderr, "Interrupt Received - Terminating")
36                         //FIXME: Gentle Shutdown
37                         os.Exit(1)
38                 case syscall.SIGTERM:
39                         fmt.Fprintln(os.Stderr, "Terminate Received - Terminating")
40                         //FIXME: Gentle Shutdown
41                         os.Exit(2)
42                 }
43         }
44
45 }
46
47 func init() {
48         go signalHandler()
49 }