-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_service_nix.go
45 lines (37 loc) · 1022 Bytes
/
run_service_nix.go
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
// +build linux darwin
package main
import (
// "fmt"
"github.com/oliveagle/go-metrics"
"github.com/oliveagle/hickwall/logging"
"net"
"os"
"os/signal"
"syscall"
"time"
)
func run(idDebug bool) (string, error) {
// Set up channel on which to send signal notifications.
// We must use a buffered channel or risk missing the signal
// if we're not ready to receive when the signal is sent.
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt, os.Kill, syscall.SIGTERM)
tick := time.Tick(1 * time.Second)
// go service_process()
addr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:2003")
go metrics.Graphite(metrics.DefaultRegistry, 1*time.Second, "metrics", addr)
c := metrics.NewCounter()
metrics.Register("foo", c)
for {
select {
case now := <-tick:
c.Inc(47)
logging.Trace("tick: %v", now)
case killSignal := <-interrupt:
if killSignal == os.Interrupt {
return "Daemon was interruped by system signal", nil
}
return "Daemon was killed", nil
}
}
}