index.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package app
  2. import (
  3. "pbx-api-gin/internal/app/ami/action"
  4. "pbx-api-gin/internal/app/stc"
  5. "pbx-api-gin/internal/app/stc/active"
  6. "pbx-api-gin/internal/app/stc/priority"
  7. "pbx-api-gin/internal/app/stc/socket"
  8. "pbx-api-gin/pkg/lfshook"
  9. "pbx-api-gin/pkg/utils"
  10. "time"
  11. )
  12. func StartApp() {
  13. //init mysql
  14. //mysql.CreateDBInstance()
  15. //Get cab number acording to IP
  16. SetMasterCabNum()
  17. //lfshook.NewLogger().Infof("=================cab number:%s========Master:%+v===", active.CabNum, active.Master)
  18. //init the active status
  19. //active.ActivedCab = ""
  20. //get priority
  21. priority.GetPriority()
  22. // 启动带有重连机制的连接管理协程MC1
  23. go stc.StartStcConnection(socket.Conn, "1")
  24. // 启动带有重连机制的连接管理协程MC8
  25. go stc.StartStcConnection(socket.Conn8, "8")
  26. //启动连接到Master服务器,检查Master是否在线
  27. //if active.CabNum == "8" {
  28. // socket.ConnectedMaster = false
  29. // go stc.StartConnectionToSipServer(socket.ConnToMaster)
  30. //}
  31. // 启动其他服务...
  32. // 启动 AMI
  33. go func() {
  34. action.StartAMI(func() {
  35. lfshook.NewLogger().Info("ami callback")
  36. }, []func(event map[string]string){})
  37. }()
  38. //refresh extension status
  39. time.Sleep(3 * time.Second)
  40. utils.ExecCmdAsync("/usr/sbin/asterisk", "-rx", "reload")
  41. }
  42. // Get eth0 IP
  43. func SetMasterCabNum() {
  44. ext, err := socket.IsIPExists("10.0.11.11")
  45. if err != nil {
  46. lfshook.NewLogger().Infof("Check IP :%+v", err)
  47. }
  48. // Init cab number and master role
  49. if !ext {
  50. active.CabNum = "8"
  51. active.Master = false
  52. } else {
  53. active.CabNum = "1"
  54. active.Master = true
  55. }
  56. }