| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package app
- import (
- "os/exec"
- "pbx-api-gin/internal/app/ami/action"
- "pbx-api-gin/internal/app/stc"
- "pbx-api-gin/internal/app/stc/active"
- "pbx-api-gin/internal/app/stc/priority"
- "pbx-api-gin/internal/app/stc/socket"
- "pbx-api-gin/pkg/lfshook"
- "pbx-api-gin/pkg/utils"
- "time"
- )
- func StartApp() {
- //init mysql
- //mysql.CreateDBInstance()
- //Get cab number acording to IP
- _, err := SetMasterCabNum()
- if err != nil {
- lfshook.NewLogger().Infof("Set Role and Cab Num err :%+v", err)
- }
- lfshook.NewLogger().Infof("=================cab number:%s========Master:%+v===", active.CabNum, active.Master)
- //init the active status
- active.ActivedCab = ""
- //get priority
- priority.GetPriority()
- // 启动带有重连机制的连接管理协程MC1
- go stc.StartStcConnection(socket.Conn, "1")
- // 启动带有重连机制的连接管理协程MC8
- go stc.StartStcConnection(socket.Conn8, "8")
- //启动连接到Master服务器,检查Master是否在线
- if active.CabNum == "8" {
- socket.ConnectedMaster = false
- go stc.StartConnectionToSipServer(socket.ConnToMaster)
- }
- // 启动其他服务...
- // 启动 AMI
- go func() {
- action.StartAMI(func() {
- lfshook.NewLogger().Info("ami callback")
- }, []func(event map[string]string){})
- }()
- //refresh extension status
- time.Sleep(3 * time.Second)
- utils.ExecCmdAsync("/usr/sbin/asterisk", "-rx", "reload")
- }
- // Get eth0 IP
- func SetMasterCabNum() (string, error) {
- cmd := "ip a |grep 10.0.11.11" //check Master IP
- out, _ := exec.Command("bash", "-c", cmd).CombinedOutput()
- // Init cab number and master role
- if len(out) == 0 {
- active.Master = false
- active.CabNum = "8"
- } else {
- active.Master = true
- active.CabNum = "1"
- }
- return string(out), nil
- }
|