Run is a blocking method. It runs the kite server and then accepts requests asynchronously. It supports graceful restart via SIGUSR2.
()
| 16 | // Run is a blocking method. It runs the kite server and then accepts requests |
| 17 | // asynchronously. It supports graceful restart via SIGUSR2. |
| 18 | func (k *Kite) Run() { |
| 19 | if os.Getenv("KITE_VERSION") != "" { |
| 20 | fmt.Println(k.Kite().Version) |
| 21 | os.Exit(0) |
| 22 | } |
| 23 | |
| 24 | // An error string equivalent to net.errClosing for using with http.Serve() |
| 25 | // during a graceful exit. Needed to declare here again because it is not |
| 26 | // exported by "net" package. |
| 27 | const errClosing = "use of closed network connection" |
| 28 | |
| 29 | err := k.listenAndServe() |
| 30 | if err != nil { |
| 31 | if strings.Contains(err.Error(), errClosing) { |
| 32 | // The server is closed by Close() method |
| 33 | k.Log.Info("Kite server is closed.") |
| 34 | return |
| 35 | } |
| 36 | k.Log.Fatal(err.Error()) |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | // Close stops the server and the kontrol client instance. |
| 41 | func (k *Kite) Close() { |