| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 | 
							- package app
 
- import (
 
- 	"fmt"
 
- 	"os/exec"
 
- 	"pbx-api-gin/internal/app/ami/action"
 
- 	"pbx-api-gin/internal/app/mysql"
 
- 	"pbx-api-gin/internal/app/stc"
 
- 	"pbx-api-gin/internal/app/stc/active"
 
- 	"pbx-api-gin/internal/app/stc/socket"
 
- 	"pbx-api-gin/pkg/lfshook"
 
- 	"pbx-api-gin/pkg/utils"
 
- 	"strings"
 
- 	"time"
 
- )
 
- func StartApp() {
 
- 	//init mysql
 
- 	mysql.CreateDBInstance()
 
- 	//Get cab number acording to IP
 
- 	IP, err := getIPByCommand()
 
- 	if err != nil {
 
- 		lfshook.NewLogger().Infof("Get IP err :%+v", err)
 
- 	}
 
- 	if IP[len(IP)-2:] == "81" {
 
- 		active.CabNum = "8"
 
- 	} else {
 
- 		active.CabNum = "1"
 
- 	}
 
- 	lfshook.NewLogger().Infof("=================cab number:%s===========", active.CabNum)
 
- 	//init the active status
 
- 	active.Actived = true
 
- 	// 启动带有重连机制的连接管理协程MC1
 
- 	go stc.StartStcConnection(socket.Conn, "1")
 
- 	// 启动带有重连机制的连接管理协程MC8
 
- 	go stc.StartStcConnection(socket.Conn8, "8")
 
- 	// 启动其他服务...
 
- 	// 启动 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 getIPByCommand() (string, error) {
 
- 	cmd := "ifconfig eth0 | grep 'inet addr:' | awk '{print $2}' | cut -d: -f2"
 
- 	out, err := exec.Command("bash", "-c", cmd).CombinedOutput()
 
- 	if err != nil {
 
- 		return "", err
 
- 	}
 
- 	ip := strings.TrimSpace(string(out))
 
- 	if ip == "" {
 
- 		return "", fmt.Errorf("no IP address found")
 
- 	}
 
- 	return ip, nil
 
- }
 
 
  |