mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-11-05 03:42:08 +08:00
Merge remote-tracking branch 'origin/3.6.1-code-conventions' into 3.6.1-code-conventions
This commit is contained in:
commit
07fbe321b4
1
.github/code-language-detector.yml
vendored
1
.github/code-language-detector.yml
vendored
@ -12,6 +12,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# https://github.com/marketplace/actions/code-language-detector
|
||||
directory: ./
|
||||
file_types:
|
||||
- .go
|
||||
|
||||
2
.github/release-drafter.yml
vendored
2
.github/release-drafter.yml
vendored
@ -48,4 +48,4 @@ template: |
|
||||
|
||||
## Contributors to this $REPOSITORY release
|
||||
|
||||
$CONTRIBUTORS
|
||||
$CONTRIBUTORS
|
||||
|
||||
50
.github/standardizer.yml
vendored
Normal file
50
.github/standardizer.yml
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
# https://github.com/marketplace/actions/conformity-checker-for-project
|
||||
baseConfig:
|
||||
searchDirectory: "./"
|
||||
ignoreCase: false
|
||||
|
||||
directoryNaming:
|
||||
allowHyphens: true
|
||||
allowUnderscores: false
|
||||
mustBeLowercase: true
|
||||
|
||||
fileNaming:
|
||||
allowHyphens: true
|
||||
allowUnderscores: true
|
||||
mustBeLowercase: true
|
||||
|
||||
ignoreFormats:
|
||||
- "\\.log$"
|
||||
- "\\.env$"
|
||||
- "README\\.md$"
|
||||
- "_test\\.go$"
|
||||
- "\\.md$"
|
||||
- _test\\.txt$
|
||||
- LICENSE
|
||||
- Dockerfile
|
||||
- CODEOWNERS
|
||||
- Makefile
|
||||
|
||||
ignoreDirectories:
|
||||
- "vendor"
|
||||
- ".git"
|
||||
- "deployments"
|
||||
- "node_modules"
|
||||
- "logs"
|
||||
- "CHANGELOG"
|
||||
- "components"
|
||||
- "_output"
|
||||
- "tools/openim-web"
|
||||
- "CHANGELOG"
|
||||
- "examples/Test_directory"
|
||||
- test/testdata
|
||||
|
||||
fileTypeSpecificNaming:
|
||||
".yaml":
|
||||
allowHyphens: true
|
||||
allowUnderscores: false
|
||||
mustBeLowercase: true
|
||||
".go":
|
||||
allowHyphens: false
|
||||
allowUnderscores: true
|
||||
mustBeLowercase: true
|
||||
3
.github/workflows/openimci.yml
vendored
3
.github/workflows/openimci.yml
vendored
@ -73,6 +73,9 @@ jobs:
|
||||
- name: Code Typecheck Detector
|
||||
uses: kubecub/typecheck@main
|
||||
|
||||
- name: Conformity Checker for Project
|
||||
uses: kubecub/standardizer@main
|
||||
|
||||
- name: Module Operations
|
||||
run: |
|
||||
sudo make tidy
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@ -34,7 +34,6 @@ deployments/charts/generated-configs/
|
||||
### OpenIM Config ###
|
||||
.env
|
||||
config/config.yaml
|
||||
config/openim.yaml
|
||||
config/alertmanager.yml
|
||||
config/prometheus.yml
|
||||
config/email.tmpl
|
||||
|
||||
@ -39,19 +39,19 @@ run:
|
||||
# from this option's value (see skip-dirs-use-default).
|
||||
# "/" will be replaced by current OS file path separator to properly work
|
||||
# on Windows.
|
||||
skip-dirs:
|
||||
- components
|
||||
- docs
|
||||
- util
|
||||
- .*~
|
||||
- api/swagger/docs
|
||||
- server/docs
|
||||
- components/mnt/config/certs
|
||||
- logs
|
||||
# skip-dirs:
|
||||
# - components
|
||||
# - docs
|
||||
# - util
|
||||
# - .*~
|
||||
# - api/swagger/docs
|
||||
# - server/docs
|
||||
# - components/mnt/config/certs
|
||||
# - logs
|
||||
|
||||
# default is true. Enables skipping of directories:
|
||||
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
|
||||
skip-dirs-use-default: true
|
||||
# skip-dirs-use-default: true
|
||||
|
||||
# which files to skip: they will be analyzed, but issues from them
|
||||
# won't be reported. Default value is empty list, but there is
|
||||
@ -59,15 +59,15 @@ run:
|
||||
# autogenerated files. If it's not please let us know.
|
||||
# "/" will be replaced by current OS file path separator to properly work
|
||||
# on Windows.
|
||||
skip-files:
|
||||
- ".*\\.my\\.go$"
|
||||
- _test.go
|
||||
- ".*_test.go"
|
||||
- "mocks/"
|
||||
- ".github/"
|
||||
- "logs/"
|
||||
- "_output/"
|
||||
- "components/"
|
||||
# skip-files:
|
||||
# - ".*\\.my\\.go$"
|
||||
# - _test.go
|
||||
# - ".*_test.go"
|
||||
# - "mocks/"
|
||||
# - ".github/"
|
||||
# - "logs/"
|
||||
# - "_output/"
|
||||
# - "components/"
|
||||
|
||||
# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
|
||||
# If invoked with -mod=readonly, the go command is disallowed from the implicit
|
||||
@ -87,7 +87,7 @@ run:
|
||||
# output configuration options
|
||||
output:
|
||||
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
|
||||
format: colored-line-number
|
||||
# format: colored-line-number
|
||||
|
||||
# print lines of code with issue, default is true
|
||||
print-issued-lines: true
|
||||
@ -150,6 +150,11 @@ linters-settings:
|
||||
comparison: true
|
||||
|
||||
exhaustive:
|
||||
# Program elements to check for exhaustiveness.
|
||||
# Default: [ switch ]
|
||||
check:
|
||||
- switch
|
||||
- map
|
||||
# check switch statements in generated files also
|
||||
check-generated: false
|
||||
# indicates that switch statements are to be considered exhaustive if a
|
||||
@ -772,6 +777,7 @@ linters:
|
||||
- dupword
|
||||
- errname
|
||||
- gci
|
||||
- exhaustive
|
||||
- gocritic
|
||||
- goprintffuncname
|
||||
- gomnd
|
||||
|
||||
1
Makefile
1
Makefile
@ -19,6 +19,7 @@ VERSION_PACKAGE=github.com/openimsdk/open-im-server/v3/pkg/version
|
||||
# Includes
|
||||
|
||||
include scripts/make-rules/common.mk # make sure include common.mk at the first include line
|
||||
include scripts/make-rules/common-versions.mk
|
||||
include scripts/make-rules/golang.mk
|
||||
include scripts/make-rules/image.mk
|
||||
include scripts/make-rules/copyright.mk
|
||||
|
||||
@ -52,7 +52,7 @@
|
||||
</p>
|
||||
|
||||
## 🟢 扫描微信进群交流
|
||||
<img src="./docs/images/Wechat.jpg" width="300">
|
||||
<img src="./docs/images/wechat.jpg" width="300">
|
||||
|
||||
|
||||
## Ⓜ️ 关于 OpenIM
|
||||
|
||||
35
cmd/openim-no-port/main.go
Normal file
35
cmd/openim-no-port/main.go
Normal file
@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Initialize the random seed
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
|
||||
// Define flags
|
||||
index := flag.Int("i", 0, "Index number")
|
||||
config := flag.String("c", "", "Configuration path")
|
||||
|
||||
// Parse the flags
|
||||
flag.Parse()
|
||||
|
||||
// Print the values of the flags
|
||||
fmt.Printf("args: -i %d -c %s\n", *index, *config)
|
||||
|
||||
// Generate a random number (0 or 1) and subtract 1 to get 0 or -1
|
||||
randomValue := rand.Intn(2) - 1
|
||||
|
||||
if randomValue == 0 {
|
||||
fmt.Println("Sleeping for 500 seconds...")
|
||||
time.Sleep(500 * time.Second)
|
||||
} else if randomValue == -1 {
|
||||
fmt.Fprintln(os.Stderr, "An error occurred. Exiting with status -1.")
|
||||
os.Exit(-1)
|
||||
}
|
||||
}
|
||||
@ -4,4 +4,4 @@ api:
|
||||
prometheus:
|
||||
enable: true
|
||||
grafanaUrl: http://127.0.0.1:13000/
|
||||
apiPrometheusPort: [20100]
|
||||
prometheusPort: [20100]
|
||||
@ -7,16 +7,6 @@ longConnSvr:
|
||||
prometheus:
|
||||
enable: true
|
||||
grafanaUrl: http://127.0.0.1:13000/
|
||||
apiPrometheusPort: [20100]
|
||||
userPrometheusPort: [ 20110 ]
|
||||
friendPrometheusPort: [ 20120 ]
|
||||
messagePrometheusPort: [ 20130 ]
|
||||
messageGatewayPrometheusPort: [ 20140 ]
|
||||
groupPrometheusPort: [ 20150 ]
|
||||
authPrometheusPort: [ 20160 ]
|
||||
pushPrometheusPort: [ 20170 ]
|
||||
conversationPrometheusPort: [ 20230 ]
|
||||
rtcPrometheusPort: [ 21300 ]
|
||||
thirdPrometheusPort: [ 21301 ]
|
||||
messageTransferPrometheusPort: [ 21400, 21401, 21402, 21403 ] # List of ports
|
||||
prometheusPort: [ 20140 ]
|
||||
|
||||
|
||||
|
||||
@ -2,15 +2,4 @@
|
||||
prometheus:
|
||||
enable: true
|
||||
grafanaUrl: http://127.0.0.1:13000/
|
||||
apiPrometheusPort: [20100]
|
||||
userPrometheusPort: [ 20110 ]
|
||||
friendPrometheusPort: [ 20120 ]
|
||||
messagePrometheusPort: [ 20130 ]
|
||||
messageGatewayPrometheusPort: [ 20140 ]
|
||||
groupPrometheusPort: [ 20150 ]
|
||||
authPrometheusPort: [ 20160 ]
|
||||
pushPrometheusPort: [ 20170 ]
|
||||
conversationPrometheusPort: [ 20230 ]
|
||||
rtcPrometheusPort: [ 21300 ]
|
||||
thirdPrometheusPort: [ 21301 ]
|
||||
messageTransferPrometheusPort: [ 21400, 21401, 21402, 21403 ] # List of ports
|
||||
prometheusPort: [ 21400, 21401, 21402, 21403 ] # List of ports
|
||||
|
||||
@ -17,15 +17,5 @@ push:
|
||||
prometheus:
|
||||
enable: true
|
||||
grafanaUrl: http://127.0.0.1:13000/
|
||||
apiPrometheusPort: [20100]
|
||||
userPrometheusPort: [ 20110 ]
|
||||
friendPrometheusPort: [ 20120 ]
|
||||
messagePrometheusPort: [ 20130 ]
|
||||
messageGatewayPrometheusPort: [ 20140 ]
|
||||
groupPrometheusPort: [ 20150 ]
|
||||
authPrometheusPort: [ 20160 ]
|
||||
pushPrometheusPort: [ 20170 ]
|
||||
conversationPrometheusPort: [ 20230 ]
|
||||
rtcPrometheusPort: [ 21300 ]
|
||||
thirdPrometheusPort: [ 21301 ]
|
||||
messageTransferPrometheusPort: [ 21400, 21401, 21402, 21403 ] # List of ports
|
||||
prometheusPort: [ 20170 ]
|
||||
|
||||
|
||||
@ -8,15 +8,4 @@ rpcRegisterName:
|
||||
prometheus:
|
||||
enable: true
|
||||
grafanaUrl: http://127.0.0.1:13000/
|
||||
apiPrometheusPort: [20100]
|
||||
userPrometheusPort: [ 20110 ]
|
||||
friendPrometheusPort: [ 20120 ]
|
||||
messagePrometheusPort: [ 20130 ]
|
||||
messageGatewayPrometheusPort: [ 20140 ]
|
||||
groupPrometheusPort: [ 20150 ]
|
||||
authPrometheusPort: [ 20160 ]
|
||||
pushPrometheusPort: [ 20170 ]
|
||||
conversationPrometheusPort: [ 20230 ]
|
||||
rtcPrometheusPort: [ 21300 ]
|
||||
thirdPrometheusPort: [ 21301 ]
|
||||
messageTransferPrometheusPort: [ 21400, 21401, 21402, 21403 ] # List of ports
|
||||
prometheusPort: [20160]
|
||||
@ -8,15 +8,5 @@ rpcRegisterName:
|
||||
prometheus:
|
||||
enable: true
|
||||
grafanaUrl: http://127.0.0.1:13000/
|
||||
apiPrometheusPort: [20100]
|
||||
userPrometheusPort: [ 20110 ]
|
||||
friendPrometheusPort: [ 20120 ]
|
||||
messagePrometheusPort: [ 20130 ]
|
||||
messageGatewayPrometheusPort: [ 20140 ]
|
||||
groupPrometheusPort: [ 20150 ]
|
||||
authPrometheusPort: [ 20160 ]
|
||||
pushPrometheusPort: [ 20170 ]
|
||||
conversationPrometheusPort: [ 20230 ]
|
||||
rtcPrometheusPort: [ 21300 ]
|
||||
thirdPrometheusPort: [ 21301 ]
|
||||
messageTransferPrometheusPort: [ 21400, 21401, 21402, 21403 ] # List of ports
|
||||
prometheusPort: [ 20230 ]
|
||||
|
||||
|
||||
@ -8,15 +8,4 @@ rpcRegisterName:
|
||||
prometheus:
|
||||
enable: true
|
||||
grafanaUrl: http://127.0.0.1:13000/
|
||||
apiPrometheusPort: [20100]
|
||||
userPrometheusPort: [ 20110 ]
|
||||
friendPrometheusPort: [ 20120 ]
|
||||
messagePrometheusPort: [ 20130 ]
|
||||
messageGatewayPrometheusPort: [ 20140 ]
|
||||
groupPrometheusPort: [ 20150 ]
|
||||
authPrometheusPort: [ 20160 ]
|
||||
pushPrometheusPort: [ 20170 ]
|
||||
conversationPrometheusPort: [ 20230 ]
|
||||
rtcPrometheusPort: [ 21300 ]
|
||||
thirdPrometheusPort: [ 21301 ]
|
||||
messageTransferPrometheusPort: [ 21400, 21401, 21402, 21403 ] # List of ports
|
||||
prometheusPort: [ 20120 ]
|
||||
|
||||
@ -8,15 +8,5 @@ rpcRegisterName:
|
||||
prometheus:
|
||||
enable: true
|
||||
grafanaUrl: http://127.0.0.1:13000/
|
||||
apiPrometheusPort: [20100]
|
||||
userPrometheusPort: [ 20110 ]
|
||||
friendPrometheusPort: [ 20120 ]
|
||||
messagePrometheusPort: [ 20130 ]
|
||||
messageGatewayPrometheusPort: [ 20140 ]
|
||||
groupPrometheusPort: [ 20150 ]
|
||||
authPrometheusPort: [ 20160 ]
|
||||
pushPrometheusPort: [ 20170 ]
|
||||
conversationPrometheusPort: [ 20230 ]
|
||||
rtcPrometheusPort: [ 21300 ]
|
||||
thirdPrometheusPort: [ 21301 ]
|
||||
messageTransferPrometheusPort: [ 21400, 21401, 21402, 21403 ] # List of ports
|
||||
prometheusPort: [ 20150 ]
|
||||
|
||||
|
||||
@ -8,15 +8,5 @@ rpcRegisterName:
|
||||
prometheus:
|
||||
enable: true
|
||||
grafanaUrl: http://127.0.0.1:13000/
|
||||
apiPrometheusPort: [20100]
|
||||
userPrometheusPort: [ 20110 ]
|
||||
friendPrometheusPort: [ 20120 ]
|
||||
messagePrometheusPort: [ 20130 ]
|
||||
messageGatewayPrometheusPort: [ 20140 ]
|
||||
groupPrometheusPort: [ 20150 ]
|
||||
authPrometheusPort: [ 20160 ]
|
||||
pushPrometheusPort: [ 20170 ]
|
||||
conversationPrometheusPort: [ 20230 ]
|
||||
rtcPrometheusPort: [ 21300 ]
|
||||
thirdPrometheusPort: [ 21301 ]
|
||||
messageTransferPrometheusPort: [ 21400, 21401, 21402, 21403 ] # List of ports
|
||||
prometheusPort: [ 20130 ]
|
||||
|
||||
|
||||
@ -9,15 +9,5 @@ rpcRegisterName:
|
||||
prometheus:
|
||||
enable: true
|
||||
grafanaUrl: http://127.0.0.1:13000/
|
||||
apiPrometheusPort: [20100]
|
||||
userPrometheusPort: [ 20110 ]
|
||||
friendPrometheusPort: [ 20120 ]
|
||||
messagePrometheusPort: [ 20130 ]
|
||||
messageGatewayPrometheusPort: [ 20140 ]
|
||||
groupPrometheusPort: [ 20150 ]
|
||||
authPrometheusPort: [ 20160 ]
|
||||
pushPrometheusPort: [ 20170 ]
|
||||
conversationPrometheusPort: [ 20230 ]
|
||||
rtcPrometheusPort: [ 21300 ]
|
||||
thirdPrometheusPort: [ 21301 ]
|
||||
messageTransferPrometheusPort: [ 21400, 21401, 21402, 21403 ] # List of ports
|
||||
prometheusPort: [ 21301 ]
|
||||
|
||||
|
||||
@ -9,15 +9,5 @@ rpcRegisterName:
|
||||
prometheus:
|
||||
enable: true
|
||||
grafanaUrl: http://127.0.0.1:13000/
|
||||
apiPrometheusPort: [20100]
|
||||
userPrometheusPort: [ 20110 ]
|
||||
friendPrometheusPort: [ 20120 ]
|
||||
messagePrometheusPort: [ 20130 ]
|
||||
messageGatewayPrometheusPort: [ 20140 ]
|
||||
groupPrometheusPort: [ 20150 ]
|
||||
authPrometheusPort: [ 20160 ]
|
||||
pushPrometheusPort: [ 20170 ]
|
||||
conversationPrometheusPort: [ 20230 ]
|
||||
rtcPrometheusPort: [ 21300 ]
|
||||
thirdPrometheusPort: [ 21301 ]
|
||||
messageTransferPrometheusPort: [ 21400, 21401, 21402, 21403 ] # List of ports
|
||||
prometheusPort: [ 20110 ]
|
||||
|
||||
|
||||
260
config/openim.yaml
Normal file
260
config/openim.yaml
Normal file
@ -0,0 +1,260 @@
|
||||
# openim.yaml 作为存放一些通用配置或特殊配置的文件,我们将包含日志、消息缓存、多登录策略、消息验证策略等配置。
|
||||
# 这些配置是跨多个服务的共享配置,它们对于整个系统的运行至关重要。
|
||||
log:
|
||||
storageLocation: /data/workspaces/open-im-server/_output/logs/
|
||||
rotationTime: 24
|
||||
remainRotationCount: 2
|
||||
remainLogLevel: 6
|
||||
isStdout: false
|
||||
isJson: false
|
||||
withStack: false
|
||||
|
||||
msgCacheTimeout: 86400
|
||||
|
||||
multiLoginPolicy: 1
|
||||
|
||||
messageVerify:
|
||||
friendVerify: false
|
||||
|
||||
tokenPolicy:
|
||||
expire: 90
|
||||
|
||||
groupMessageHasReadReceiptEnable: true
|
||||
|
||||
singleMessageHasReadReceiptEnable: true
|
||||
|
||||
retainChatRecords: 365
|
||||
|
||||
chatRecordsClearTime: "0 2 * * 3"
|
||||
|
||||
msgDestructTime: "0 2 * * *"
|
||||
|
||||
secret: openIM123
|
||||
|
||||
iosPush:
|
||||
pushSound: "xxx"
|
||||
badgeCount: true
|
||||
production: false
|
||||
|
||||
|
||||
###################### Third-party service configuration ######################
|
||||
# Callback configuration
|
||||
#
|
||||
# Callback URL
|
||||
# Whether to enable this callback event
|
||||
# Timeout in seconds
|
||||
# Whether to continue execution if callback fails
|
||||
callback:
|
||||
url: "http://127.0.0.1:10008/callbackExample"
|
||||
beforeSendSingleMsg:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
beforeUpdateUserInfoEx:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
afterUpdateUserInfoEx:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
afterSendSingleMsg:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
beforeSendGroupMsg:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
afterSendGroupMsg:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
msgModify:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
userOnline:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
userOffline:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
userKickOff:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
offlinePush:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
onlinePush:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
superGroupOnlinePush:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
beforeAddFriend:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
beforeUpdateUserInfo:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
beforeCreateGroup:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
afterCreateGroup:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
beforeMemberJoinGroup:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
beforeSetGroupMemberInfo:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
afterSetGroupMemberInfo:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
setMessageReactionExtensions:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
quitGroup:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
killGroupMember:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
dismissGroup:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
joinGroup:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
groupMsgRead:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
singleMsgRead:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
updateUserInfo:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
beforeUserRegister:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
afterUserRegister:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
transferGroupOwner:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
beforeSetFriendRemark:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
afterSetFriendRemark:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
afterGroupMsgRead:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
afterGroupMsgRevoke:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
afterJoinGroup:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
beforeInviteUserToGroup:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
joinGroupAfter:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
setGroupInfoAfter:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
setGroupInfoBefore:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
revokeMsgAfter:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
addBlackBefore:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
addFriendAfter:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
addFriendAgreeBefore:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
deleteFriendAfter:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
importFriendsBefore:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
importFriendsAfter:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
removeBlackAfter:
|
||||
enable: false
|
||||
timeout: 5
|
||||
failedContinue: true
|
||||
|
||||
###################### Prometheus ######################
|
||||
# Prometheus configuration for various services
|
||||
# The number of Prometheus ports per service needs to correspond to rpcPort
|
||||
# The number of ports needs to be consistent with msg_transfer_service_num in script/path_info.sh
|
||||
prometheus:
|
||||
enable: true
|
||||
grafanaUrl: http://127.0.0.1:13000/
|
||||
apiPrometheusPort: [20100]
|
||||
userPrometheusPort: [ 20110 ]
|
||||
friendPrometheusPort: [ 20120 ]
|
||||
messagePrometheusPort: [ 20130 ]
|
||||
messageGatewayPrometheusPort: [ 20140 ]
|
||||
groupPrometheusPort: [ 20150 ]
|
||||
authPrometheusPort: [ 20160 ]
|
||||
pushPrometheusPort: [ 20170 ]
|
||||
conversationPrometheusPort: [ 20230 ]
|
||||
rtcPrometheusPort: [ 21300 ]
|
||||
thirdPrometheusPort: [ 21301 ]
|
||||
messageTransferPrometheusPort: [ 21400, 21401, 21402, 21403 ] # List of ports
|
||||
@ -1,4 +1,4 @@
|
||||
#fixme Clone openIM Server project before using docker-compose,project address:https://github.com/OpenIMSDK/Open-IM-Server.git
|
||||
#fixme Clone openIM Server project before using docker-compose,project address:https://github.com/openimsdk/open-im-server.git
|
||||
# The command that triggers this file to pull the image is "docker compose up -f"
|
||||
version: '3'
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#fixme Clone openIM Server project before using docker-compose,project address:https://github.com/OpenIMSDK/Open-IM-Server.git
|
||||
#fixme Clone openIM Server project before using docker-compose,project address:https://github.com/openimsdk/open-im-server.git
|
||||
# The command that triggers this file to pull the image is "docker compose up -d".
|
||||
version: '3'
|
||||
|
||||
|
||||
@ -96,4 +96,21 @@ When pulling OpenIM's Docker images, you can choose the most suitable source bas
|
||||
|
||||
3. Run the `docker images` command to confirm that the image has been successfully pulled.
|
||||
|
||||
This concludes OpenIM's image management strategy and the steps for pulling images. If you have any questions, please feel free to ask.
|
||||
### Accelerating Deployment for Users in China with Aliyun Mirror or Alternative Image Addresses
|
||||
|
||||
For users in China looking to speed up the deployment process of OpenIM, leveraging a mirror image address is a highly recommended practice. After executing the `make init` command, a `.env` file is generated, which you'll need to edit to configure the image registry source. This configuration is crucial for optimizing download speeds and ensuring a smoother setup process.
|
||||
|
||||
Within the generated `.env` file, you'll find a section dedicated to choosing the image address. It includes options for GitHub (`ghcr.io/openimsdk`), Docker Hub (`openim`), and Ali Cloud (`registry.cn-hangzhou.aliyuncs.com/openimsdk`). To achieve the best performance within China, it is advised to use the Aliyun image address.
|
||||
|
||||
To do this, you need to comment out the current `IMAGE_REGISTRY` setting and uncomment the Aliyun option. Here is how you can adjust it for Aliyun:
|
||||
|
||||
```bash
|
||||
# Choose the image address: GitHub (ghcr.io/openimsdk), Docker Hub (openim),
|
||||
# or Ali Cloud (registry.cn-hangzhou.aliyuncs.com/openimsdk).
|
||||
# Uncomment one of the following three options. Aliyun is recommended for users in China.
|
||||
# IMAGE_REGISTRY="ghcr.io/openimsdk"
|
||||
# IMAGE_REGISTRY="openim"
|
||||
IMAGE_REGISTRY="registry.cn-hangzhou.aliyuncs.com/openimsdk"
|
||||
```
|
||||
|
||||
This change directs the deployment process to fetch the required images from the Aliyun registry, significantly improving download and installation speeds due to the geographical and network advantages within China. If, for any reason, you prefer not to use Aliyun or encounter issues, consider switching to another mirror address listed in the `.env` file by following the same uncommenting process. This flexibility ensures that users can select the most suitable image source for their specific situation, leading to a more efficient deployment of OpenIM.
|
||||
|
||||
162
docs/contrib/kafka.md
Normal file
162
docs/contrib/kafka.md
Normal file
@ -0,0 +1,162 @@
|
||||
# OpenIM Kafka Guide
|
||||
|
||||
This document aims to provide a set of concise guidelines to help you quickly install and use Kafka through Docker Compose.
|
||||
|
||||
## Installing Kafka
|
||||
|
||||
With the Docker Compose script provided by OpenIM, you can easily install Kafka. Use the following command to start Kafka:
|
||||
|
||||
```bash
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
After executing this command, Kafka will be installed and started. You can confirm the Kafka container is running with the following command:
|
||||
|
||||
```bash
|
||||
docker ps | grep kafka
|
||||
```
|
||||
|
||||
The output of this command, as shown below, displays the status information of the Kafka container:
|
||||
|
||||
```
|
||||
be416b5a0851 bitnami/kafka:3.5.1 "/opt/bitnami/script…" 3 days ago Up 2 days 9092/tcp, 0.0.0.0:19094->9094/tcp, :::19094->9094/tcp kafka
|
||||
```
|
||||
|
||||
### References
|
||||
|
||||
- Official Docker installation documentation: [Click here](http://events.jianshu.io/p/b60afa35303a)
|
||||
- Detailed installation guide: [Tutorial on Towards Data Science](https://towardsdatascience.com/how-to-install-apache-kafka-using-docker-the-easy-way-4ceb00817d8b)
|
||||
|
||||
## Using Kafka
|
||||
|
||||
### Entering the Kafka Container
|
||||
|
||||
To execute Kafka commands, you first need to enter the Kafka container. Use the following command:
|
||||
|
||||
```bash
|
||||
docker exec -it kafka bash
|
||||
```
|
||||
|
||||
### Kafka Command Tools
|
||||
|
||||
Inside the Kafka container, you can use various command-line tools to manage Kafka. These tools include but are not limited to:
|
||||
|
||||
- `kafka-topics.sh`: For creating, deleting, listing, or altering topics.
|
||||
- `kafka-console-producer.sh`: Allows sending messages to a specified topic from the command line.
|
||||
- `kafka-console-consumer.sh`: Allows reading messages from the command line, with the ability to specify topics.
|
||||
- `kafka-consumer-groups.sh`: For managing consumer group information.
|
||||
|
||||
### Kafka Client Tool Installation
|
||||
|
||||
For easier Kafka management, you can install Kafka client tools. If you installed Kafka through OpenIM's Docker Compose, you can install the Kafka client tools with the following command:
|
||||
|
||||
```bash
|
||||
make install.kafkactl
|
||||
```
|
||||
|
||||
### Automatic Topic Creation
|
||||
|
||||
When installing Kafka through OpenIM's Docker Compose method, OpenIM automatically creates the following topics:
|
||||
|
||||
- `latestMsgToRedis`
|
||||
- `msgToPush`
|
||||
- `offlineMsgToMongoMysql`
|
||||
|
||||
These topics are created using the `scripts/create-topic.sh` script. The script waits for Kafka to be ready before executing the commands to create topics:
|
||||
|
||||
```bash
|
||||
# Wait for Kafka to be ready
|
||||
until /opt/bitnami/kafka/bin/kafka-topics.sh --list --bootstrap-server localhost:9092; do
|
||||
echo "Waiting for Kafka to be ready..."
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# Create topics
|
||||
/opt/bitnami/kafka/bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 8 --topic latestMsgToRedis
|
||||
/opt/bitnami/kafka/bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 8 --topic msgToPush
|
||||
/opt/bitnami/kafka/bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 8 --topic offlineMsgToMongoMysql
|
||||
|
||||
echo "Topics created."
|
||||
```
|
||||
|
||||
The optimized and expanded documentation further details some basic commands for operations inside the Kafka container, as well as basic commands for managing Kafka using `kafkactl`. Here is a more detailed guide.
|
||||
|
||||
|
||||
## Basic Commands in the Kafka Container
|
||||
|
||||
### Listing Topics
|
||||
|
||||
To list all existing topics, you can use the following command:
|
||||
|
||||
```bash
|
||||
kafka-topics.sh --list --bootstrap-server localhost:9092
|
||||
```
|
||||
|
||||
### Creating a New Topic
|
||||
|
||||
When creating a new topic, you can specify the number of partitions and the replication factor. Here is the command to create a new topic:
|
||||
|
||||
```bash
|
||||
kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic your_topic_name
|
||||
```
|
||||
|
||||
### Producing Messages
|
||||
|
||||
To send messages to a specific topic, you can use the producer command. The following command prompts you to enter messages, which are sent to the specified topic with each press of the Enter key:
|
||||
|
||||
```bash
|
||||
kafka-console-producer.sh --broker-list localhost:9092 --topic your_topic_name
|
||||
```
|
||||
|
||||
### Consuming Messages
|
||||
|
||||
To read messages from a specific topic, you can use the consumer command. The following command reads new messages from the specified topic and outputs them on the console:
|
||||
|
||||
```bash
|
||||
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic your_topic_name --from-beginning
|
||||
```
|
||||
|
||||
The `
|
||||
|
||||
--from-beginning` parameter reads messages from the beginning of the topic. If this parameter is omitted, only new messages will be read.
|
||||
|
||||
|
||||
## Basic Commands Using `kafkactl`
|
||||
|
||||
`kafkactl` is a command-line tool for managing and operating Kafka clusters. It offers a more modern way to interact with Kafka.
|
||||
|
||||
### Listing Topics
|
||||
|
||||
To list all topics, you can use:
|
||||
|
||||
```bash
|
||||
kafkactl get topics
|
||||
```
|
||||
|
||||
### Creating a New Topic
|
||||
|
||||
To create a new topic with `kafkactl`, use:
|
||||
|
||||
```bash
|
||||
kafkactl create topic your_topic_name --partitions 1 --replication-factor 1
|
||||
```
|
||||
|
||||
### Producing Messages
|
||||
|
||||
To send messages to a topic, you can use:
|
||||
|
||||
```bash
|
||||
kafkactl produce your_topic_name --value "your message"
|
||||
```
|
||||
|
||||
Here, `"your message"` is the content of the message you want to send.
|
||||
|
||||
### Consuming Messages
|
||||
|
||||
To consume messages from a topic, use:
|
||||
|
||||
```bash
|
||||
kafkactl consume your_topic_name --from-beginning
|
||||
```
|
||||
|
||||
Again, the `--from-beginning` parameter will start consuming messages from the beginning of the topic. If you do not wish to start from the beginning, you can omit this parameter.
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
## Script Logging Documentation Link
|
||||
|
||||
If you wish to view the script's logging documentation, you can click on this link: [Logging Documentation](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/contrib/bash-log.md).
|
||||
If you wish to view the script's logging documentation, you can click on this link: [Logging Documentation](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/bash-log.md).
|
||||
|
||||
Below is the documentation for logging and error handling in the OpenIM Go project.
|
||||
|
||||
|
||||
@ -2,14 +2,94 @@
|
||||
|
||||
This document serves as a comprehensive guide to understanding and utilizing the `test.sh` script for testing OpenIM RPC services. The `test.sh` script is a collection of bash functions designed to test various aspects of the OpenIM RPC services, ensuring that each part of the API is functioning as expected.
|
||||
|
||||
+ Scripts:https://github.com/OpenIMSDK/Open-IM-Server/tree/main/scripts/install/test.sh
|
||||
+ Scripts:https://github.com/openimsdk/open-im-server/tree/main/scripts/install/test.sh
|
||||
|
||||
For some complex, bulky functional tests, performance tests, and various e2e tests, We are all in the current warehouse to https://github.com/OpenIMSDK/Open-IM-Server/tree/main/test or https://github.com/openim-sigs/test-infra directory In the.
|
||||
For some complex, bulky functional tests, performance tests, and various e2e tests, We are all in the current warehouse to https://github.com/openimsdk/open-im-server/tree/main/test or https://github.com/openim-sigs/test-infra directory In the.
|
||||
|
||||
+ About OpenIM Feature [Test Docs](https://docs.google.com/spreadsheets/d/1zELWkwxgOOZ7u5pmYCqqaFnvZy2SVajv/edit?usp=sharing&ouid=103266350914914783293&rtpof=true&sd=true)
|
||||
|
||||
## Util Test
|
||||
|
||||
## Usage
|
||||
Let's restructure and enhance the document under a unified second-level heading, adding clarity and details for better comprehension and visual appeal.
|
||||
|
||||
---
|
||||
|
||||
## Development Guide
|
||||
|
||||
### Comprehensive Testing Instructions
|
||||
|
||||
#### Running Unit Tests
|
||||
|
||||
- **Command**: To execute unit tests, input the following in your terminal:
|
||||
```
|
||||
make test
|
||||
```
|
||||
|
||||
#### Evaluating Test Coverage
|
||||
|
||||
- **Overview**: It's crucial to assess how much of your code is covered by tests.
|
||||
- **Command**:
|
||||
```bash
|
||||
make cover
|
||||
```
|
||||
This command generates a report detailing the percentage of your code tested, ensuring adherence to quality standards.
|
||||
|
||||
#### Conducting API Tests
|
||||
|
||||
- **Purpose**: API tests validate the interaction and functionality of your application's interfaces.
|
||||
- **How to Run**:
|
||||
```
|
||||
make test-api
|
||||
```
|
||||
Use this to check the integrity and reliability of your API endpoints.
|
||||
|
||||
#### End-to-End (E2E) Testing
|
||||
|
||||
- **Scope**: E2E tests simulate real-user scenarios from start to finish.
|
||||
- **Execution**:
|
||||
```
|
||||
make test-e2e
|
||||
```
|
||||
This comprehensive testing ensures your application performs as expected in real-world situations.
|
||||
|
||||
### Crafting Unit Test Cases
|
||||
|
||||
#### Setup for Test Case Generation
|
||||
|
||||
- **Installation**: Install the `gotests` tool to generate test cases automatically.
|
||||
```bash
|
||||
make install.gotests
|
||||
```
|
||||
This command installs the `gotests` tool for test case generation.
|
||||
|
||||
- **Environment Preparation**: Define your test template environment variable and generate test cases as shown below:
|
||||
```bash
|
||||
export GOTESTS_TEMPLATE=testify
|
||||
gotests -i -w -only keyFunc .
|
||||
```
|
||||
This prepares your environment for test case generation using the `testify` template.
|
||||
|
||||
#### Isolating Function Tests
|
||||
|
||||
- **Single Function Testing**: When you need to focus on testing a single function for detailed examination.
|
||||
- **Method**:
|
||||
```bash
|
||||
go test -v -run TestKeyFunc
|
||||
```
|
||||
This command specifically runs tests for `TestKeyFunc`, allowing targeted debugging and validation.
|
||||
|
||||
### Important Note
|
||||
|
||||
- **Quality Assurance**: Throughout your development process, it is imperative to ensure that the unit test coverage meets or surpasses the standards set by OpenIM.
|
||||
- **Maintaining Standards**: Regularly running your tests with
|
||||
```make test```
|
||||
supports maintaining high code quality and adherence to OpenIM's rigorous testing benchmarks.
|
||||
|
||||
## E2E Test
|
||||
|
||||
TODO
|
||||
|
||||
## Api Test
|
||||
|
||||
The `test.sh` script is located within the `./scripts/install/` directory of the OpenIM service's codebase. To use the script, navigate to this directory from your terminal:
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 207 KiB After Width: | Height: | Size: 207 KiB |
|
Before Width: | Height: | Size: 118 KiB After Width: | Height: | Size: 118 KiB |
@ -304,7 +304,6 @@ func (m *MessageApi) BatchSendMsg(c *gin.Context) {
|
||||
apiresp.GinError(c, errs.ErrArgs.WithDetail(err.Error()).Wrap())
|
||||
return
|
||||
}
|
||||
log.ZInfo(c, "BatchSendMsg", "req", req)
|
||||
if err := authverify.CheckAdmin(c, m.manager, m.imAdmin); err != nil {
|
||||
apiresp.GinError(c, errs.ErrNoPermission.WrapMsg("only app manager can send message"))
|
||||
return
|
||||
|
||||
@ -187,7 +187,7 @@ func (s *Server) KickUserOffline(
|
||||
for _, v := range req.KickUserIDList {
|
||||
clients, _, ok := s.LongConnServer.GetUserPlatformCons(v, int(req.PlatformID))
|
||||
if !ok {
|
||||
log.ZInfo(ctx, "conn not exist", "userID", v, "platformID", req.PlatformID)
|
||||
log.ZDebug(ctx, "conn not exist", "userID", v, "platformID", req.PlatformID)
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@ -315,14 +315,8 @@ func (och *OnlineHistoryRedisConsumerHandler) MessagesDistributionHandle() {
|
||||
for i, header := range consumerMessages[i].Headers {
|
||||
arr = append(arr, strconv.Itoa(i), string(header.Key), string(header.Value))
|
||||
}
|
||||
log.ZInfo(
|
||||
ctx,
|
||||
"consumer.kafka.GetContextWithMQHeader",
|
||||
"len",
|
||||
len(consumerMessages[i].Headers),
|
||||
"header",
|
||||
strings.Join(arr, ", "),
|
||||
)
|
||||
log.ZInfo(ctx, "consumer.kafka.GetContextWithMQHeader", "len", len(consumerMessages[i].Headers),
|
||||
"header", strings.Join(arr, ", "))
|
||||
ctxMsg.ctx = kafka.GetContextWithMQHeader(consumerMessages[i].Headers)
|
||||
ctxMsg.message = msgFromMQ
|
||||
log.ZDebug(
|
||||
|
||||
@ -71,7 +71,7 @@ func (g *Client) Push(ctx context.Context, userIDs []string, title, content stri
|
||||
token, err := g.cache.GetGetuiToken(ctx)
|
||||
if err != nil {
|
||||
if errs.Unwrap(err) == redis.Nil {
|
||||
log.ZInfo(ctx, "getui token not exist in redis")
|
||||
log.ZDebug(ctx, "getui token not exist in redis")
|
||||
token, err = g.getTokenAndSave2Redis(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@ -237,7 +237,7 @@ func (p *Pusher) Push2SuperGroup(ctx context.Context, groupID string, msg *sdkws
|
||||
if p.UnmarshalNotificationElem(msg.Content, &tips) != nil {
|
||||
return err
|
||||
}
|
||||
log.ZInfo(ctx, "GroupDismissedNotificationInfo****", "groupID", groupID, "num", len(pushToUserIDs), "list", pushToUserIDs)
|
||||
log.ZDebug(ctx, "GroupDismissedNotificationInfo****", "groupID", groupID, "num", len(pushToUserIDs), "list", pushToUserIDs)
|
||||
if len(p.config.Manager.UserID) > 0 {
|
||||
ctx = mcontext.WithOpUserIDContext(ctx, p.config.Manager.UserID[0])
|
||||
}
|
||||
|
||||
@ -876,7 +876,7 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbgroup.JoinGroupReq)
|
||||
} else if !s.IsNotFound(err) && errs.Unwrap(err) != errs.ErrRecordNotFound {
|
||||
return nil, err
|
||||
}
|
||||
log.ZInfo(ctx, "JoinGroup.groupInfo", "group", group, "eq", group.NeedVerification == constant.Directly)
|
||||
log.ZDebug(ctx, "JoinGroup.groupInfo", "group", group, "eq", group.NeedVerification == constant.Directly)
|
||||
if group.NeedVerification == constant.Directly {
|
||||
groupMember := &relationtb.GroupMemberModel{
|
||||
GroupID: group.GroupID,
|
||||
|
||||
@ -60,7 +60,7 @@ func (m *msgServer) RevokeMsg(ctx context.Context, req *msg.RevokeMsgReq) (*msg.
|
||||
}
|
||||
|
||||
data, _ := json.Marshal(msgs[0])
|
||||
log.ZInfo(ctx, "GetMsgBySeqs", "conversationID", req.ConversationID, "seq", req.Seq, "msg", string(data))
|
||||
log.ZDebug(ctx, "GetMsgBySeqs", "conversationID", req.ConversationID, "seq", req.Seq, "msg", string(data))
|
||||
var role int32
|
||||
if !authverify.IsAppManagerUid(ctx, &m.config.Manager, &m.config.IMAdmin) {
|
||||
switch msgs[0].SessionType {
|
||||
|
||||
2
pkg/common/db/cache/group.go
vendored
2
pkg/common/db/cache/group.go
vendored
@ -237,7 +237,7 @@ func (g *GroupCacheRedis) GetGroupMemberHashMap(ctx context.Context, groupIDs []
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.ZInfo(ctx, "GetGroupMemberHashMap", "groupID", groupID, "hash", hash)
|
||||
log.ZDebug(ctx, "GetGroupMemberHashMap", "groupID", groupID, "hash", hash)
|
||||
num, err := g.GetGroupMemberNum(ctx, groupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@ -533,7 +533,7 @@ func (db *commonMsgDatabase) GetMsgBySeqsRange(ctx context.Context, userID strin
|
||||
}
|
||||
// "minSeq" represents the startSeq value that the user can retrieve.
|
||||
if minSeq > end {
|
||||
log.ZInfo(ctx, "minSeq > end", "minSeq", minSeq, "end", end)
|
||||
log.ZWarn(ctx, "minSeq > end", errs.New("minSeq>end"), "minSeq", minSeq, "end", end)
|
||||
return 0, 0, nil, nil
|
||||
}
|
||||
maxSeq, err := db.cache.GetMaxSeq(ctx, conversationID)
|
||||
@ -681,22 +681,8 @@ func (db *commonMsgDatabase) GetMsgBySeqs(ctx context.Context, userID string, co
|
||||
log.ZError(ctx, "get message from redis exception", err, "failedSeqs", failedSeqs, "conversationID", conversationID)
|
||||
}
|
||||
}
|
||||
log.ZInfo(
|
||||
ctx,
|
||||
"db.cache.GetMessagesBySeq",
|
||||
"userID",
|
||||
userID,
|
||||
"conversationID",
|
||||
conversationID,
|
||||
"seqs",
|
||||
seqs,
|
||||
"successMsgs",
|
||||
len(successMsgs),
|
||||
"failedSeqs",
|
||||
failedSeqs,
|
||||
"conversationID",
|
||||
conversationID,
|
||||
)
|
||||
log.ZDebug(ctx, "db.cache.GetMessagesBySeq", "userID", userID, "conversationID", conversationID, "seqs",
|
||||
seqs, "len(successMsgs)", len(successMsgs), "failedSeqs", failedSeqs)
|
||||
|
||||
if len(failedSeqs) > 0 {
|
||||
mongoMsgs, err := db.getMsgBySeqs(ctx, userID, conversationID, failedSeqs)
|
||||
@ -717,7 +703,7 @@ func (db *commonMsgDatabase) DeleteConversationMsgsAndSetMinSeq(ctx context.Cont
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.ZInfo(ctx, "DeleteConversationMsgsAndSetMinSeq", "conversationID", conversationID, "minSeq", minSeq)
|
||||
log.ZDebug(ctx, "DeleteConversationMsgsAndSetMinSeq", "conversationID", conversationID, "minSeq", minSeq)
|
||||
if minSeq == 0 {
|
||||
return nil
|
||||
}
|
||||
@ -896,7 +882,7 @@ func (db *commonMsgDatabase) CleanUpUserConversationsMsgs(ctx context.Context, u
|
||||
maxSeq, err := db.cache.GetMaxSeq(ctx, conversationID)
|
||||
if err != nil {
|
||||
if err == redis.Nil {
|
||||
log.ZInfo(ctx, "max seq is nil", "conversationID", conversationID)
|
||||
log.ZDebug(ctx, "max seq is nil", "conversationID", conversationID)
|
||||
} else {
|
||||
log.ZError(ctx, "get max seq failed", err, "conversationID", conversationID)
|
||||
}
|
||||
|
||||
@ -859,7 +859,7 @@ func (m *MsgMgo) ConvertMsgsDocLen(ctx context.Context, conversationIDs []string
|
||||
if len(msgDocs) < 1 {
|
||||
continue
|
||||
}
|
||||
log.ZInfo(ctx, "msg doc convert", "conversationID", conversationID, "len(msgDocs)", len(msgDocs))
|
||||
log.ZDebug(ctx, "msg doc convert", "conversationID", conversationID, "len(msgDocs)", len(msgDocs))
|
||||
if len(msgDocs[0].Msg) == int(m.model.GetSingleGocMsgNum5000()) {
|
||||
if err := mongoutil.DeleteMany(ctx, m.coll, bson.M{"doc_id": regex}); err != nil {
|
||||
log.ZError(ctx, "convertAll delete many failed", err, "conversationID", conversationID)
|
||||
@ -891,7 +891,7 @@ func (m *MsgMgo) ConvertMsgsDocLen(ctx context.Context, conversationIDs []string
|
||||
if err = mongoutil.InsertMany(ctx, m.coll, newMsgDocs); err != nil {
|
||||
log.ZError(ctx, "convertAll insert many failed", err, "conversationID", conversationID, "len(newMsgDocs)", len(newMsgDocs))
|
||||
} else {
|
||||
log.ZInfo(ctx, "msg doc convert", "conversationID", conversationID, "len(newMsgDocs)", len(newMsgDocs))
|
||||
log.ZDebug(ctx, "msg doc convert", "conversationID", conversationID, "len(newMsgDocs)", len(newMsgDocs))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@ import (
|
||||
|
||||
"github.com/openimsdk/protocol/msg"
|
||||
"github.com/openimsdk/protocol/sdkws"
|
||||
"github.com/openimsdk/tools/errs"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
)
|
||||
|
||||
|
||||
@ -15,8 +15,6 @@
|
||||
package discoveryregister
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/discoveryregister/direct"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/discoveryregister/kubernetes"
|
||||
@ -28,10 +26,6 @@ import (
|
||||
// NewDiscoveryRegister creates a new service discovery and registry client based on the provided environment type.
|
||||
func NewDiscoveryRegister(config *config.GlobalConfig) (discovery.SvcDiscoveryRegistry, error) {
|
||||
|
||||
if os.Getenv("ENVS_DISCOVERY") != "" {
|
||||
config.Envs.Discovery = os.Getenv("ENVS_DISCOVERY")
|
||||
}
|
||||
|
||||
switch config.Envs.Discovery {
|
||||
case "zookeeper":
|
||||
return zookeeper.NewZookeeperDiscoveryRegister(&config.Zookeeper)
|
||||
|
||||
@ -104,6 +104,7 @@ func getSelfHost(ctx context.Context, gatewayName string) string {
|
||||
}
|
||||
|
||||
// like openimserver-openim-msggateway-0.openimserver-openim-msggateway-headless.openim-lin.svc.cluster.local:88.
|
||||
// Replica set in kubernetes environment
|
||||
func getMsgGatewayHost(ctx context.Context, gatewayName string) []string {
|
||||
port := 88
|
||||
instance := "openimserver"
|
||||
@ -124,7 +125,7 @@ func getMsgGatewayHost(ctx context.Context, gatewayName string) []string {
|
||||
host := fmt.Sprintf("%s-openim-msggateway-%d.%s-openim-msggateway-headless.%s.svc.cluster.local:%d", instance, i, instance, ns, port)
|
||||
ret = append(ret, host)
|
||||
}
|
||||
log.ZInfo(ctx, "getMsgGatewayHost", "instance", instance, "selfPodName", selfPodName, "replicas", replicas, "ns", ns, "ret", ret)
|
||||
log.ZDebug(ctx, "getMsgGatewayHost", "instance", instance, "selfPodName", selfPodName, "replicas", replicas, "ns", ns, "ret", ret)
|
||||
return ret
|
||||
}
|
||||
|
||||
@ -189,9 +190,10 @@ func (cli *K8sDR) CloseConn(conn *grpc.ClientConn) {
|
||||
|
||||
// do not use this method for call rpc.
|
||||
func (cli *K8sDR) GetClientLocalConns() map[string][]*grpc.ClientConn {
|
||||
fmt.Println("should not call this function!!!!!!!!!!!!!!!!!!!!!!!!!")
|
||||
log.ZError(context.Background(), "should not call this function!", nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cli *K8sDR) Close() {
|
||||
|
||||
}
|
||||
|
||||
@ -1,46 +1,64 @@
|
||||
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/
|
||||
source "${OPENIM_ROOT}/lib/util.sh"
|
||||
source "${OPENIM_ROOT}/define/binaries.sh"
|
||||
source "${OPENIM_ROOT}/lib/path.sh"
|
||||
|
||||
source "$(dirname "${BASH_SOURCE[0]}")/lib/util.sh"
|
||||
source "$(dirname "${BASH_SOURCE[0]}")/define/binaries.sh"
|
||||
source "$(dirname "${BASH_SOURCE[0]}")/lib/path.sh"
|
||||
source "$(dirname "${BASH_SOURCE[0]}")/lib/logging.sh"
|
||||
|
||||
|
||||
#停止所有的二进制对应的进程
|
||||
stop_binaries{
|
||||
stop_binaries() {
|
||||
for binary in "${!binaries[@]}"; do
|
||||
full_path=$(get_bin_full_path "$binary")
|
||||
openim::util::kill_exist_binary "$full_path"
|
||||
done
|
||||
}
|
||||
|
||||
LOG_FILE=log.file
|
||||
ERR_LOG_FILE=err.log.file
|
||||
|
||||
#启动所有的二进制
|
||||
start_binaries() {
|
||||
local project_dir="$OPENIM_ROOT" # You should adjust this path as necessary
|
||||
# Iterate over binaries defined in binary_path.sh
|
||||
for binary in "${!binaries[@]}"; do
|
||||
local count=${binaries[$binary]}
|
||||
local bin_full_path=$(get_bin_full_path "$binary")
|
||||
# Loop to start binary the specified number of times
|
||||
for ((i=0; i<count; i++)); do
|
||||
echo "Starting $binary instance $i: $bin_full_path -i $i -c $OPENIM_OUTPUT_CONFIG"
|
||||
nohup "$bin_full_path" -i "$i" -c "$OPENIM_OUTPUT_CONFIG" > "test.log" 2>&1 &
|
||||
|
||||
echo "Starting $bin_full_path -i $i -c $OPENIM_OUTPUT_CONFIG"
|
||||
cmd=("$bin_full_path" -i "$i" -c "$OPENIM_OUTPUT_CONFIG")
|
||||
nohup "${cmd[@]}" >> "${LOG_FILE}" 2> >(tee -a "$ERR_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) &
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
start_tools() {
|
||||
# Assume tool_binaries=("ncpu" "infra")
|
||||
for binary in "${tool_binaries[@]}"; do
|
||||
local bin_full_path=$(get_tool_full_path "$binary")
|
||||
cmd=("$bin_full_path" -c "$OPENIM_OUTPUT_CONFIG")
|
||||
echo "Starting ${cmd[@]}"
|
||||
"${cmd[@]}"
|
||||
ret_val=$?
|
||||
if [ $ret_val -eq 0 ]; then
|
||||
echo "Started $bin_full_path successfully."
|
||||
else
|
||||
echo "Failed to start $bin_full_path with exit code $ret_val."
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#kill二进制全路径对应的进程
|
||||
kill_exist_binaries(){
|
||||
for binary in "${!binaries[@]}"; do
|
||||
full_path=$(get_bin_full_path "$binary")
|
||||
result=$(openim::util::kill_exist_binary "$full_path" | tail -n1)
|
||||
if [ "$result" -eq 0 ]; then
|
||||
else
|
||||
echo "$full_path running. waiting stop"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
@ -60,10 +78,8 @@ check_binaries_stop() {
|
||||
done
|
||||
|
||||
if [ "$running_binaries" -ne 0 ]; then
|
||||
echo "There are $running_binaries binaries still running. Aborting..."
|
||||
return 1
|
||||
else
|
||||
echo "All processes have been stopped."
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
@ -71,27 +87,32 @@ check_binaries_stop() {
|
||||
|
||||
|
||||
#检查所有的二进制是否运行
|
||||
check_binaries_running{
|
||||
check_binaries_running(){
|
||||
local no_running_binaries=0
|
||||
for binary in "${!binaries[@]}"; do
|
||||
expected_count=${binaries[$binary]}
|
||||
full_path=$(get_bin_full_path "$binary")
|
||||
|
||||
result=$(openim::util::check_process_names "$full_path" "$expected_count")
|
||||
if [ "$result" -eq 0 ]; then
|
||||
echo "$binary is running normally."
|
||||
return 0
|
||||
else
|
||||
echo "$binary is not running normally, $result processes missing."
|
||||
return 1
|
||||
ret_val=$?
|
||||
if [ "$ret_val" -ne 0 ]; then
|
||||
no_running_binaries=$((no_running_binaries + 1))
|
||||
echo $result
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$no_running_binaries" -ne 0 ]; then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#打印所有的二进制对应的进程所所监听的端口
|
||||
print_listened_ports_by_binaries{
|
||||
print_listened_ports_by_binaries(){
|
||||
for binary in "${!binaries[@]}"; do
|
||||
expected_count=${binaries[$binary]}
|
||||
base_path=$(get_bin_full_path "$binary")
|
||||
|
||||
@ -24,20 +24,23 @@
|
||||
|
||||
|
||||
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/
|
||||
source "${OPENIM_ROOT}/lib/util.sh"
|
||||
source "${OPENIM_ROOT}/define/binaries.sh"
|
||||
source "${OPENIM_ROOT}/lib/path.sh"
|
||||
|
||||
OPENIM_SCRIPTS=$(dirname "${BASH_SOURCE[0]}")/
|
||||
source "$OPENIM_SCRIPTS/bricks.sh"
|
||||
|
||||
|
||||
|
||||
result=$(check_binaries_running)
|
||||
ret_val=$?
|
||||
|
||||
if [ $ret_val -eq 0 ]; then
|
||||
echo "All binaries are running."
|
||||
openim::log::print_green "All services are running normally."
|
||||
else
|
||||
echo "$result"
|
||||
openim::log::print_red "Some services are not running as expected. Details are as follows:"
|
||||
openim::log::print_red_no_time_stamp "$result"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
result=$(print_listened_ports_by_binaries)
|
||||
openim::log::print_green_two_line "$result"
|
||||
|
||||
|
||||
|
||||
@ -4,5 +4,8 @@
|
||||
# The count for openim-msgtransfer is set to 4, all others are set to 1.
|
||||
declare -A binaries=(
|
||||
[openim-test]=2
|
||||
[openim-no-port]=2
|
||||
)
|
||||
|
||||
|
||||
tool_binaries=("ncpu" "infra")
|
||||
|
||||
@ -254,10 +254,45 @@ function openim::log::test_log() {
|
||||
|
||||
# openim::log::test_log
|
||||
|
||||
function openim::log::print_blue() {
|
||||
echo -e "\033[0;36m$1\033[0m"
|
||||
|
||||
function openim::log::print_blue_two_line() {
|
||||
local current_time=$(date "+%Y-%m-%d %H:%M:%S %Z")
|
||||
echo -e "[$current_time]"
|
||||
echo -e "\033[0;34m$1\033[0m"
|
||||
}
|
||||
|
||||
function openim::log::print_blue() {
|
||||
local current_time=$(date "+%Y-%m-%d %H:%M:%S %Z")
|
||||
echo -e "[$current_time] \033[0;34m$1\033[0m"
|
||||
}
|
||||
|
||||
|
||||
function openim::log::print_green_two_line() {
|
||||
local current_time=$(date "+%Y-%m-%d %H:%M:%S %Z")
|
||||
echo -e "[$current_time]"
|
||||
echo -e "\033[0;32m$1\033[0m"
|
||||
}
|
||||
|
||||
function openim::log::print_green() {
|
||||
local current_time=$(date "+%Y-%m-%d %H:%M:%S %Z")
|
||||
echo -e "[$current_time] \033[0;32m$1\033[0m"
|
||||
}
|
||||
|
||||
|
||||
function openim::log::print_red() {
|
||||
local current_time=$(date "+%Y-%m-%d %H:%M:%S %Z")
|
||||
echo -e "[$current_time] \033[0;31m$1\033[0m"
|
||||
}
|
||||
|
||||
function openim::log::print_red_no_time_stamp() {
|
||||
echo -e "\033[0;31m$1\033[0m"
|
||||
}
|
||||
|
||||
function openim::log::print_green_no_time_stamp() {
|
||||
echo -e "\033[0;32m$1\033[0m"
|
||||
}
|
||||
|
||||
|
||||
|
||||
openim::log::colorless() {
|
||||
local V="${V:-0}"
|
||||
|
||||
@ -14,3 +14,8 @@ get_bin_full_path() {
|
||||
|
||||
|
||||
|
||||
get_tool_full_path() {
|
||||
local tool_name="$1"
|
||||
local tool_full_path="${OPENIM_OUTPUT_HOSTBIN_TOOLS}/${tool_name}"
|
||||
echo ${tool_full_path}
|
||||
}
|
||||
|
||||
@ -375,13 +375,7 @@ openim::util::check_ports() {
|
||||
# openim::util::check_ports 10002 1004 12345 13306
|
||||
#
|
||||
|
||||
# The `openim::util::check_process_names` function analyzes the state of processes based on given names.
|
||||
# It accepts multiple process names as arguments and prints:
|
||||
# 1. The state of the process (whether it's running or not).
|
||||
# 2. The start time of the process if it's running.
|
||||
# User:
|
||||
# openim::util::check_process_names nginx mysql redis
|
||||
# The function returns a status of 1 if any of the processes is not running.
|
||||
|
||||
|
||||
openim::util::check_process_names() {
|
||||
local process_path="$1"
|
||||
@ -391,9 +385,10 @@ openim::util::check_process_names() {
|
||||
local running_count=$(ps -ef | grep "$process_path" | grep -v grep | wc -l)
|
||||
|
||||
if [ "$running_count" -eq "$expected_count" ]; then
|
||||
echo 0
|
||||
return 0
|
||||
else
|
||||
echo $(($expected_count - $running_count))
|
||||
echo "$process_path Expected $expected_count processes, but $running_count running"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
@ -414,94 +409,7 @@ openim::util::check_process_names_exist() {
|
||||
|
||||
|
||||
|
||||
openim::util::check_process_names_for_stop() {
|
||||
# Function to get the port of a process
|
||||
get_port() {
|
||||
local pid=$1
|
||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
# Linux
|
||||
ss -ltnp 2>/dev/null | grep $pid | awk '{print $4}' | cut -d ':' -f2
|
||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
# macOS
|
||||
lsof -nP -iTCP -sTCP:LISTEN -a -p $pid | awk 'NR>1 {print $9}' | sed 's/.*://'
|
||||
else
|
||||
echo "Unsupported OS"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Arrays to collect details of processes
|
||||
local not_started=()
|
||||
local started=()
|
||||
|
||||
|
||||
# Iterate over each given process name
|
||||
for process_name in "$@"; do
|
||||
# Use `pgrep` to find process IDs related to the given process name
|
||||
local pids=($(pgrep -f $process_name))
|
||||
|
||||
# Check if any process IDs were found
|
||||
if [[ ${#pids[@]} -eq 0 ]]; then
|
||||
not_started+=($process_name)
|
||||
else
|
||||
# If there are PIDs, loop through each one
|
||||
for pid in "${pids[@]}"; do
|
||||
local command=$(ps -p $pid -o comm=)
|
||||
local start_time=$(ps -p $pid -o lstart=)
|
||||
local port=$(get_port $pid)
|
||||
|
||||
# Check if port information was found for the PID
|
||||
if [[ -z $port ]]; then
|
||||
port="N/A"
|
||||
fi
|
||||
|
||||
started+=("Process $process_name - Command: $command, PID: $pid, Port: $port, Start time: $start_time")
|
||||
done
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
if [[ ${#started[@]} -ne 0 ]]; then
|
||||
echo
|
||||
echo "The programs that have not exited are:"
|
||||
for info in "${started[@]}"; do
|
||||
echo "$info "
|
||||
done
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
|
||||
}
|
||||
|
||||
# openim::util::check_process_names docker-pr
|
||||
|
||||
# The `openim::util::stop_services_on_ports` function stops services running on specified ports.
|
||||
# It accepts multiple ports as arguments and performs the following:
|
||||
# 1. Attempts to stop any services running on the specified ports.
|
||||
# 2. Prints details of services successfully stopped and those that failed to stop.
|
||||
# Usage:
|
||||
# openim::util::stop_services_on_ports 8080 8081 8082
|
||||
# The function returns a status of 1 if any service couldn't be stopped.
|
||||
|
||||
# nc -l -p 12345
|
||||
# nc -l -p 123456
|
||||
# ps -ef | grep "nc -l"
|
||||
# openim::util::stop_services_on_ports 1234 12345
|
||||
|
||||
|
||||
# The `openim::util::stop_services_with_name` function stops services with specified names.
|
||||
# It accepts multiple service names as arguments and performs the following:
|
||||
# 1. Attempts to stop any services with the specified names.
|
||||
# 2. Prints details of services successfully stopped and those that failed to stop.
|
||||
# Usage:
|
||||
# openim::util::stop_services_with_name nginx apache
|
||||
# The function returns a status of 1 if any service couldn't be stopped.
|
||||
|
||||
# sleep 333333&
|
||||
# sleep 444444&
|
||||
# ps -ef | grep "sleep"
|
||||
# openim::util::stop_services_with_name "sleep 333333" "sleep 444444"
|
||||
|
||||
# This figures out the host platform without relying on golang. We need this as
|
||||
# we don't want a golang install to be a prerequisite to building yet we need
|
||||
@ -1513,151 +1421,6 @@ openim::util::check_ports() {
|
||||
# openim::util::check_ports 10002 1004 12345 13306
|
||||
#
|
||||
|
||||
# The `openim::util::check_process_names` function analyzes the state of processes based on given names.
|
||||
# It accepts multiple process names as arguments and prints:
|
||||
# 1. The state of the process (whether it's running or not).
|
||||
# 2. The start time of the process if it's running.
|
||||
# User:
|
||||
# openim::util::check_process_names nginx mysql redis
|
||||
# The function returns a status of 1 if any of the processes is not running.
|
||||
openim::util::check_process_names() {
|
||||
# Function to get the port of a process
|
||||
get_port() {
|
||||
local pid=$1
|
||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
# Linux
|
||||
ss -ltnp 2>/dev/null | grep $pid | awk '{print $4}' | cut -d ':' -f2
|
||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
# macOS
|
||||
lsof -nP -iTCP -sTCP:LISTEN -a -p $pid | awk 'NR>1 {print $9}' | sed 's/.*://'
|
||||
else
|
||||
echo "Unsupported OS"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Arrays to collect details of processes
|
||||
local not_started=()
|
||||
local started=()
|
||||
|
||||
echo "Checking processes: $*"
|
||||
# Iterate over each given process name
|
||||
for process_name in "$@"; do
|
||||
# Use `pgrep` to find process IDs related to the given process name
|
||||
local pids=($(pgrep -f $process_name))
|
||||
|
||||
# Check if any process IDs were found
|
||||
if [[ ${#pids[@]} -eq 0 ]]; then
|
||||
not_started+=($process_name)
|
||||
else
|
||||
# If there are PIDs, loop through each one
|
||||
for pid in "${pids[@]}"; do
|
||||
local command=$(ps -p $pid -o cmd=)
|
||||
local start_time=$(ps -p $pid -o lstart=)
|
||||
local port=$(get_port $pid)
|
||||
|
||||
# Check if port information was found for the PID
|
||||
if [[ -z $port ]]; then
|
||||
port="N/A"
|
||||
fi
|
||||
|
||||
started+=("Process $process_name - Command: $command, PID: $pid, Port: $port, Start time: $start_time")
|
||||
done
|
||||
fi
|
||||
done
|
||||
|
||||
# Print information
|
||||
if [[ ${#not_started[@]} -ne 0 ]]; then
|
||||
echo "Not started processes:"
|
||||
for process_name in "${not_started[@]}"; do
|
||||
openim::log::error "Process $process_name is not started."
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ ${#started[@]} -ne 0 ]]; then
|
||||
echo
|
||||
echo "Started processes:"
|
||||
for info in "${started[@]}"; do
|
||||
echo "$info"
|
||||
done
|
||||
fi
|
||||
|
||||
# Return status
|
||||
if [[ ${#not_started[@]} -ne 0 ]]; then
|
||||
openim::color::echo $COLOR_RED " OpenIM Stdout Log >> cat ${LOG_FILE}"
|
||||
openim::color::echo $COLOR_RED " OpenIM Stderr Log >> cat ${STDERR_LOG_FILE}"
|
||||
cat "$TMP_LOG_FILE" | awk '{print "\033[31m" $0 "\033[0m"}'
|
||||
return 1
|
||||
else
|
||||
echo ""
|
||||
openim::log::success "All processes are running."
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
# openim::util::check_process_names docker-pr
|
||||
|
||||
# The `openim::util::stop_services_on_ports` function stops services running on specified ports.
|
||||
# It accepts multiple ports as arguments and performs the following:
|
||||
# 1. Attempts to stop any services running on the specified ports.
|
||||
# 2. Prints details of services successfully stopped and those that failed to stop.
|
||||
# Usage:
|
||||
# openim::util::stop_services_on_ports 8080 8081 8082
|
||||
# The function returns a status of 1 if any service couldn't be stopped.
|
||||
openim::util::stop_services_on_ports() {
|
||||
# An array to collect ports of processes that couldn't be stopped.
|
||||
local not_stopped=()
|
||||
|
||||
# An array to collect information about processes that were stopped.
|
||||
local stopped=()
|
||||
|
||||
echo "Stopping services on ports: $*"
|
||||
# Iterate over each given port.
|
||||
for port in "$@"; do
|
||||
# Use the `lsof` command to find process information related to the given port.
|
||||
info=$(lsof -i :$port -n -P | grep LISTEN || true)
|
||||
|
||||
# If there's process information, it means the process associated with the port is running.
|
||||
if [[ -n $info ]]; then
|
||||
# Extract the Process ID.
|
||||
while read -r line; do
|
||||
local pid=$(echo $line | awk '{print $2}')
|
||||
|
||||
# Try to stop the service by killing its process.
|
||||
if kill -10 $pid; then
|
||||
stopped+=($port)
|
||||
else
|
||||
not_stopped+=($port)
|
||||
fi
|
||||
done <<< "$info"
|
||||
fi
|
||||
done
|
||||
|
||||
# Print information about ports whose processes couldn't be stopped.
|
||||
if [[ ${#not_stopped[@]} -ne 0 ]]; then
|
||||
echo "Ports that couldn't be stopped:"
|
||||
for port in "${not_stopped[@]}"; do
|
||||
openim::log::status "Failed to stop service on port $port."
|
||||
done
|
||||
fi
|
||||
|
||||
# Print information about ports whose processes were successfully stopped.
|
||||
if [[ ${#stopped[@]} -ne 0 ]]; then
|
||||
for port in "${stopped[@]}"; do
|
||||
echo "Successfully stopped service on port $port."
|
||||
done
|
||||
fi
|
||||
|
||||
# If any of the processes couldn't be stopped, return a status of 1.
|
||||
if [[ ${#not_stopped[@]} -ne 0 ]]; then
|
||||
return 1
|
||||
else
|
||||
openim::log::success "All specified services were stopped."
|
||||
echo ""
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# The `openim::util::stop_services_with_name` function stops services with specified names.
|
||||
# It accepts multiple service names as arguments and performs the following:
|
||||
@ -2672,68 +2435,7 @@ function openim::util::is_running_in_container() {
|
||||
}
|
||||
|
||||
|
||||
function openim::util::check_process_names_for_stop() {
|
||||
local all_stopped=true
|
||||
for service in "${OPENIM_ALL_SERVICE_LIBRARIES[@]}"; do
|
||||
|
||||
PIDS=$(pgrep -f "${service}") || PIDS="0"
|
||||
if [ "$PIDS" = "0" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
|
||||
NUM_PROCESSES=$(echo "$PIDS" | wc -l | xargs)
|
||||
if [ "$NUM_PROCESSES" -gt 0 ]; then
|
||||
all_stopped=false
|
||||
echo "Found $NUM_PROCESSES processes for ${service}"
|
||||
for PID in $PIDS; do
|
||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
echo -e "\033[31m$(ps -p $PID -o pid,cmd)\033[0m"
|
||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
echo -e "\033[31m$(ps -p $PID -o pid,comm)\033[0m"
|
||||
else
|
||||
openim::log::error "Unsupported OS type: $OSTYPE"
|
||||
fi
|
||||
done
|
||||
echo "Processes for ${service} have not been stopped properly. " "$NUM_PROCESSES"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$all_stopped" = true ]; then
|
||||
openim::log::success "All processes have been stopped properly."
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function openim::util::find_process_ports() {
|
||||
local process_path="$1"
|
||||
if [[ -z "$process_path" ]]; then
|
||||
echo "Usage: find_process_ports /path/to/process"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local protocol_ports=""
|
||||
while read -r line; do
|
||||
local port_protocol=($line)
|
||||
local port=${port_protocol[0]##*:}
|
||||
local protocol=${port_protocol[1]}
|
||||
protocol_ports="${protocol_ports}${protocol} ${port}, "
|
||||
|
||||
done < <(lsof -nP -iTCP -iUDP | grep LISTEN | grep "$(pgrep -f "$process_path")" | awk '{print $9, $8}')
|
||||
|
||||
protocol_ports=${protocol_ports%, }
|
||||
|
||||
if [[ -z "$protocol_ports" ]]; then
|
||||
openim::log::colorless "$process_path is not listening on any ports"
|
||||
else
|
||||
openim::log::colorless "$process_path is listening on protocol & port: $protocol_ports"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -2753,8 +2455,6 @@ function openim::util::print_binary_ports() {
|
||||
|
||||
# Check if the binary is running
|
||||
if pgrep -f "$binary_path" > /dev/null; then
|
||||
# echo "$binary_name is running." "arg $1"
|
||||
|
||||
# Find the PID(s) of the running binary
|
||||
pids=$(pgrep -f "$binary_path")
|
||||
|
||||
@ -2766,11 +2466,9 @@ function openim::util::print_binary_ports() {
|
||||
# Check for listening ports using lsof
|
||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
# Linux
|
||||
# Append found ports to the ports variable, followed by a space
|
||||
ports+=$(lsof -i -n | grep LISTEN | grep "$pid" | awk '{print $9}' | cut -d':' -f2 | uniq | tr '\n' ' ')
|
||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
# macOS
|
||||
# Append found ports to the ports variable, followed by a space
|
||||
ports+=$(lsof -i -n | grep LISTEN | grep "$pid" | awk '{print $9}' | awk -F'[:\.]+' '{print $(NF-1)}' | uniq | tr '\n' ' ')
|
||||
fi
|
||||
done
|
||||
@ -2778,7 +2476,7 @@ function openim::util::print_binary_ports() {
|
||||
# Remove trailing spaces and duplicate ports if any
|
||||
ports=$(echo "$ports" | xargs | tr ' ' '\n' | uniq | tr '\n' ' ')
|
||||
|
||||
if [ -z "$ports" ]; then
|
||||
if [[ ${#ports} -eq 1 ]]; then
|
||||
echo "$binary_path is not listening on any ports."
|
||||
else
|
||||
echo "$binary_path is listening on the following ports: $ports"
|
||||
@ -2790,6 +2488,7 @@ function openim::util::print_binary_ports() {
|
||||
|
||||
|
||||
|
||||
|
||||
function openim::util::kill_exist_binary() {
|
||||
local binary_path="$1"
|
||||
local pids=$(pgrep -f "$binary_path")
|
||||
|
||||
@ -2,10 +2,8 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
OPENIM_SCRIPTS=$(dirname "${BASH_SOURCE[0]}")/
|
||||
source "$OPENIM_SCRIPTS/lib/path.sh"
|
||||
source "$OPENIM_SCRIPTS/define/binaries.sh"
|
||||
source "$OPENIM_SCRIPTS/bricks.sh"
|
||||
|
||||
|
||||
# Assuming 'openim::util::host_platform' is defined in one of the sourced scripts or elsewhere.
|
||||
@ -13,28 +11,39 @@ source "$OPENIM_SCRIPTS/define/binaries.sh"
|
||||
|
||||
# Main function to start binaries
|
||||
|
||||
openim::log::print_blue "Starting tools primarily involves component verification and other preparatory tasks."
|
||||
|
||||
|
||||
|
||||
result=$(start_tools)
|
||||
ret_val=$?
|
||||
if [ $ret_val -ne 0 ]; then
|
||||
openim::log::print_red "Some tools failed to start, details are as follows, abort start"
|
||||
openim::log::print_red_no_time_stamp "$result"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "$result"
|
||||
|
||||
|
||||
openim::log::print_green "All tools executed successfully"
|
||||
openim::log::print_blue "Starting services involves multiple RPCs and API and may take some time. Please be patient"
|
||||
|
||||
kill_exist_binaries
|
||||
|
||||
result=$(check_binaries_stop)
|
||||
ret_val=$?
|
||||
|
||||
if [ $ret_val -eq 0 ]; then
|
||||
echo "All binaries are stopped."
|
||||
else
|
||||
echo "$result"
|
||||
echo "abort..."
|
||||
exit 1
|
||||
if [ $ret_val -ne 0 ]; then
|
||||
openim::log::print_red "Some services running, details are as follows, abort start"
|
||||
openim::log::print_red_no_time_stamp "$result"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# Call the main function
|
||||
start_binaries
|
||||
|
||||
check_binaries_running
|
||||
|
||||
print_listened_ports_by_binaries
|
||||
|
||||
result=$(start_binaries)
|
||||
openim::log::print_blue_two_line "$result"
|
||||
|
||||
$OPENIM_SCRIPTS/check.sh
|
||||
|
||||
|
||||
@ -3,12 +3,21 @@
|
||||
|
||||
|
||||
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/
|
||||
source "${OPENIM_ROOT}/lib/util.sh"
|
||||
source "${OPENIM_ROOT}/define/binaries.sh"
|
||||
source "${OPENIM_ROOT}/lib/path.sh"
|
||||
|
||||
|
||||
|
||||
OPENIM_SCRIPTS=$(dirname "${BASH_SOURCE[0]}")/
|
||||
source "$OPENIM_SCRIPTS/bricks.sh"
|
||||
|
||||
|
||||
kill_exist_binaries
|
||||
|
||||
result=$(check_binaries_stop)
|
||||
ret_val=$?
|
||||
if [ $ret_val -ne 0 ]; then
|
||||
openim::log::print_red "Some services have not been stopped, details are as follows:"
|
||||
openim::log::print_red_no_time_stamp "$result"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
openim::log::print_green "All services have been stopped"
|
||||
@ -20,9 +20,6 @@
|
||||
# READ: https://github.com/openimsdk/open-im-server/tree/main/scripts/install/environment.sh
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
source "${OPENIM_ROOT}/scripts/install/common.sh"
|
||||
|
||||
@ -114,7 +111,3 @@ else
|
||||
openim::util::find_ports_for_all_services ${OPENIM_MSGTRANSFER_BINARY[@]}
|
||||
openim::log::success "All OpenIM services are running normally! "
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
58
scripts/make-rules/common-versions.mk
Normal file
58
scripts/make-rules/common-versions.mk
Normal file
@ -0,0 +1,58 @@
|
||||
# Copyright © 2023 OpenIMSDK.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
# OpenIM Makefile Versions used
|
||||
#
|
||||
# Define the latest version for each tool to ensure consistent versioning across installations
|
||||
GOLANGCI_LINT_VERSION ?= latest
|
||||
GOIMPORTS_VERSION ?= latest
|
||||
ADDLICENSE_VERSION ?= latest
|
||||
DEEPCOPY_GEN_VERSION ?= latest
|
||||
CONVERSION_GEN_VERSION ?= latest
|
||||
GINKGO_VERSION ?= v1.16.2
|
||||
GO_GITLINT_VERSION ?= latest
|
||||
GO_JUNIT_REPORT_VERSION ?= latest
|
||||
GOTESTS_VERSION ?= latest
|
||||
SWAGGER_VERSION ?= latest
|
||||
KUBE_SCORE_VERSION ?= latest
|
||||
KUBECONFORM_VERSION ?= latest
|
||||
GSEMVER_VERSION ?= latest
|
||||
GIT_CHGLOG_VERSION ?= latest
|
||||
KO_VERSION ?= latest
|
||||
GITHUB_RELEASE_VERSION ?= latest
|
||||
COSCLI_VERSION ?= v0.19.0-beta
|
||||
MINIO_VERSION ?= latest
|
||||
DELVE_VERSION ?= latest
|
||||
AIR_VERSION ?= latest
|
||||
GOLINES_VERSION ?= latest
|
||||
GO_MOD_OUTDATED_VERSION ?= latest
|
||||
CFSSL_VERSION ?= latest
|
||||
DEPTH_VERSION ?= latest
|
||||
GO_CALLVIS_VERSION ?= latest
|
||||
MISSPELL_VERSION ?= latest
|
||||
GOTHANKS_VERSION ?= latest
|
||||
RICHGO_VERSION ?= latest
|
||||
RTS_VERSION ?= latest
|
||||
TYPECHECK_VERSION ?= latest
|
||||
COMMENT_LANG_DETECTOR_VERSION ?= latest
|
||||
STANDARDIZER_VERSION ?= latest
|
||||
GO_TESTS_VERSION ?= v1.6.0
|
||||
GO_APIDIFF_VERSION ?= v0.8.2
|
||||
KAFKACTL_VERSION ?= latest
|
||||
GOTESTSUM_VERSION ?= latest
|
||||
|
||||
WIRE_VERSION ?= latest
|
||||
# WIRE_VERSION ?= $(call get_go_version,github.com/google/wire)
|
||||
MOCKGEN_VERSION ?= $(call get_go_version,github.com/golang/mock)
|
||||
PROTOC_GEN_GO_VERSION ?= $(call get_go_version,github.com/golang/protobuf/protoc-gen-go)
|
||||
@ -78,6 +78,13 @@ VERSION := $(shell git describe --tags --always --match='v*')
|
||||
# v2.3.3: git tag
|
||||
endif
|
||||
|
||||
# Helper function to get dependency version from go.mod
|
||||
get_gomod_version = $(shell go list -m $1 | awk '{print $$2}')
|
||||
define go_install
|
||||
$(info ===========> Installing $(1)@$(2))
|
||||
$(GO) install $(1)@$(2)
|
||||
endef
|
||||
|
||||
# Check if the tree is dirty. default to dirty(maybe u should commit?)
|
||||
GIT_TREE_STATE:="dirty"
|
||||
ifeq (, $(shell git status --porcelain 2>/dev/null))
|
||||
|
||||
@ -64,81 +64,101 @@ tools.verify.%:
|
||||
## install.golangci-lint: Install golangci-lint
|
||||
.PHONY: install.golangci-lint
|
||||
install.golangci-lint:
|
||||
@$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
||||
@$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
|
||||
|
||||
## install.goimports: Install goimports, used to format go source files
|
||||
.PHONY: install.goimports
|
||||
install.goimports:
|
||||
@$(GO) install golang.org/x/tools/cmd/goimports@latest
|
||||
@$(GO) install golang.org/x/tools/cmd/goimports@$(GOIMPORTS_VERSION)
|
||||
|
||||
## install.addlicense: Install addlicense, used to add license header to source files
|
||||
.PHONY: install.addlicense
|
||||
install.addlicense:
|
||||
@$(GO) install github.com/google/addlicense@latest
|
||||
@$(GO) install github.com/google/addlicense@$(ADDLICENSE_VERSION)
|
||||
|
||||
## install.deepcopy-gen: Install deepcopy-gen, used to generate deep copy functions
|
||||
.PHONY: install.deepcopy-gen
|
||||
install.deepcopy-gen:
|
||||
@$(GO) install k8s.io/code-generator/cmd/deepcopy-gen@latest
|
||||
@$(GO) install k8s.io/code-generator/cmd/deepcopy-gen@$(DEEPCOPY_GEN_VERSION)
|
||||
|
||||
## install.conversion-gen: Install conversion-gen, used to generate conversion functions
|
||||
.PHONY: install.conversion-gen
|
||||
install.conversion-gen:
|
||||
@$(GO) install k8s.io/code-generator/cmd/conversion-gen@latest
|
||||
@$(GO) install k8s.io/code-generator/cmd/conversion-gen@$(CONVERSION_GEN_VERSION)
|
||||
|
||||
## install.ginkgo: Install ginkgo to run a single test or set of tests
|
||||
.PHONY: install.ginkgo
|
||||
install.ginkgo:
|
||||
@$(GO) install github.com/onsi/ginkgo/ginkgo@v1.16.2
|
||||
@$(GO) install github.com/onsi/ginkgo/ginkgo@$(GINKGO_VERSION)
|
||||
|
||||
## Install go-gitlint: Install go-gitlint, used to check git commit message
|
||||
## install.go-gitlint: Install go-gitlint, used to check git commit message
|
||||
.PHONY: install.go-gitlint
|
||||
install.go-gitlint:
|
||||
@$(GO) install github.com/marmotedu/go-gitlint/cmd/go-gitlint@latest
|
||||
@$(GO) install github.com/marmotedu/go-gitlint/cmd/go-gitlint@$(GO_GITLINT_VERSION)
|
||||
|
||||
## install.go-junit-report: Install go-junit-report, used to convert go test output to junit xml
|
||||
.PHONY: install.go-junit-report
|
||||
install.go-junit-report:
|
||||
@$(GO) install github.com/jstemmer/go-junit-report@latest
|
||||
@$(GO) install github.com/jstemmer/go-junit-report@$(GO_JUNIT_REPORT_VERSION)
|
||||
|
||||
## install.gotests: Install gotests, used to generate go tests
|
||||
.PHONY: install.gotests
|
||||
install.gotests:
|
||||
@$(GO) install github.com/cweill/gotests/gotests@$(GO_TESTS_VERSION)
|
||||
|
||||
## install.kafkactl: Install kafkactl command line tool.
|
||||
.PHONY: install.kafkactl
|
||||
install.kafkactl:
|
||||
@$(GO) install github.com/deviceinsight/kafkactl@$(KAFKACTL_VERSION)
|
||||
|
||||
## install.go-apidiff: Install go-apidiff, used to check api changes
|
||||
.PHONY: install.go-apidiff
|
||||
install.go-apidiff:
|
||||
@$(GO) install github.com/joelanford/go-apidiff@$(GO_APIDIFF_VERSION)
|
||||
|
||||
## install.swagger: Install swagger, used to generate swagger documentation
|
||||
.PHONY: install.swagger
|
||||
install.swagger:
|
||||
@$(GO) install github.com/go-swagger/go-swagger/cmd/swagger@latest
|
||||
@$(GO) install github.com/go-swagger/go-swagger/cmd/swagger@$(SWAGGER_VERSION)
|
||||
|
||||
# ==============================================================================
|
||||
# Tools that might be used include go gvm
|
||||
#
|
||||
|
||||
## install.gotestsum: Install gotestsum, used to run go tests
|
||||
.PHONY: install.gotestsum
|
||||
install.gotestsum:
|
||||
@$(GO) install gotest.tools/gotestsum@$(GOTESTSUM_VERSION)
|
||||
|
||||
## install.kube-score: Install kube-score, used to check kubernetes yaml files
|
||||
.PHONY: install.kube-score
|
||||
install.kube-score:
|
||||
@$(GO) install github.com/zegl/kube-score/cmd/kube-score@latest
|
||||
@$(GO) install github.com/zegl/kube-score/cmd/kube-score@$(KUBE_SCORE_VERSION)
|
||||
|
||||
## install.kubeconform: Install kubeconform, used to check kubernetes yaml files
|
||||
.PHONY: install.kubeconform
|
||||
install.kubeconform:
|
||||
@$(GO) install github.com/yannh/kubeconform/cmd/kubeconform@latest
|
||||
@$(GO) install github.com/yannh/kubeconform/cmd/kubeconform@$(KUBECONFORM_VERSION)
|
||||
|
||||
## install.gsemver: Install gsemver, used to generate semver
|
||||
.PHONY: install.gsemver
|
||||
install.gsemver:
|
||||
@$(GO) install github.com/arnaud-deprez/gsemver@latest
|
||||
@$(GO) install github.com/arnaud-deprez/gsemver@$(GSEMVER_VERSION)
|
||||
|
||||
## install.git-chglog: Install git-chglog, used to generate changelog
|
||||
.PHONY: install.git-chglog
|
||||
install.git-chglog:
|
||||
@$(GO) install github.com/git-chglog/git-chglog/cmd/git-chglog@latest
|
||||
@$(GO) install github.com/git-chglog/git-chglog/cmd/git-chglog@$(GIT_CHGLOG_VERSION)
|
||||
|
||||
## install.ko: Install ko, used to build go program into container images
|
||||
.PHONY: install.ko
|
||||
install.ko:
|
||||
@$(GO) install github.com/google/ko@latest
|
||||
@$(GO) install github.com/google/ko@$(KO_VERSION)
|
||||
|
||||
## install.github-release: Install github-release, used to create github release
|
||||
.PHONY: install.github-release
|
||||
install.github-release:
|
||||
@$(GO) install github.com/github-release/github-release@latest
|
||||
@$(GO) install github.com/github-release/github-release@$(GITHUB_RELEASE_VERSION)
|
||||
|
||||
## install.coscli: Install coscli, used to upload files to cos
|
||||
# example: ./coscli cp/sync -r /home/off-line/docker-off-line/ cos://openim-1306374445/openim/image/amd/off-line/off-line/ -e cos.ap-guangzhou.myqcloud.com
|
||||
@ -146,7 +166,7 @@ install.github-release:
|
||||
# amd64
|
||||
.PHONY: install.coscli
|
||||
install.coscli:
|
||||
@wget -q https://github.com/tencentyun/coscli/releases/download/v0.19.0-beta/coscli-linux -O ${TOOLS_DIR}/coscli
|
||||
@wget -q https://github.com/tencentyun/coscli/releases/download/$(COSCLI_VERSION)/coscli-linux -O ${TOOLS_DIR}/coscli
|
||||
@chmod +x ${TOOLS_DIR}/coscli
|
||||
|
||||
## install.coscmd: Install coscmd, used to upload files to cos
|
||||
@ -157,50 +177,50 @@ install.coscmd:
|
||||
## install.minio: Install minio, used to upload files to minio
|
||||
.PHONY: install.minio
|
||||
install.minio:
|
||||
@$(GO) install github.com/minio/minio@latest
|
||||
@$(GO) install github.com/minio/minio@$(MINIO_VERSION)
|
||||
|
||||
## install.delve: Install delve, used to debug go program
|
||||
.PHONY: install.delve
|
||||
install.delve:
|
||||
@$(GO) install github.com/go-delve/delve/cmd/dlv@latest
|
||||
@$(GO) install github.com/go-delve/delve/cmd/dlv@$(DELVE_VERSION)
|
||||
|
||||
## install.air: Install air, used to hot reload go program
|
||||
.PHONY: install.air
|
||||
install.air:
|
||||
@$(GO) install github.com/cosmtrek/air@latest
|
||||
@$(GO) install github.com/cosmtrek/air@$(AIR_VERSION)
|
||||
|
||||
## install.gvm: Install gvm, gvm is a Go version manager, built on top of the official go tool.
|
||||
# github: https://github.com/moovweb/gvm
|
||||
.PHONY: install.gvm
|
||||
install.gvm:
|
||||
@echo "===========> Installing gvm,The default installation path is ~/.gvm/scripts/gvm"
|
||||
@echo "===========> Installing gvm, The default installation path is ~/.gvm/scripts/gvm"
|
||||
@bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
|
||||
@$(shell source /root/.gvm/scripts/gvm)
|
||||
@source /root/.gvm/scripts/gvm
|
||||
|
||||
## install.golines: Install golines, used to format long lines
|
||||
.PHONY: install.golines
|
||||
install.golines:
|
||||
@$(GO) install github.com/segmentio/golines@latest
|
||||
@$(GO) install github.com/segmentio/golines@$(GOLINES_VERSION)
|
||||
|
||||
## install.go-mod-outdated: Install go-mod-outdated, used to check outdated dependencies
|
||||
.PHONY: install.go-mod-outdated
|
||||
install.go-mod-outdated:
|
||||
@$(GO) install github.com/psampaz/go-mod-outdated@latest
|
||||
@$(GO) install github.com/psampaz/go-mod-outdated@$(GO_MOD_OUTDATED_VERSION)
|
||||
|
||||
## install.mockgen: Install mockgen, used to generate mock functions
|
||||
.PHONY: install.mockgen
|
||||
install.mockgen:
|
||||
@$(GO) install github.com/golang/mock/mockgen@latest
|
||||
@$(GO) install github.com/golang/mock/mockgen@$(MOCKGEN_VERSION)
|
||||
|
||||
## install.wire: Install wire, used to generate wire files
|
||||
.PHONY: install.wire
|
||||
install.wire:
|
||||
@$(GO) install github.com/google/wire/cmd/wire@$(WIRE_VERSION)
|
||||
|
||||
## install.gotests: Install gotests, used to generate test functions
|
||||
.PHONY: install.gotests
|
||||
install.gotests:
|
||||
@$(GO) install github.com/cweill/gotests/gotests@latest
|
||||
|
||||
## install.protoc-gen-go: Install protoc-gen-go, used to generate go source files from protobuf files
|
||||
.PHONY: install.protoc-gen-go
|
||||
install.protoc-gen-go:
|
||||
@$(GO) install github.com/golang/protobuf/protoc-gen-go@latest
|
||||
@$(GO) install github.com/golang/protobuf/protoc-gen-go@$(PROTOC_GEN_GO_VERSION)
|
||||
|
||||
## install.cfssl: Install cfssl, used to generate certificates
|
||||
.PHONY: install.cfssl
|
||||
@ -210,43 +230,49 @@ install.cfssl:
|
||||
## install.depth: Install depth, used to check dependency tree
|
||||
.PHONY: install.depth
|
||||
install.depth:
|
||||
@$(GO) install github.com/KyleBanks/depth/cmd/depth@latest
|
||||
@$(GO) install github.com/KyleBanks/depth/cmd/depth@$(DEPTH_VERSION)
|
||||
|
||||
## install.go-callvis: Install go-callvis, used to visualize call graph
|
||||
.PHONY: install.go-callvis
|
||||
install.go-callvis:
|
||||
@$(GO) install github.com/ofabry/go-callvis@latest
|
||||
@$(GO) install github.com/ofabry/go-callvis@$(GO_CALLVIS_VERSION)
|
||||
|
||||
## install.misspell
|
||||
## install.misspell: Install misspell
|
||||
.PHONY: install.misspell
|
||||
install.misspell:
|
||||
@$(GO) install github.com/client9/misspell/cmd/misspell@latest
|
||||
@$(GO) install github.com/client9/misspell/cmd/misspell@$(MISSPELL_VERSION)
|
||||
|
||||
## install.gothanks: Install gothanks, used to thank go dependencies
|
||||
.PHONY: install.gothanks
|
||||
install.gothanks:
|
||||
@$(GO) install github.com/psampaz/gothanks@latest
|
||||
@$(GO) install github.com/psampaz/gothanks@$(GOTHANKS_VERSION)
|
||||
|
||||
## install.richgo: Install richgo
|
||||
.PHONY: install.richgo
|
||||
install.richgo:
|
||||
@$(GO) install github.com/kyoh86/richgo@latest
|
||||
@$(GO) install github.com/kyoh86/richgo@$(RICHGO_VERSION)
|
||||
|
||||
## install.rts: Install rts
|
||||
.PHONY: install.rts
|
||||
install.rts:
|
||||
@$(GO) install github.com/galeone/rts/cmd/rts@latest
|
||||
@$(GO) install github.com/galeone/rts/cmd/rts@$(RTS_VERSION)
|
||||
|
||||
# ================= kubecub openim tools =========================================
|
||||
## install.typecheck: install kubecub typecheck check for go code
|
||||
# https://github.com/kubecub
|
||||
## install.typecheck: Install kubecub typecheck, checks for go code
|
||||
.PHONY: install.typecheck
|
||||
install.typecheck:
|
||||
@$(GO) install github.com/kubecub/typecheck@latest
|
||||
@$(GO) install github.com/kubecub/typecheck@$(TYPECHECK_VERSION)
|
||||
|
||||
## install.comment-lang-detector: install kubecub comment-lang-detector check for go code comment language
|
||||
## install.comment-lang-detector: Install kubecub comment-lang-detector, checks for go code comment language
|
||||
.PHONY: install.comment-lang-detector
|
||||
install.comment-lang-detector:
|
||||
@$(GO) install github.com/kubecub/comment-lang-detector/cmd/cld@latest
|
||||
@$(GO) install github.com/kubecub/comment-lang-detector/cmd/cld@$(COMMENT_LANG_DETECTOR_VERSION)
|
||||
|
||||
## install.standardizer: Install kubecub standardizer, checks for go code standardization
|
||||
.PHONY: install.standardizer
|
||||
install.standardizer:
|
||||
@$(GO) install github.com/kubecub/standardizer@$(STANDARDIZER_VERSION)
|
||||
|
||||
## tools.help: Display help information about the tools package
|
||||
.PHONY: tools.help
|
||||
|
||||
@ -94,7 +94,6 @@ if [[ $? -ne 0 ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
result=$(openim::util::check_process_names ${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]})
|
||||
if [[ $? -ne 0 ]]; then
|
||||
openim::log::error "The OpenIM services may fail to start.\n $result"
|
||||
|
||||
33
scripts/verify-standardizer.sh
Executable file
33
scripts/verify-standardizer.sh
Executable file
@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright © 2023 OpenIM. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# This script does a fast type check of script srnetes code for all platforms.
|
||||
# Usage: `scripts/verify-standardizer.sh`.
|
||||
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
||||
|
||||
openim::golang::verify_go_version
|
||||
|
||||
cd "${OPENIM_ROOT}"
|
||||
ret=0
|
||||
scripts/run-in-gopath.sh \
|
||||
make tools.verify.standardizer
|
||||
${OPENIM_ROOT}/_output/tools/standardizer || ret=$?
|
||||
if [[ $ret -ne 0 ]]; then
|
||||
openim::log::error "Failed to check the directory name or file name. Your name may not meet the specification. Please check the configuration file and the directory or file name." >&2
|
||||
openim::log::error "Please see https://github.com/kubecub/standardizer for more information." >&2
|
||||
exit 1
|
||||
fi
|
||||
@ -115,7 +115,7 @@ func main() {
|
||||
|
||||
allSuccess := true
|
||||
for _, check := range serviceChecks {
|
||||
if err := check(ctx, conf); err != nil {
|
||||
if err := check(ctx, &config.Config); err != nil {
|
||||
util.ColorErrPrint(fmt.Sprintf("Check failed: %v", err))
|
||||
allSuccess = false
|
||||
break
|
||||
|
||||
@ -1,107 +0,0 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||
"github.com/openimsdk/tools/errs"
|
||||
)
|
||||
|
||||
func ConfigGetEnv(config *config.GlobalConfig) error {
|
||||
config.Mongo.Uri = getEnv("MONGO_URI", config.Mongo.Uri)
|
||||
config.Mongo.Username = getEnv("MONGO_OPENIM_USERNAME", config.Mongo.Username)
|
||||
config.Mongo.Password = getEnv("MONGO_OPENIM_PASSWORD", config.Mongo.Password)
|
||||
config.Mongo.Address = getArrEnv("MONGO_ADDRESS", "MONGO_PORT", config.Mongo.Address)
|
||||
config.Mongo.Database = getEnv("MONGO_DATABASE", config.Mongo.Database)
|
||||
maxPoolSize, err := getEnvInt("MONGO_MAX_POOL_SIZE", config.Mongo.MaxPoolSize)
|
||||
if err != nil {
|
||||
return errs.WrapMsg(err, "MONGO_MAX_POOL_SIZE")
|
||||
}
|
||||
config.Mongo.MaxPoolSize = maxPoolSize
|
||||
|
||||
config.Redis.Username = getEnv("REDIS_USERNAME", config.Redis.Username)
|
||||
config.Redis.Password = getEnv("REDIS_PASSWORD", config.Redis.Password)
|
||||
config.Redis.Address = getArrEnv("REDIS_ADDRESS", "REDIS_PORT", config.Redis.Address)
|
||||
|
||||
config.Object.ApiURL = getEnv("OBJECT_APIURL", config.Object.ApiURL)
|
||||
config.Object.Minio.Endpoint = getEnv("MINIO_ENDPOINT", config.Object.Minio.Endpoint)
|
||||
config.Object.Minio.AccessKeyID = getEnv("MINIO_ACCESS_KEY_ID", config.Object.Minio.AccessKeyID)
|
||||
config.Object.Minio.SecretAccessKey = getEnv("MINIO_SECRET_ACCESS_KEY", config.Object.Minio.SecretAccessKey)
|
||||
config.Object.Minio.SignEndpoint = getEnv("MINIO_SIGN_ENDPOINT", config.Object.Minio.SignEndpoint)
|
||||
|
||||
config.Zookeeper.Schema = getEnv("ZOOKEEPER_SCHEMA", config.Zookeeper.Schema)
|
||||
config.Zookeeper.ZkAddr = getArrEnv("ZOOKEEPER_ADDRESS", "ZOOKEEPER_PORT", config.Zookeeper.ZkAddr)
|
||||
config.Zookeeper.Username = getEnv("ZOOKEEPER_USERNAME", config.Zookeeper.Username)
|
||||
config.Zookeeper.Password = getEnv("ZOOKEEPER_PASSWORD", config.Zookeeper.Password)
|
||||
|
||||
config.Kafka.Username = getEnv("KAFKA_USERNAME", config.Kafka.Username)
|
||||
config.Kafka.Password = getEnv("KAFKA_PASSWORD", config.Kafka.Password)
|
||||
config.Kafka.Addr = getArrEnv("KAFKA_ADDRESS", "KAFKA_PORT", config.Kafka.Addr)
|
||||
config.Object.Minio.Endpoint = getMinioAddr("MINIO_ENDPOINT", "MINIO_ADDRESS", "MINIO_PORT", config.Object.Minio.Endpoint)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Helper function to get environment variable or default value
|
||||
func getEnv(key, fallback string) string {
|
||||
if value, exists := os.LookupEnv(key); exists {
|
||||
return value
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
// Helper function to get environment variable or default value
|
||||
func getEnvInt(key string, fallback int) (int, error) {
|
||||
if value, exists := os.LookupEnv(key); exists {
|
||||
val, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
return 0, errs.WrapMsg(err, "string to int failed")
|
||||
}
|
||||
return val, nil
|
||||
}
|
||||
return fallback, nil
|
||||
}
|
||||
|
||||
func getArrEnv(key1, key2 string, fallback []string) []string {
|
||||
address, addrExists := os.LookupEnv(key1)
|
||||
port, portExists := os.LookupEnv(key2)
|
||||
|
||||
if addrExists && portExists {
|
||||
addresses := strings.Split(address, ",")
|
||||
for i, addr := range addresses {
|
||||
addresses[i] = addr + ":" + port
|
||||
}
|
||||
return addresses
|
||||
}
|
||||
|
||||
if addrExists && !portExists {
|
||||
addresses := strings.Split(address, ",")
|
||||
for i, addr := range addresses {
|
||||
addresses[i] = addr + ":" + "0"
|
||||
}
|
||||
return addresses
|
||||
}
|
||||
|
||||
if !addrExists && portExists {
|
||||
result := make([]string, len(fallback))
|
||||
for i, addr := range fallback {
|
||||
add := strings.Split(addr, ":")
|
||||
result[i] = add[0] + ":" + port
|
||||
}
|
||||
return result
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
func getMinioAddr(key1, key2, key3, fallback string) string {
|
||||
// Prioritize environment variables
|
||||
endpoint := getEnv(key1, fallback)
|
||||
address, addressExist := os.LookupEnv(key2)
|
||||
port, portExist := os.LookupEnv(key3)
|
||||
if portExist && addressExist {
|
||||
endpoint = "http://" + address + ":" + port
|
||||
return endpoint
|
||||
}
|
||||
return endpoint
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user