|
|
|
@ -33,19 +33,20 @@ import (
|
|
|
|
|
|
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
|
|
|
|
|
|
|
|
|
"github.com/minio/minio-go/v7/pkg/credentials"
|
|
|
|
|
"github.com/minio/minio-go/v7"
|
|
|
|
|
"github.com/redis/go-redis/v9"
|
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
|
"github.com/minio/minio-go/v7/pkg/credentials"
|
|
|
|
|
"github.com/redis/go-redis/v9"
|
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
// defaultCfgPath is the default path of the configuration file.
|
|
|
|
|
defaultCfgPath = "../../../../../config/config.yaml"
|
|
|
|
|
minioHealthCheckDuration = 1
|
|
|
|
|
maxRetry = 100
|
|
|
|
|
maxRetry = 300
|
|
|
|
|
componentStartErrCode = 6000
|
|
|
|
|
configErrCode = 6001
|
|
|
|
|
mongoConnTimeout = 30 * time.Second
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
@ -55,8 +56,7 @@ const (
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
cfgPath = flag.String("c", defaultCfgPath, "Path to the configuration file")
|
|
|
|
|
|
|
|
|
|
cfgPath = flag.String("c", defaultCfgPath, "Path to the configuration file")
|
|
|
|
|
ErrComponentStart = errs.NewCodeError(componentStartErrCode, "ComponentStartErr")
|
|
|
|
|
ErrConfig = errs.NewCodeError(configErrCode, "Config file is incorrect")
|
|
|
|
|
)
|
|
|
|
@ -95,7 +95,7 @@ func main() {
|
|
|
|
|
|
|
|
|
|
for i := 0; i < maxRetry; i++ {
|
|
|
|
|
if i != 0 {
|
|
|
|
|
time.Sleep(3 * time.Second)
|
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
|
}
|
|
|
|
|
fmt.Printf("Checking components Round %v...\n", i+1)
|
|
|
|
|
|
|
|
|
@ -141,19 +141,25 @@ func getEnv(key, fallback string) string {
|
|
|
|
|
return fallback
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// checkMongo checks the MongoDB connection
|
|
|
|
|
// checkMongo checks the MongoDB connection without retries
|
|
|
|
|
func checkMongo() (string, error) {
|
|
|
|
|
// Use environment variables or fallback to config
|
|
|
|
|
uri := getEnv("MONGO_URI", buildMongoURI())
|
|
|
|
|
|
|
|
|
|
client, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), mongoConnTimeout)
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
str := "ths addr is:" + strings.Join(config.Config.Mongo.Address, ",")
|
|
|
|
|
|
|
|
|
|
client, err := mongo.Connect(ctx, options.Client().ApplyURI(uri))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", errs.Wrap(errStr(err, str))
|
|
|
|
|
}
|
|
|
|
|
defer client.Disconnect(context.TODO())
|
|
|
|
|
defer client.Disconnect(context.Background())
|
|
|
|
|
|
|
|
|
|
ctx, cancel = context.WithTimeout(context.Background(), mongoConnTimeout)
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
if err = client.Ping(context.TODO(), nil); err != nil {
|
|
|
|
|
if err = client.Ping(ctx, nil); err != nil {
|
|
|
|
|
return "", errs.Wrap(errStr(err, str))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -222,8 +228,8 @@ func checkMinio() (string, error) {
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
if minioClient.IsOffline() {
|
|
|
|
|
// str := fmt.Sprintf("Minio server is offline;%s", str)
|
|
|
|
|
// return "", ErrComponentStart.Wrap(str)
|
|
|
|
|
str := fmt.Sprintf("Minio server is offline;%s", str)
|
|
|
|
|
return "", ErrComponentStart.Wrap(str)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check for localhost in API URL and Minio SignEndpoint
|
|
|
|
|