diff --git a/.github/ISSUE_TEMPLATE/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE/ISSUE_TEMPLATE.md new file mode 100644 index 000000000..e5d8ed6fa --- /dev/null +++ b/.github/ISSUE_TEMPLATE/ISSUE_TEMPLATE.md @@ -0,0 +1,37 @@ +--- +name: "\U0001F41E Bug" +about: File a bug/issue +title: "[BUG] " +labels: '' +assignees: '' + +--- + +<!-- +Note: Please search to see if an issue already exists for the bug you encountered. +--> + +### Environment: +<!-- linux? windows? or Mac? +Example: +- OS: Ubuntu 20.04 --> + +### Physical Memory Capacity: +<!-- 8G or above is better --> + +### Docker Image: +<!-- Did you pull the docker image before execute docker images --> + +### Code Version: +<!-- Did you pull code from github? Make sure the code is up to date--> + +### Component installation: +<!-- Has etcd, mysql, mongodb, redis or Kafka been installed on the server before Open-IM-Server deployment--> + + +### Log File: +<!-- view log file(logs/openIM.log) content. --> + + +### screenshot: +<!----> diff --git a/.github/ISSUE_TEMPLATE/deployment-issues.md b/.github/ISSUE_TEMPLATE/deployment-issues.md new file mode 100644 index 000000000..57d7cbcb7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/deployment-issues.md @@ -0,0 +1,36 @@ +--- +name: Deployment issues +about: Deployment issues +title: '' +labels: '' +assignees: '' + +--- + +If you are deploying OpenIM for the first time + + + +``` +git clone https://github.com/OpenIMSDK/Open-IM-Server.git --recursive +``` + +screenshot here + +``` +cd Open-IM-Server/script ; chmod +x *.sh ; ./env_check.sh +``` + +screenshot here + +``` +cd .. ; docker-compose up -d +``` + +screenshot here + +``` +cd script ; ./docker_check_service.sh +``` + +screenshot here diff --git a/.github/ISSUE_TEMPLATE/update-.md b/.github/ISSUE_TEMPLATE/update-.md new file mode 100644 index 000000000..ba8da7270 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/update-.md @@ -0,0 +1,38 @@ +--- +name: 'update ' +about: update docker image +title: update docker image +labels: '' +assignees: '' + +--- + +``` +cd Open-IM-Server ; docker-compose down +``` + +screenshot here + +``` +git pull +``` + +screenshot here + +``` +docker-compose pull +``` + +screenshot here + +``` +chmod +x script/*.sh ; docker-compose up -d +``` + +screenshot here + +``` +cd script ; ./docker_check_service.sh +``` + +screenshot here diff --git a/.gitignore b/.gitignore index e4b74c4e9..3390267f4 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ out-test .github .idea + deploy/open_im_demo deploy/open_im_api deploy/open_im_msg_gateway diff --git a/README.md b/README.md index ad3aa2129..4964bacb5 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,7 @@ All images are available at https://hub.docker.com/r/lyt1123/open_im_server 4. Start docker-compose with one click(Docker automatically pulls all images) ``` + cd Open-IM-Server docker-compose up -d ``` @@ -99,6 +100,7 @@ All images are available at https://hub.docker.com/r/lyt1123/open_im_server ``` ./docker_check_service.sh + ./check_all.sh ``` ![OpenIMServersondockerpng](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/Open-IM-Servers-on-docker.png) diff --git a/cmd/open_im_api/main.go b/cmd/open_im_api/main.go index 58378e119..a7deb7dbd 100644 --- a/cmd/open_im_api/main.go +++ b/cmd/open_im_api/main.go @@ -79,6 +79,7 @@ func main() { thirdGroup := r.Group("/third") { thirdGroup.POST("/tencent_cloud_storage_credential", apiThird.TencentCloudStorageCredential) + thirdGroup.POST("/ali_oss_credential", apiThird.AliOSSCredential) thirdGroup.POST("/minio_storage_credential", apiThird.MinioStorageCredential) thirdGroup.POST("/minio_upload", apiThird.MinioUploadFile) } @@ -119,13 +120,9 @@ func main() { officeGroup.POST("/send_msg_to_tag", office.SendMsg2Tag) officeGroup.POST("/get_send_tag_log", office.GetTagSendLogs) } - apiThird.MinioInit() log.NewPrivateLog("api") ginPort := flag.Int("port", 10000, "get ginServerPort from cmd,default 10000 as port") flag.Parse() - err := r.Run(":" + strconv.Itoa(*ginPort)) - if err != nil { - log.NewError("", utils.GetSelfFuncName(), "start gin failed", err.Error()) - } + r.Run(":" + strconv.Itoa(*ginPort)) } diff --git a/config/config.yaml b/config/config.yaml index 4f1c79279..7d864283c 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -19,7 +19,8 @@ mysql: dbMaxLifeTime: 120 mongo: - dbAddress: [ 127.0.0.1:37017 ] #redis地址 目前仅支持单机,默认即可 + dbUri: ""#当dbUri值不为空则直接使用该值 + dbAddress: [ 127.0.0.1:37017 ] #mongo地址 目前仅支持单机,默认即可 dbDirect: false dbTimeout: 10 dbDatabase: openIM #mongo db 默认即可 @@ -91,9 +92,20 @@ credential: #腾讯cos,发送图片、视频、文件时需要,请自行申 minio: #MinIO 发送图片、视频、文件时需要,请自行申请后替换,必须修改。 客户端初始化InitSDK,中 object_storage参数为minio bucket: openim location: us-east-1 - endpoint: http://43.128.5.63:9000 + endpoint: http://127.0.0.1:9000 accessKeyID: user12345 secretAccessKey: key12345 + ali: # ali oss + regionID: "oss-cn-beijing" + accessKeyID: "" + accessKeySecret: "" + stsEndpoint: "sts.cn-beijing.aliyun.com" + ossEndpoint: "oss-cn-beijing.aliyuncs.com" + bucket: "bucket1" + finalHost: "http://bucket1.oss-cn-beijing.aliyuncs.com" + stsDurationSeconds: 3600 + OssRoleArn: "acs:ram::xxx:role/xxx" + rpcport: #rpc服务端口 默认即可 @@ -136,7 +148,7 @@ log: rotationTime: 24 remainRotationCount: 3 #日志数量 #日志级别 6表示全都打印,测试阶段建议设置为6 - remainLogLevel: 6 + remainLogLevel: 4 elasticSearchSwitch: false elasticSearchAddr: [ 127.0.0.1:9201 ] elasticSearchUser: "" diff --git a/deploy/config.example.yaml b/deploy/config.example.yaml index f0ae8314e..08d8858e4 100644 --- a/deploy/config.example.yaml +++ b/deploy/config.example.yaml @@ -19,6 +19,7 @@ mysql: dbMaxLifeTime: 120 mongo: + dbUri: ""#当dbUri值不为空则直接使用该值 dbAddress: [ openim_mongo:27017 ] dbDirect: false dbTimeout: 10 diff --git a/docker-compose.yaml b/docker-compose.yaml index f63b3c125..c67203773 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -32,6 +32,7 @@ services: # - MONGO_INITDB_ROOT_USERNAME=openIM # - MONGO_INITDB_ROOT_PASSWORD=openIM + #TZ: Asia/Shanghai restart: always @@ -93,7 +94,7 @@ services: command: /usr/local/bin/etcd --name etcd0 --data-dir /etcd-data --listen-client-urls http://0.0.0.0:2379 --advertise-client-urls http://0.0.0.0:2379 --listen-peer-urls http://0.0.0.0:2380 --initial-advertise-peer-urls http://0.0.0.0:2380 --initial-cluster etcd0=http://0.0.0.0:2380 --initial-cluster-token tkn --initial-cluster-state new open_im_server: - image: openim/open_im_server:v2.0.2 + image: openim/open_im_server:v2.0.5 container_name: open_im_server volumes: - ./logs:/Open-IM-Server/logs diff --git a/go.mod b/go.mod index 4b9da4af5..f005f9ce0 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/Shopify/toxiproxy v2.1.4+incompatible // indirect github.com/alibabacloud-go/darabonba-openapi v0.1.11 github.com/alibabacloud-go/dysmsapi-20170525/v2 v2.0.8 + github.com/alibabacloud-go/sts-20150401 v1.1.0 github.com/alibabacloud-go/tea v1.1.17 github.com/antonfisher/nested-logrus-formatter v1.3.0 github.com/bwmarrin/snowflake v0.3.0 @@ -21,7 +22,7 @@ require ( github.com/gin-gonic/gin v1.7.0 github.com/go-playground/validator/v10 v10.4.1 github.com/go-sql-driver/mysql v1.6.0 // indirect - github.com/gogo/protobuf v1.3.2 // indirect + github.com/gogo/protobuf v1.3.2 github.com/golang-jwt/jwt/v4 v4.1.0 github.com/golang/protobuf v1.5.2 github.com/golang/snappy v0.0.4 // indirect @@ -59,6 +60,7 @@ require ( google.golang.org/protobuf v1.27.1 gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df + gopkg.in/ini.v1 v1.66.2 // indirect gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b sigs.k8s.io/yaml v1.2.0 // indirect diff --git a/go.sum b/go.sum index 1defffaf3..cec54f0ff 100644 --- a/go.sum +++ b/go.sum @@ -53,6 +53,7 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= +github.com/alibabacloud-go/darabonba-openapi v0.1.7/go.mod h1:6FV1Bt1AItYIlC2rVopPTumrRNtkfPBmrPVAZ8v2bLk= github.com/alibabacloud-go/darabonba-openapi v0.1.11 h1:w59gtSA0s87p0U5NNG/N/PIHsRP3rtj7qCP9hx9+GL8= github.com/alibabacloud-go/darabonba-openapi v0.1.11/go.mod h1:MPJMxv7HYrFm5m9uOZWkDYsAWyZztEgnBRfk9Fg0eIU= github.com/alibabacloud-go/darabonba-string v1.0.0/go.mod h1:93cTfV3vuPhhEwGGpKKqhVW4jLe7tDpo3LUM0i0g6mA= @@ -62,8 +63,11 @@ github.com/alibabacloud-go/dysmsapi-20170525/v2 v2.0.8 h1:KXMiCg99Jx7B6V+DlRFbWw github.com/alibabacloud-go/dysmsapi-20170525/v2 v2.0.8/go.mod h1:8aL6tSyQIWJygF7W/Vqxdf/QDbN2S+u57k36bEA8hD8= github.com/alibabacloud-go/endpoint-util v1.1.0 h1:r/4D3VSw888XGaeNpP994zDUaxdgTSHBbVfZlzf6b5Q= github.com/alibabacloud-go/endpoint-util v1.1.0/go.mod h1:O5FuCALmCKs2Ff7JFJMudHs0I5EBgecXXxZRyswlEjE= +github.com/alibabacloud-go/openapi-util v0.0.8/go.mod h1:sQuElr4ywwFRlCCberQwKRFhRzIyG4QTP/P4y1CJ6Ws= github.com/alibabacloud-go/openapi-util v0.0.9 h1:Z0DP4LFzkM/rW2nxOMiiLoQVZSeE3jVc5jrZ9Fd/UX0= github.com/alibabacloud-go/openapi-util v0.0.9/go.mod h1:sQuElr4ywwFRlCCberQwKRFhRzIyG4QTP/P4y1CJ6Ws= +github.com/alibabacloud-go/sts-20150401 v1.1.0 h1:1yVyKz02ES6aKo3xVjmoPLBH1OAmmSqPkhKRdjEkmYs= +github.com/alibabacloud-go/sts-20150401 v1.1.0/go.mod h1:QW4O/c7Hp4krHYt+6xwnoG8EyZW3V9GYkl6EgIBmxJc= github.com/alibabacloud-go/tea v1.1.0/go.mod h1:IkGyUSX4Ba1V+k4pCtJUc6jDpZLFph9QMy2VUPTwukg= github.com/alibabacloud-go/tea v1.1.7/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeGOFfwYm3N/p4= github.com/alibabacloud-go/tea v1.1.8/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeGOFfwYm3N/p4= @@ -1095,6 +1099,8 @@ gopkg.in/ini.v1 v1.56.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ini.v1 v1.57.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ini.v1 v1.63.2 h1:tGK/CyBg7SMzb60vP1M03vNZ3VDu3wGQJwn7Sxi9r3c= gopkg.in/ini.v1 v1.63.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/ini.v1 v1.66.2 h1:XfR1dOYubytKy4Shzc2LHrrGhU0lDCfDGG1yLPmpgsI= +gopkg.in/ini.v1 v1.66.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 h1:VpOs+IwYnYBaFnrNAeB8UUWtL3vEUnzSCL1nVjPhqrw= gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= diff --git a/internal/api/group/group.go b/internal/api/group/group.go index 588858982..41b425d4c 100644 --- a/internal/api/group/group.go +++ b/internal/api/group/group.go @@ -259,7 +259,7 @@ func CreateGroup(c *gin.Context) { c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"}) return } - req.OwnerUserID = req.OpUserID + req.OwnerUserID = params.OwnerUserID req.OperationID = params.OperationID log.NewInfo(req.OperationID, "CreateGroup args ", req.String()) diff --git a/internal/api/third/ali_oss_credential.go b/internal/api/third/ali_oss_credential.go new file mode 100644 index 000000000..6f5bc7c04 --- /dev/null +++ b/internal/api/third/ali_oss_credential.go @@ -0,0 +1,95 @@ +package apiThird + +import ( + api "Open_IM/pkg/base_info" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" + "Open_IM/pkg/common/log" + "Open_IM/pkg/common/token_verify" + "fmt" + openapi "github.com/alibabacloud-go/darabonba-openapi/client" + sts20150401 "github.com/alibabacloud-go/sts-20150401/client" + "github.com/alibabacloud-go/tea/tea" + "github.com/fatih/structs" + + //"github.com/fatih/structs" + "github.com/gin-gonic/gin" + "net/http" + "time" +) + +var stsClient *sts20150401.Client + +/** + * 使用AK&SK初始化账号Client + * @param accessKeyId + * @param accessKeySecret + * @return Client + * @throws Exception + */ +func getStsClient() *sts20150401.Client { + if stsClient != nil { + return stsClient + } + conf := &openapi.Config{ + // 您的AccessKey ID + AccessKeyId: tea.String(config.Config.Credential.Ali.AccessKeyID), + // 您的AccessKey Secret + AccessKeySecret: tea.String(config.Config.Credential.Ali.AccessKeySecret), + // Endpoint + Endpoint: tea.String(config.Config.Credential.Ali.StsEndpoint), + } + result, err := sts20150401.NewClient(conf) + if err != nil { + log.NewError("", "alists client初始化失败 ", err) + } + stsClient = result + return stsClient +} + +func AliOSSCredential(c *gin.Context) { + req := api.OSSCredentialReq{} + if err := c.BindJSON(&req); err != nil { + log.NewError("0", "BindJSON failed ", err.Error()) + c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()}) + return + } + ok, userID := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID) + if !ok { + log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token")) + c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"}) + return + } + log.NewInfo(req.OperationID, "AliOSSCredential args ", userID) + + stsResp, err := getStsClient().AssumeRole(&sts20150401.AssumeRoleRequest{ + DurationSeconds: tea.Int64(config.Config.Credential.Ali.StsDurationSeconds), + Policy: nil, + RoleArn: tea.String(config.Config.Credential.Ali.OssRoleArn), + RoleSessionName: tea.String(fmt.Sprintf("%s-%d", userID, time.Now().Unix())), + }) + + resp := api.OSSCredentialResp{} + if err != nil { + resp.ErrCode = constant.ErrTencentCredential.ErrCode + resp.ErrMsg = err.Error() + } else { + resp = api.OSSCredentialResp{ + CommResp: api.CommResp{}, + OssData: api.OSSCredentialRespData{ + Endpoint: config.Config.Credential.Ali.OssEndpoint, + AccessKeyId: *stsResp.Body.Credentials.AccessKeyId, + AccessKeySecret: *stsResp.Body.Credentials.AccessKeySecret, + Token: *stsResp.Body.Credentials.SecurityToken, + Bucket: config.Config.Credential.Ali.Bucket, + FinalHost: config.Config.Credential.Ali.FinalHost, + }, + Data: nil, + } + } + + resp.Data = structs.Map(&resp.OssData) + log.NewInfo(req.OperationID, "AliOSSCredential return ", resp) + + c.JSON(http.StatusOK, resp) +} diff --git a/internal/demo/register/set_password.go b/internal/demo/register/set_password.go index 7540d9830..804e8eb11 100644 --- a/internal/demo/register/set_password.go +++ b/internal/demo/register/set_password.go @@ -17,6 +17,7 @@ import ( type ParamsSetPassword struct { Email string `json:"email"` + Name string `json:"name"` PhoneNumber string `json:"phoneNumber"` Password string `json:"password"` VerificationCode string `json:"verificationCode"` @@ -38,6 +39,9 @@ func SetPassword(c *gin.Context) { } else { account = params.PhoneNumber } + if params.Name == "" { + params.Name = account + } if params.VerificationCode != config.Config.Demo.SuperCode { accountKey := account + "_" + constant.VerificationCodeForRegisterSuffix v, err := db.DB.GetAccountCode(accountKey) @@ -54,7 +58,7 @@ func SetPassword(c *gin.Context) { openIMRegisterReq.OperationID = params.OperationID openIMRegisterReq.Platform = params.Platform openIMRegisterReq.UserID = account - openIMRegisterReq.Nickname = account + openIMRegisterReq.Nickname = params.Name openIMRegisterReq.Secret = config.Config.Secret openIMRegisterResp := api.UserRegisterResp{} bMsg, err := http2.Post(url, openIMRegisterReq, 2) @@ -69,7 +73,7 @@ func SetPassword(c *gin.Context) { if err != nil { log.NewError(params.OperationID, utils.GetSelfFuncName(), err.Error()) } - c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterFailed, "errMsg": "register failed: "+openIMRegisterResp.ErrMsg}) + c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterFailed, "errMsg": "register failed: " + openIMRegisterResp.ErrMsg}) return } log.Info(params.OperationID, "begin store mysql", account, params.Password) diff --git a/pkg/base_info/friend_api_struct.go b/pkg/base_info/friend_api_struct.go index 64b71b284..3c45c393e 100644 --- a/pkg/base_info/friend_api_struct.go +++ b/pkg/base_info/friend_api_struct.go @@ -21,7 +21,7 @@ type ImportFriendReq struct { FromUserID string `json:"fromUserID" binding:"required"` } type UserIDResult struct { - UserID string `json:"userID""` + UserID string `json:"userID"` Result int32 `json:"result"` } type ImportFriendResp struct { diff --git a/pkg/base_info/oss_api_struct.go b/pkg/base_info/oss_api_struct.go new file mode 100644 index 000000000..621d18820 --- /dev/null +++ b/pkg/base_info/oss_api_struct.go @@ -0,0 +1,22 @@ +package base_info + +type OSSCredentialReq struct { + OperationID string `json:"operationID"` + Filename string `json:"filename"` + FileType string `json:"file_type"` +} + +type OSSCredentialRespData struct { + Endpoint string `json:"endpoint"` + AccessKeyId string `json:"access_key_id"` + AccessKeySecret string `json:"access_key_secret"` + Token string `json:"token"` + Bucket string `json:"bucket"` + FinalHost string `json:"final_host"` +} + +type OSSCredentialResp struct { + CommResp + OssData OSSCredentialRespData `json:"-"` + Data map[string]interface{} `json:"data"` +} diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go index 1e0a54f1a..2a8ec36ff 100644 --- a/pkg/common/config/config.go +++ b/pkg/common/config/config.go @@ -45,6 +45,17 @@ type config struct { SecretID string `yaml:"secretID"` SecretKey string `yaml:"secretKey"` } + Ali struct { + RegionID string `yaml:"regionID"` + AccessKeyID string `yaml:"accessKeyID"` + AccessKeySecret string `yaml:"accessKeySecret"` + StsEndpoint string `yaml:"stsEndpoint"` + OssEndpoint string `yaml:"ossEndpoint"` + Bucket string `yaml:"bucket"` + FinalHost string `yaml:"finalHost"` + StsDurationSeconds int64 `yaml:"stsDurationSeconds"` + OssRoleArn string `yaml:"OssRoleArn"` + } Minio struct { Bucket string `yaml:"bucket"` Location string `yaml:"location"` @@ -66,6 +77,7 @@ type config struct { DBMaxLifeTime int `yaml:"dbMaxLifeTime"` } Mongo struct { + DBUri string `yaml:"dbUri"` // 当dbUri值不为空则直接使用该值 DBAddress []string `yaml:"dbAddress"` DBDirect bool `yaml:"dbDirect"` DBTimeout int `yaml:"dbTimeout"` diff --git a/pkg/common/db/model.go b/pkg/common/db/model.go index 6e3048db9..812783e03 100644 --- a/pkg/common/db/model.go +++ b/pkg/common/db/model.go @@ -41,12 +41,17 @@ func init() { // mongo init // "mongodb://sysop:moon@localhost/records" uri := "mongodb://sample.host:27017/?maxPoolSize=20&w=majority" - uri = fmt.Sprintf("mongodb://%s/%s/?connect=direct&maxPoolSize=%d", - config.Config.Mongo.DBAddress[0], config.Config.Mongo.DBDatabase, - config.Config.Mongo.DBMaxPoolSize) + if config.Config.Mongo.DBUri != "" { + // example: mongodb://$user:$password@mongo1.mongo:27017,mongo2.mongo:27017,mongo3.mongo:27017/$DBDatabase/?replicaSet=rs0&readPreference=secondary&authSource=admin&maxPoolSize=$DBMaxPoolSize + uri = config.Config.Mongo.DBUri + } else { + uri = fmt.Sprintf("mongodb://%s/%s/?maxPoolSize=%d", + config.Config.Mongo.DBAddress[0], config.Config.Mongo.DBDatabase, + config.Config.Mongo.DBMaxPoolSize) + } mongoClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri)) - if err != nil { + if err != nil{ log.NewError(" mongo.Connect failed, try ", utils.GetSelfFuncName(), err.Error(), uri) time.Sleep(time.Duration(30) * time.Second) mongoClient, err1 = mongo.Connect(context.TODO(), options.Client().ApplyURI(uri)) diff --git a/script/demo_svr_start.sh b/script/demo_svr_start.sh index 55aaa88b1..85b36ab25 100644 --- a/script/demo_svr_start.sh +++ b/script/demo_svr_start.sh @@ -44,4 +44,4 @@ if [ $check -ge 1 ]; then echo -e ${SKY_BLUE_PREFIX}"LISTENING_PORT: "${COLOR_SUFFIX}${YELLOW_PREFIX}${allPorts}${COLOR_SUFFIX} else echo -e ${YELLOW_PREFIX}${demo_server_name}${COLOR_SUFFIX}${RED_PREFIX}"SERVICE START ERROR, PLEASE CHECK openIM.log"${COLOR_SUFFIX} -fi +fi \ No newline at end of file diff --git a/script/docker_check_service.sh b/script/docker_check_service.sh index 6579d400c..6236712ba 100644 --- a/script/docker_check_service.sh +++ b/script/docker_check_service.sh @@ -8,3 +8,4 @@ sleep 30 echo "check OpenIM................................" ./check_all.sh + diff --git a/script/env_check.sh b/script/env_check.sh index 6af30a37b..a3a9857f6 100644 --- a/script/env_check.sh +++ b/script/env_check.sh @@ -17,4 +17,3 @@ if [ $available -lt 2000 ] ; then else echo -e ${GREEN_PREFIX} "Memory is ok, available is: "$available"m${COLOR_SUFFIX}" fi - diff --git a/script/path_info.cfg b/script/path_info.cfg index f9038d11f..84e81adfd 100644 --- a/script/path_info.cfg +++ b/script/path_info.cfg @@ -80,4 +80,3 @@ service_names=( - diff --git a/script/start_all.sh b/script/start_all.sh index 4354eace9..4125ca50a 100644 --- a/script/start_all.sh +++ b/script/start_all.sh @@ -16,4 +16,3 @@ for i in ${need_to_start_server_shell[*]}; do chmod +x $i ./$i done - diff --git a/script/start_rpc_service.sh b/script/start_rpc_service.sh index 8cf9bb6df..0b54493c2 100644 --- a/script/start_rpc_service.sh +++ b/script/start_rpc_service.sh @@ -65,4 +65,4 @@ for ((i = 0; i < ${#service_filename[*]}; i++)); do pid="netstat -ntlp|grep $j |awk '{printf \$7}'|cut -d/ -f1" echo -e "${RED_PREFIX}${service_filename[$i]} Service is started,port number:$j pid:$(eval $pid)$COLOR_SUFFIX" done -done +done \ No newline at end of file