bug fix and shell optimization

This commit is contained in:
Gordon 2021-09-13 15:48:19 +08:00
parent c1bcadd9ed
commit 649bc5657e
14 changed files with 72 additions and 42 deletions

View File

@ -70,12 +70,12 @@ credential:
rpcport: rpcport:
openImUserPort: [ 10100,10101 ] openImUserPort: [ 10100 ]
openImFriendPort: [ 10200,10201 ] openImFriendPort: [ 10200 ]
openImOfflineMessagePort: [ 10300 ] openImOfflineMessagePort: [ 10300 ]
openImOnlineRelayPort: [ 10400 ] openImOnlineRelayPort: [ 10400 ]
openImGroupPort: [ 10500 ,10501 ] openImGroupPort: [ 10500 ]
openImAuthPort: [ 10600, 10601 ] openImAuthPort: [ 10600 ]
openImPushPort: [ 10700 ] openImPushPort: [ 10700 ]

2
go.mod
View File

@ -36,9 +36,9 @@ require (
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 // indirect github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 // indirect
go.etcd.io/etcd v0.0.0-20200402134248-51bdeb39e698 go.etcd.io/etcd v0.0.0-20200402134248-51bdeb39e698
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b
golang.org/x/tools v0.0.0-20210106214847-113979e3529a // indirect golang.org/x/tools v0.0.0-20210106214847-113979e3529a // indirect
google.golang.org/grpc v1.33.2 google.golang.org/grpc v1.33.2
google.golang.org/protobuf v1.26.0
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
sigs.k8s.io/yaml v1.2.0 // indirect sigs.k8s.io/yaml v1.2.0 // indirect

View File

@ -36,7 +36,7 @@ allPorts=""
if [ $check -ge 1 ]; then if [ $check -ge 1 ]; then
allNewPid=$(ps aux | grep -w ./${msg_gateway_name} | grep -v grep | awk '{print $2}') allNewPid=$(ps aux | grep -w ./${msg_gateway_name} | grep -v grep | awk '{print $2}')
for i in $allNewPid; do for i in $allNewPid; do
ports=$(netstat -netulp | grep ${i} | awk '{print $4}' | awk -F '[:]' '{print $NF}') ports=$(netstat -netulp | grep -w ${i} | awk '{print $4}' | awk -F '[:]' '{print $NF}')
allPorts=${allPorts}"$ports " allPorts=${allPorts}"$ports "
done done
echo -e ${SKY_BLUE_PREFIX}"SERVICE START SUCCESS !!!"${COLOR_SUFFIX} echo -e ${SKY_BLUE_PREFIX}"SERVICE START SUCCESS !!!"${COLOR_SUFFIX}

View File

@ -3,27 +3,32 @@
source ./style_info.cfg source ./style_info.cfg
source ./path_info.cfg source ./path_info.cfg
#Check if the service exists #Check if the service exists
#If it is exists,kill this process #If it is exists,kill this process
check=$(ps aux | grep -w ./${msg_transfer_name} | grep -v grep | wc -l) check=`ps aux | grep -w ./${msg_transfer_name} | grep -v grep| wc -l`
if [ $check -eq 1 ]; then if [ $check -eq 1 ]
oldPid=$(ps aux | grep -w ./${msg_transfer_name} | grep -v grep | awk '{print $2}') then
oldPid=`ps aux | grep -w ./${msg_transfer_name} | grep -v grep|awk '{print $2}'`
kill -9 $oldPid kill -9 $oldPid
fi fi
#Waiting port recycling #Waiting port recycling
sleep 1 sleep 1
cd ${msg_transfer_binary_root} cd ${msg_transfer_binary_root}
nohup ./${msg_transfer_name} >>../logs/${msg_transfer_name}.log 2>&1 & nohup ./${msg_transfer_name} >>../logs/${msg_transfer_name}.log 2>&1 &
#Check launched service process #Check launched service process
check=$(ps aux | grep -w ./${msg_transfer_name} | grep -v grep | wc -l) check=`ps aux | grep -w ./${msg_transfer_name} | grep -v grep| wc -l`
if [ $check -eq 1 ]; then if [ $check -eq 1 ]
newPid=$(ps aux | grep -w ./${msg_transfer_name} | grep -v grep | awk '{print $2}') then
ports=$(netstat -netulp | grep ${newPid} | awk '{print $4}' | awk -F '[:]' '{print $NF}') newPid=`ps aux | grep -w ./${msg_transfer_name} | grep -v grep|awk '{print $2}'`
allPorts="" ports=`netstat -netulp | grep -w ${newPid}|awk '{print $4}'|awk -F '[:]' '{print $NF}'`
allPorts=""
for i in $ports; do for i in $ports ;
do
allPorts=${allPorts}"$i " allPorts=${allPorts}"$i "
done done
echo -e ${SKY_BLUE_PREFIX}"SERVICE START SUCCESS !!!"${COLOR_SUFFIX} echo -e ${SKY_BLUE_PREFIX}"SERVICE START SUCCESS !!!"${COLOR_SUFFIX}
echo -e ${SKY_BLUE_PREFIX}"SERVICE_NAME: "${COLOR_SUFFIX}${YELLOW_PREFIX}${msg_transfer_name}${COLOR_SUFFIX} echo -e ${SKY_BLUE_PREFIX}"SERVICE_NAME: "${COLOR_SUFFIX}${YELLOW_PREFIX}${msg_transfer_name}${COLOR_SUFFIX}
echo -e ${SKY_BLUE_PREFIX}"PID: "${COLOR_SUFFIX}${YELLOW_PREFIX}${newPid}${COLOR_SUFFIX} echo -e ${SKY_BLUE_PREFIX}"PID: "${COLOR_SUFFIX}${YELLOW_PREFIX}${newPid}${COLOR_SUFFIX}

View File

@ -4,6 +4,8 @@ source ./style_info.cfg
source ./path_info.cfg source ./path_info.cfg
source ./function.sh source ./function.sh
list1=$(cat $config_path | grep openImPushPort | awk -F '[:]' '{print $NF}') list1=$(cat $config_path | grep openImPushPort | awk -F '[:]' '{print $NF}')
list_to_string $list1 list_to_string $list1
rpc_ports=($ports_array) rpc_ports=($ports_array)
@ -23,11 +25,12 @@ for ((i = 0; i < ${#rpc_ports[@]}; i++)); do
nohup ./${push_name} -port ${rpc_ports[$i]} >>../logs/${push_name}.log 2>&1 & nohup ./${push_name} -port ${rpc_ports[$i]} >>../logs/${push_name}.log 2>&1 &
done done
sleep 1
#Check launched service process #Check launched service process
check=$(ps aux | grep -w ./${push_name} | grep -v grep | wc -l) check=$(ps aux | grep -w ./${push_name} | grep -v grep | wc -l)
if [ $check -eq 1 ]; then if [ $check -eq 1 ]; then
newPid=$(ps aux | grep -w ./${push_name} | grep -v grep | awk '{print $2}') newPid=$(ps aux | grep -w ./${push_name} | grep -v grep | awk '{print $2}')
ports=$(netstat -netulp | grep ${newPid} | awk '{print $4}' | awk -F '[:]' '{print $NF}') ports=$(netstat -netulp | grep -w ${newPid} | awk '{print $4}' | awk -F '[:]' '{print $NF}')
allPorts="" allPorts=""
for i in $ports; do for i in $ports; do

View File

@ -2,6 +2,7 @@ package db
import ( import (
"Open_IM/src/common/config" "Open_IM/src/common/config"
"Open_IM/src/common/log"
"fmt" "fmt"
"github.com/jinzhu/gorm" "github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mysql" _ "github.com/jinzhu/gorm/dialects/mysql"
@ -15,10 +16,13 @@ type mysqlDB struct {
} }
func initMysqlDB() { func initMysqlDB() {
//When there is no open IM database, connect to the mysql built-in database to create openIM database
dsn := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local", dsn := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local",
config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], "mysql") config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], "mysql")
db, err := gorm.Open("mysql", dsn) db, err := gorm.Open("mysql", dsn)
if err != nil { if err != nil {
log.Error("", "", dsn)
panic(err) panic(err)
} }

View File

@ -37,7 +37,7 @@ func InsertMessageToChatLog(msgData pbMsg.WSToMsgSvrChatMsg) error {
MsgId: msgData.MsgID, MsgId: msgData.MsgID,
SendID: msgData.SendID, SendID: msgData.SendID,
RecvID: msgData.RecvID, RecvID: msgData.RecvID,
SendTime: utils.UnixSecondToTime(msgData.SendTime), SendTime: utils.UnixNanoSecondToTime(msgData.SendTime),
SessionType: msgData.SessionType, SessionType: msgData.SessionType,
ContentType: msgData.ContentType, ContentType: msgData.ContentType,
MsgFrom: msgData.MsgFrom, MsgFrom: msgData.MsgFrom,

View File

@ -59,7 +59,7 @@ func (ws *WServer) readMsg(conn *websocket.Conn) {
for { for {
msgType, msg, err := conn.ReadMessage() msgType, msg, err := conn.ReadMessage()
if err != nil { if err != nil {
log.ErrorByKv("WS ReadMsg error", "", "userIP", conn.RemoteAddr().String(), "userUid", ws.getUserUid(conn), "error", err, "conn", conn) log.ErrorByKv("WS ReadMsg error", "", "userIP", conn.RemoteAddr().String(), "userUid", ws.getUserUid(conn), "error", err)
ws.delUserConn(conn) ws.delUserConn(conn)
return return
} else { } else {

View File

@ -109,6 +109,7 @@ func (mc *HistoryConsumerHandler) ConsumeClaim(sess sarama.ConsumerGroupSession,
for msg := range claim.Messages() { for msg := range claim.Messages() {
log.InfoByKv("kafka get info to mongo", "", "msgTopic", msg.Topic, "msgPartition", msg.Partition, "chat", string(msg.Value)) log.InfoByKv("kafka get info to mongo", "", "msgTopic", msg.Topic, "msgPartition", msg.Partition, "chat", string(msg.Value))
mc.msgHandle[msg.Topic](msg.Value, string(msg.Key)) mc.msgHandle[msg.Topic](msg.Value, string(msg.Key))
sess.MarkMessage(msg, "")
} }
return nil return nil
} }

View File

@ -69,6 +69,7 @@ func (pc *PersistentConsumerHandler) ConsumeClaim(sess sarama.ConsumerGroupSessi
for msg := range claim.Messages() { for msg := range claim.Messages() {
log.InfoByKv("kafka get info to mysql", "", "msgTopic", msg.Topic, "msgPartition", msg.Partition, "chat", string(msg.Value)) log.InfoByKv("kafka get info to mysql", "", "msgTopic", msg.Topic, "msgPartition", msg.Partition, "chat", string(msg.Value))
pc.msgHandle[msg.Topic](msg.Value, string(msg.Key)) pc.msgHandle[msg.Topic](msg.Value, string(msg.Key))
sess.MarkMessage(msg, "")
} }
return nil return nil
} }

View File

@ -2,6 +2,7 @@ package rpcChat
import ( import (
"context" "context"
"github.com/garyburd/redigo/redis"
commonDB "Open_IM/src/common/db" commonDB "Open_IM/src/common/db"
"Open_IM/src/common/log" "Open_IM/src/common/log"
@ -23,8 +24,12 @@ func (rpc *rpcChat) GetNewSeq(_ context.Context, in *pbMsg.GetNewSeqReq) (*pbMsg
resp.ErrMsg = "" resp.ErrMsg = ""
return resp, err return resp, err
} else { } else {
log.ErrorByKv("getSeq from redis error", in.OperationID, "args", in.String(), "err", err.Error()) if err == redis.ErrNil {
resp.Seq = 0 resp.Seq = 0
} else {
log.ErrorByKv("getSeq from redis error", in.OperationID, "args", in.String(), "err", err.Error())
resp.Seq = -1
}
resp.ErrCode = 0 resp.ErrCode = 0
resp.ErrMsg = "" resp.ErrMsg = ""
return resp, nil return resp, nil

View File

@ -13,7 +13,7 @@ func (s *groupServer) GetGroupApplicationList(_ context.Context, pb *group.GetGr
reply, err := im_mysql_model.GetGroupApplicationList(pb.UID) reply, err := im_mysql_model.GetGroupApplicationList(pb.UID)
if err != nil { if err != nil {
log.Error("", "", "rpc GetGroupApplicationList call..., im_mysql_model.GetGroupApplicationList fail [uid: %s] [err: %s]", pb.UID, err.Error()) log.Error("", "", "rpc GetGroupApplicationList call..., im_mysql_model.GetGroupApplicationList fail [uid: %s] [err: %s]", pb.UID, err.Error())
return nil, err return &group.GetGroupApplicationListResp{ErrCode: 701, ErrMsg: "GetGroupApplicationList failed"}, nil
} }
log.Info("", "", "rpc GetGroupApplicationList call..., im_mysql_model.GetGroupApplicationList") log.Info("", "", "rpc GetGroupApplicationList call..., im_mysql_model.GetGroupApplicationList")

View File

@ -14,7 +14,7 @@ func (s *groupServer) GroupApplicationResponse(_ context.Context, pb *group.Grou
reply, err := im_mysql_model.GroupApplicationResponse(pb) reply, err := im_mysql_model.GroupApplicationResponse(pb)
if err != nil { if err != nil {
log.Error("", "", "rpc GroupApplicationResponse call..., im_mysql_model.GroupApplicationResponse fail [pb: %s] [err: %s]", pb.String(), err.Error()) log.Error("", "", "rpc GroupApplicationResponse call..., im_mysql_model.GroupApplicationResponse fail [pb: %s] [err: %s]", pb.String(), err.Error())
return nil, err return &group.GroupApplicationResponseResp{ErrCode: 702, ErrMsg: "rpc GroupApplicationResponse failed"}, nil
} }
if pb.HandleResult == 1 { if pb.HandleResult == 1 {

View File

@ -41,11 +41,22 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
} }
if RpcResp.ErrorCode != 0 { if RpcResp.ErrorCode != 0 {
log.ErrorByKv("get friend list rpc server failed", req.OperationID, "err", err.Error(), "req", req.String()) log.ErrorByKv("get friend list rpc server failed", req.OperationID, "err", err.Error(), "req", req.String())
}
self, err := im_mysql_model.FindUserByUID(claims.UID)
if err != nil {
log.ErrorByKv("get self info failed", req.OperationID, "err", err.Error(), "req", req.String())
}
var name, faceUrl string
if self != nil {
name, faceUrl = self.Name, self.Icon
} }
for _, v := range RpcResp.Data { for _, v := range RpcResp.Data {
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{ logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
SendID: claims.UID, SendID: claims.UID,
RecvID: v.Uid, RecvID: v.Uid,
SenderNickName: name,
SenderFaceURL: faceUrl,
Content: claims.UID + "'s info has changed", Content: claims.UID + "'s info has changed",
SendTime: utils.GetCurrentTimestampBySecond(), SendTime: utils.GetCurrentTimestampBySecond(),
MsgFrom: constant.SysMsgType, MsgFrom: constant.SysMsgType,