...
1 package server
2
3 import (
4 "fmt"
5 "golang.conradwood.net/apis/common"
6 "golang.conradwood.net/apis/goeasyops"
7 "golang.conradwood.net/go-easyops/utils"
8 "os"
9 "sync"
10 "time"
11 )
12
13 var (
14 stoplock sync.Mutex
15 was_stop_requested = false
16 )
17
18 func IsStopping() bool {
19 return was_stop_requested
20 }
21
22 func stop_requested() {
23 stoplock.Lock()
24 if was_stop_requested {
25 stoplock.Unlock()
26 return
27 }
28 was_stop_requested = true
29 stoplock.Unlock()
30 fmt.Printf("[go-easyops] server received stop request and is shutting down\n")
31 SetHealth(common.Health_STOPPING)
32 go func() {
33 for {
34
35 x := make(chan bool, 10)
36 stopping(x)
37 for ActiveRPCs() != 0 {
38 time.Sleep(time.Duration(1) * time.Second)
39 response := &goeasyops.StopUpdate{Stopping: true, ActiveRPCs: uint32(ActiveRPCs())}
40 b, err := utils.MarshalBytes(response)
41 if err != nil {
42 fmt.Printf("[go-easyops] unable to marshal stop response: %s\n", err)
43 } else {
44 _, err = unixipc_srv.Send("STOPREQUEST", b)
45 if err != nil {
46 fmt.Printf("[go-easyops] failed to send update to stoprequest: %s\n", err)
47 }
48 }
49
50 }
51 os.Exit(0)
52 }
53 }()
54 }
55
View as plain text