The Ripple API https://ripple.moe/api/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

startuato_linux.go 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // +build !windows
  2. package main
  3. import (
  4. "fmt"
  5. "log"
  6. "net"
  7. "time"
  8. "github.com/rcrowley/goagain"
  9. "github.com/valyala/fasthttp"
  10. "zxq.co/ripple/rippleapi/common"
  11. "zxq.co/ripple/schiavolib"
  12. )
  13. func startuato(hn fasthttp.RequestHandler) {
  14. conf, _ := common.Load()
  15. // Inherit a net.Listener from our parent process or listen anew.
  16. l, err := goagain.Listener()
  17. if nil != err {
  18. // Listen on a TCP or a UNIX domain socket (TCP here).
  19. if conf.Unix {
  20. l, err = net.Listen("unix", conf.ListenTo)
  21. } else {
  22. l, err = net.Listen("tcp", conf.ListenTo)
  23. }
  24. if nil != err {
  25. schiavo.Bunker.Send(err.Error())
  26. log.Fatalln(err)
  27. }
  28. schiavo.Bunker.Send(fmt.Sprint("LISTENINGU STARTUATO ON ", l.Addr()))
  29. // Accept connections in a new goroutine.
  30. go fasthttp.Serve(l, hn)
  31. } else {
  32. // Resume accepting connections in a new goroutine.
  33. schiavo.Bunker.Send(fmt.Sprint("LISTENINGU RESUMINGU ON ", l.Addr()))
  34. go fasthttp.Serve(l, hn)
  35. // Kill the parent, now that the child has started successfully.
  36. if err := goagain.Kill(); nil != err {
  37. schiavo.Bunker.Send(err.Error())
  38. log.Fatalln(err)
  39. }
  40. }
  41. // Block the main goroutine awaiting signals.
  42. if _, err := goagain.Wait(l); nil != err {
  43. schiavo.Bunker.Send(err.Error())
  44. log.Fatalln(err)
  45. }
  46. // Do whatever's necessary to ensure a graceful exit like waiting for
  47. // goroutines to terminate or a channel to become closed.
  48. //
  49. // In this case, we'll simply stop listening and wait one second.
  50. if err := l.Close(); nil != err {
  51. schiavo.Bunker.Send(err.Error())
  52. log.Fatalln(err)
  53. }
  54. if err := db.Close(); err != nil {
  55. schiavo.Bunker.Send(err.Error())
  56. log.Fatalln(err)
  57. }
  58. time.Sleep(time.Second * 1)
  59. }