commit
4b2f34bba4
@ -0,0 +1,13 @@
|
|||||||
|
enable: "etcd"
|
||||||
|
etcd:
|
||||||
|
rootDirectory: openim
|
||||||
|
address: [ localhost:12379 ]
|
||||||
|
username: ''
|
||||||
|
password: ''
|
||||||
|
|
||||||
|
zookeeper:
|
||||||
|
schema: openim
|
||||||
|
address: [ localhost:12181 ]
|
||||||
|
username: ''
|
||||||
|
password: ''
|
||||||
|
|
@ -1,47 +0,0 @@
|
|||||||
# 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.
|
|
||||||
|
|
||||||
###################### AlertManager Configuration ######################
|
|
||||||
# AlertManager configuration using environment variables
|
|
||||||
#
|
|
||||||
# Resolve timeout
|
|
||||||
# SMTP configuration for sending alerts
|
|
||||||
# Templates for email notifications
|
|
||||||
# Routing configurations for alerts
|
|
||||||
# Receiver configurations
|
|
||||||
global:
|
|
||||||
resolve_timeout: 5m
|
|
||||||
smtp_from: alert@openim.io
|
|
||||||
smtp_smarthost: smtp.163.com:465
|
|
||||||
smtp_auth_username: alert@openim.io
|
|
||||||
smtp_auth_password: YOURAUTHPASSWORD
|
|
||||||
smtp_require_tls: false
|
|
||||||
smtp_hello: xxx监控告警
|
|
||||||
|
|
||||||
templates:
|
|
||||||
- /etc/alertmanager/email.tmpl
|
|
||||||
|
|
||||||
route:
|
|
||||||
group_by: ['alertname']
|
|
||||||
group_wait: 5s
|
|
||||||
group_interval: 5s
|
|
||||||
repeat_interval: 5m
|
|
||||||
receiver: email
|
|
||||||
receivers:
|
|
||||||
- name: email
|
|
||||||
email_configs:
|
|
||||||
- to: 'alert@example.com'
|
|
||||||
html: '{{ template "email.to.html" . }}'
|
|
||||||
headers: { Subject: "[OPENIM-SERVER]Alarm" }
|
|
||||||
send_resolved: true
|
|
@ -1,552 +0,0 @@
|
|||||||
envs:
|
|
||||||
discovery: zookeeper
|
|
||||||
|
|
||||||
###################### Zookeeper ######################
|
|
||||||
# Zookeeper configuration
|
|
||||||
# It's not recommended to modify the schema
|
|
||||||
#
|
|
||||||
# Zookeeper address
|
|
||||||
# Zookeeper username
|
|
||||||
# Zookeeper password
|
|
||||||
zookeeper:
|
|
||||||
schema: openim
|
|
||||||
address: [ 172.28.0.1:12181 ]
|
|
||||||
username: ''
|
|
||||||
password: ''
|
|
||||||
|
|
||||||
###################### Mongo ######################
|
|
||||||
# MongoDB configuration
|
|
||||||
|
|
||||||
# If uri is not empty, it will be used directly for the MongoDB connection.
|
|
||||||
# This is a complete MongoDB URI string.
|
|
||||||
# Example: mongodb://user:password@host1:port1,host2:port2/dbname?options
|
|
||||||
mongo:
|
|
||||||
uri: ''
|
|
||||||
|
|
||||||
# List of MongoDB server addresses.
|
|
||||||
# Used for constructing the MongoDB URI if 'uri' above is empty.
|
|
||||||
# For a standalone setup, specify the address of the single server.
|
|
||||||
# For a sharded cluster, specify the addresses of the Mongos servers.
|
|
||||||
# Example: [ '172.28.0.1:37017', '172.28.0.2:37017' ]
|
|
||||||
# Default MongoDB database name
|
|
||||||
# Maximum connection pool size
|
|
||||||
address: [ 172.28.0.1:37017 ]
|
|
||||||
database: openim_v3
|
|
||||||
username: openIM
|
|
||||||
password: openIM123
|
|
||||||
maxPoolSize: 100
|
|
||||||
|
|
||||||
###################### Redis configuration information ######################
|
|
||||||
# Redis configuration
|
|
||||||
#
|
|
||||||
# Username is required only for Redis version 6.0+
|
|
||||||
redis:
|
|
||||||
address: [ 172.28.0.1:16379 ]
|
|
||||||
username: ''
|
|
||||||
password: openIM123
|
|
||||||
|
|
||||||
###################### Kafka configuration information ######################
|
|
||||||
# Kafka configuration
|
|
||||||
#
|
|
||||||
# Kafka username
|
|
||||||
# Kafka password
|
|
||||||
# It's not recommended to modify this topic name
|
|
||||||
# Consumer group ID, it's not recommended to modify
|
|
||||||
kafka:
|
|
||||||
username: ''
|
|
||||||
password: ''
|
|
||||||
addr: [ 172.28.0.1:19094 ]
|
|
||||||
latestMsgToRedis:
|
|
||||||
topic: "latestMsgToRedis"
|
|
||||||
offlineMsgToMongo:
|
|
||||||
topic: "offlineMsgToMongoMysql"
|
|
||||||
msgToPush:
|
|
||||||
topic: "msgToPush"
|
|
||||||
consumerGroupID:
|
|
||||||
msgToRedis: redis
|
|
||||||
msgToMongo: mongo
|
|
||||||
msgToMySql: mysql
|
|
||||||
msgToPush: push
|
|
||||||
|
|
||||||
###################### RPC configuration information ######################
|
|
||||||
# RPC configuration
|
|
||||||
#
|
|
||||||
# IP address to register with zookeeper when starting RPC, the IP and corresponding rpcPort should be accessible by api/gateway
|
|
||||||
# Default listen IP is 0.0.0.0
|
|
||||||
rpc:
|
|
||||||
registerIP: ''
|
|
||||||
listenIP: 0.0.0.0
|
|
||||||
|
|
||||||
###################### API configuration information ######################
|
|
||||||
# API configuration
|
|
||||||
#
|
|
||||||
# API service port
|
|
||||||
# Default listen IP is 0.0.0.0
|
|
||||||
api:
|
|
||||||
openImApiPort: [ 10002 ]
|
|
||||||
listenIP: 0.0.0.0
|
|
||||||
|
|
||||||
###################### Object configuration information ######################
|
|
||||||
# Object storage configuration
|
|
||||||
#
|
|
||||||
# Use minio for object storage
|
|
||||||
# API URL should be accessible by the app
|
|
||||||
# It's not recommended to modify the bucket name
|
|
||||||
# Endpoint should be accessible by the app
|
|
||||||
# Session token
|
|
||||||
# Configuration for Tencent COS
|
|
||||||
# Configuration for Aliyun OSS
|
|
||||||
# apiURL is the address of the api, the access address of the app, use s3 must be configured
|
|
||||||
# minio.endpoint can be configured as an intranet address,
|
|
||||||
# minio.signEndpoint is minio public network address
|
|
||||||
object:
|
|
||||||
enable: "minio"
|
|
||||||
apiURL: "http://127.0.0.1:10002"
|
|
||||||
minio:
|
|
||||||
bucket: "openim"
|
|
||||||
endpoint: "http://172.28.0.1:10005"
|
|
||||||
accessKeyID: "root"
|
|
||||||
secretAccessKey: "openIM123"
|
|
||||||
sessionToken: ''
|
|
||||||
signEndpoint: "http://127.0.0.1:10005"
|
|
||||||
publicRead: false
|
|
||||||
cos:
|
|
||||||
bucketURL: https://temp-1252357374.cos.ap-chengdu.myqcloud.com
|
|
||||||
secretID: ''
|
|
||||||
secretKey: ''
|
|
||||||
sessionToken: ''
|
|
||||||
publicRead: false
|
|
||||||
oss:
|
|
||||||
endpoint: "https://oss-cn-chengdu.aliyuncs.com"
|
|
||||||
bucket: "demo-9999999"
|
|
||||||
bucketURL: "https://demo-9999999.oss-cn-chengdu.aliyuncs.com"
|
|
||||||
accessKeyID: ''
|
|
||||||
accessKeySecret: ''
|
|
||||||
sessionToken: ''
|
|
||||||
publicRead: false
|
|
||||||
kodo:
|
|
||||||
endpoint: "http://s3.cn-east-1.qiniucs.com"
|
|
||||||
bucket: "demo-9999999"
|
|
||||||
bucketURL: "http://your.domain.com"
|
|
||||||
accessKeyID: ''
|
|
||||||
accessKeySecret: ''
|
|
||||||
sessionToken: ''
|
|
||||||
publicRead: false
|
|
||||||
aws:
|
|
||||||
endpoint: "''" # This might not be necessary unless you're using a custom endpoint
|
|
||||||
region: "us-east-1"
|
|
||||||
bucket: "demo-9999999"
|
|
||||||
accessKeyID: ''
|
|
||||||
accessKeySecret: ''
|
|
||||||
publicRead: false
|
|
||||||
|
|
||||||
###################### RPC Port Configuration ######################
|
|
||||||
# RPC service ports
|
|
||||||
# These ports are passed into the program by the script and are not recommended to modify
|
|
||||||
# For launching multiple programs, just fill in multiple ports separated by commas
|
|
||||||
# For example, [10110, 10111]
|
|
||||||
rpcPort:
|
|
||||||
openImUserPort: [ 10110 ]
|
|
||||||
openImFriendPort: [ 10120 ]
|
|
||||||
openImMessagePort: [ 10130 ]
|
|
||||||
openImGroupPort: [ 10150 ]
|
|
||||||
openImAuthPort: [ 10160 ]
|
|
||||||
openImPushPort: [ 10170 ]
|
|
||||||
openImConversationPort: [ 10180 ]
|
|
||||||
openImThirdPort: [ 10190 ]
|
|
||||||
|
|
||||||
###################### RPC Register Name Configuration ######################
|
|
||||||
# RPC service names for registration, it's not recommended to modify these
|
|
||||||
rpcRegisterName:
|
|
||||||
openImUserName: User
|
|
||||||
openImFriendName: Friend
|
|
||||||
openImMsgName: Msg
|
|
||||||
openImPushName: Push
|
|
||||||
openImMessageGatewayName: MessageGateway
|
|
||||||
openImGroupName: Group
|
|
||||||
openImAuthName: Auth
|
|
||||||
openImConversationName: Conversation
|
|
||||||
openImThirdName: Third
|
|
||||||
|
|
||||||
###################### Log Configuration ######################
|
|
||||||
# Log configuration
|
|
||||||
#
|
|
||||||
# Storage directory
|
|
||||||
# Log rotation time
|
|
||||||
# Maximum number of logs to retain
|
|
||||||
# Log level, 6 means all levels
|
|
||||||
# Whether to output to stdout
|
|
||||||
# Whether to output in json format
|
|
||||||
# Whether to include stack trace in logs
|
|
||||||
log:
|
|
||||||
storageLocation: /data/workspaces/open-im-server/_output/logs/
|
|
||||||
rotationTime: 24
|
|
||||||
remainRotationCount: 2
|
|
||||||
remainLogLevel: 6
|
|
||||||
isStdout: false
|
|
||||||
isJson: false
|
|
||||||
withStack: false
|
|
||||||
|
|
||||||
###################### Variables definition ######################
|
|
||||||
# Long connection server configuration
|
|
||||||
#
|
|
||||||
# Websocket port for msg_gateway
|
|
||||||
# Maximum number of websocket connections
|
|
||||||
# Maximum length of websocket request package
|
|
||||||
# Websocket connection handshake timeout
|
|
||||||
longConnSvr:
|
|
||||||
openImWsPort: [ 10001 ]
|
|
||||||
websocketMaxConnNum: 100000
|
|
||||||
openImMessageGatewayPort: [ 10140 ]
|
|
||||||
websocketMaxMsgLen: 4096
|
|
||||||
websocketTimeout: 10
|
|
||||||
|
|
||||||
# Push notification service configuration
|
|
||||||
#
|
|
||||||
# Use GeTui for push notifications
|
|
||||||
# GeTui offline push configuration
|
|
||||||
# FCM offline push configuration
|
|
||||||
# Account file, place it in the config directory
|
|
||||||
# JPush configuration, modify these after applying in JPush backend
|
|
||||||
push:
|
|
||||||
enable: getui
|
|
||||||
geTui:
|
|
||||||
pushUrl: "https://restapi.getui.com/v2/$appId"
|
|
||||||
masterSecret: ''
|
|
||||||
appKey: ''
|
|
||||||
intent: ''
|
|
||||||
channelID: ''
|
|
||||||
channelName: ''
|
|
||||||
fcm:
|
|
||||||
serviceAccount: "x.json"
|
|
||||||
jpns:
|
|
||||||
appKey: ''
|
|
||||||
masterSecret: ''
|
|
||||||
pushUrl: ''
|
|
||||||
pushIntent: ''
|
|
||||||
|
|
||||||
# App manager configuration
|
|
||||||
#
|
|
||||||
# Built-in app manager user IDs
|
|
||||||
# Built-in app manager nicknames
|
|
||||||
# Attention, this configure is discarded. If you have used him before, configure your own
|
|
||||||
manager:
|
|
||||||
userID:
|
|
||||||
nickname:
|
|
||||||
|
|
||||||
# chatAdmin, use for send notification
|
|
||||||
#
|
|
||||||
# Built-in app system notification account ID
|
|
||||||
# Built-in app system notification account nickname
|
|
||||||
im-admin:
|
|
||||||
userID: [ "imAdmin" ]
|
|
||||||
nickname: [ "imAdmin" ]
|
|
||||||
|
|
||||||
# Multi-platform login policy
|
|
||||||
# For each platform(Android, iOS, Windows, Mac, web), only one can be online at a time
|
|
||||||
multiLoginPolicy: 1
|
|
||||||
|
|
||||||
# Whether to store messages in MySQL, messages in MySQL are only used for management background
|
|
||||||
chatPersistenceMysql: true
|
|
||||||
|
|
||||||
# Message cache timeout in seconds, it's not recommended to modify
|
|
||||||
msgCacheTimeout: 86400
|
|
||||||
|
|
||||||
# Whether to enable read receipts for group chat
|
|
||||||
groupMessageHasReadReceiptEnable: true
|
|
||||||
|
|
||||||
# Whether to enable read receipts for single chat
|
|
||||||
singleMessageHasReadReceiptEnable: true
|
|
||||||
|
|
||||||
# MongoDB offline message retention period in days
|
|
||||||
retainChatRecords: 365
|
|
||||||
|
|
||||||
# Schedule to clear expired messages(older than retainChatRecords days) in MongoDB every Wednesday at 2am
|
|
||||||
# This deletion is just for cleaning up disk usage according to previous configuration retainChatRecords, no notification will be sent
|
|
||||||
chatRecordsClearTime: "0 2 * * 3"
|
|
||||||
|
|
||||||
# Schedule to auto delete messages every day at 2am
|
|
||||||
# This deletion is for messages that have been retained for more than msg_destruct_time (seconds) in the conversation field
|
|
||||||
msgDestructTime: "0 2 * * *"
|
|
||||||
|
|
||||||
# Secret key
|
|
||||||
secret: openIM123
|
|
||||||
|
|
||||||
# Token policy
|
|
||||||
#
|
|
||||||
# Token expiration period in days
|
|
||||||
tokenPolicy:
|
|
||||||
expire: 90
|
|
||||||
|
|
||||||
# Message verification policy
|
|
||||||
#
|
|
||||||
# Whether to verify friendship when sending messages
|
|
||||||
messageVerify:
|
|
||||||
friendVerify: false
|
|
||||||
|
|
||||||
# iOS push notification configuration
|
|
||||||
#
|
|
||||||
# iOS push notification sound
|
|
||||||
# Whether to count badge
|
|
||||||
# Whether it's production environment
|
|
||||||
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
|
|
||||||
|
|
||||||
###################### LocalCache configuration information ######################
|
|
||||||
# topic: redis subscriber channel
|
|
||||||
# slotNum: number of slots, multiple slots can prevent too many keys from competing for a lock
|
|
||||||
# slotSize: number of slots, the number of cached keys per slot, the overall cache quantity is slotNum * slotSize
|
|
||||||
# successExpire: successful cache time seconds
|
|
||||||
# failedExpire: failed cache time seconds
|
|
||||||
# disable local caching and annotate topic, slotNum, and slotSize
|
|
||||||
localCache:
|
|
||||||
user:
|
|
||||||
topic: DELETE_CACHE_USER
|
|
||||||
slotNum: 100
|
|
||||||
slotSize: 2000
|
|
||||||
successExpire: 300
|
|
||||||
failedExpire: 5
|
|
||||||
|
|
||||||
group:
|
|
||||||
topic: DELETE_CACHE_GROUP
|
|
||||||
slotNum: 100
|
|
||||||
slotSize: 2000
|
|
||||||
successExpire: 300
|
|
||||||
failedExpire: 5
|
|
||||||
|
|
||||||
friend:
|
|
||||||
topic: DELETE_CACHE_FRIEND
|
|
||||||
slotNum: 100
|
|
||||||
slotSize: 2000
|
|
||||||
successExpire: 300
|
|
||||||
failedExpire: 5
|
|
||||||
|
|
||||||
conversation:
|
|
||||||
topic: DELETE_CACHE_CONVERSATION
|
|
||||||
slotNum: 100
|
|
||||||
slotSize: 2000
|
|
||||||
successExpire: 300
|
|
||||||
failedExpire: 5
|
|
@ -1,16 +0,0 @@
|
|||||||
{{ define "email.to.html" }}
|
|
||||||
{{ range .Alerts }}
|
|
||||||
<!-- Begin of OpenIM Alert -->
|
|
||||||
<div style="border:1px solid #ccc; padding:10px; margin-bottom:10px;">
|
|
||||||
<h3>OpenIM Alert</h3>
|
|
||||||
<p><strong>Alert Program:</strong> Prometheus Alert</p>
|
|
||||||
<p><strong>Severity Level:</strong> {{ .Labels.severity }}</p>
|
|
||||||
<p><strong>Alert Type:</strong> {{ .Labels.alertname }}</p>
|
|
||||||
<p><strong>Affected Host:</strong> {{ .Labels.instance }}</p>
|
|
||||||
<p><strong>Affected Service:</strong> {{ .Labels.job }}</p>
|
|
||||||
<p><strong>Alert Subject:</strong> {{ .Annotations.summary }}</p>
|
|
||||||
<p><strong>Trigger Time:</strong> {{ .StartsAt.Format "2006-01-02 15:04:05" }}</p>
|
|
||||||
</div>
|
|
||||||
<!-- End of OpenIM Alert -->
|
|
||||||
{{ end }}
|
|
||||||
{{ end }}
|
|
@ -1,36 +0,0 @@
|
|||||||
# 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.
|
|
||||||
|
|
||||||
groups:
|
|
||||||
- name: instance_down
|
|
||||||
rules:
|
|
||||||
- alert: InstanceDown
|
|
||||||
expr: up == 0
|
|
||||||
for: 1m
|
|
||||||
labels:
|
|
||||||
severity: critical
|
|
||||||
annotations:
|
|
||||||
summary: "Instance {{ $labels.instance }} down"
|
|
||||||
description: "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 1 minutes."
|
|
||||||
|
|
||||||
- name: database_insert_failure_alerts
|
|
||||||
rules:
|
|
||||||
- alert: DatabaseInsertFailed
|
|
||||||
expr: (increase(msg_insert_redis_failed_total[5m]) > 0) or (increase(msg_insert_mongo_failed_total[5m]) > 0)
|
|
||||||
for: 1m
|
|
||||||
labels:
|
|
||||||
severity: critical
|
|
||||||
annotations:
|
|
||||||
summary: "Increase in MsgInsertRedisFailedCounter or MsgInsertMongoFailedCounter detected"
|
|
||||||
description: "Either MsgInsertRedisFailedCounter or MsgInsertMongoFailedCounter has increased in the last 5 minutes, indicating failures in message insert operations to Redis or MongoDB,maybe the redis or mongodb is crash."
|
|
@ -1,354 +0,0 @@
|
|||||||
# 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.
|
|
||||||
|
|
||||||
# Determines if a message should be sent. If set to false, it triggers a silent sync without a message. If true, it requires triggering a conversation.
|
|
||||||
# For rpc notification, send twice: once as a message and once as a notification.
|
|
||||||
# The options field 'isNotification' indicates if it's a notification.
|
|
||||||
groupCreated:
|
|
||||||
isSendMsg: true
|
|
||||||
|
|
||||||
# Reliability level of the message sending.
|
|
||||||
# Set to 1 to send only when online, 2 for guaranteed delivery.
|
|
||||||
reliabilityLevel: 1
|
|
||||||
|
|
||||||
# This setting is effective only when 'isSendMsg' is true.
|
|
||||||
# It controls whether to count unread messages.
|
|
||||||
unreadCount: false
|
|
||||||
|
|
||||||
# Configuration for offline push notifications.
|
|
||||||
offlinePush:
|
|
||||||
# Enables or disables offline push notifications.
|
|
||||||
enable: false
|
|
||||||
|
|
||||||
# Title for the notification when a group is created.
|
|
||||||
title: "create group title"
|
|
||||||
|
|
||||||
# Description for the notification.
|
|
||||||
desc: "create group desc"
|
|
||||||
|
|
||||||
# Additional information for the notification.
|
|
||||||
ext: "create group ext"
|
|
||||||
|
|
||||||
# Content type is not added here.
|
|
||||||
# Content should use a JSON structure conforming to the protobuf format.
|
|
||||||
|
|
||||||
groupInfoSet:
|
|
||||||
isSendMsg: false
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: false
|
|
||||||
title: "groupInfoSet title"
|
|
||||||
desc: "groupInfoSet desc"
|
|
||||||
ext: "groupInfoSet ext"
|
|
||||||
|
|
||||||
|
|
||||||
joinGroupApplication:
|
|
||||||
isSendMsg: false
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: false
|
|
||||||
title: "joinGroupApplication title"
|
|
||||||
desc: "joinGroupApplication desc"
|
|
||||||
ext: "joinGroupApplication ext"
|
|
||||||
|
|
||||||
memberQuit:
|
|
||||||
isSendMsg: true
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: false
|
|
||||||
title: "memberQuit title"
|
|
||||||
desc: "memberQuit desc"
|
|
||||||
ext: "memberQuit ext"
|
|
||||||
|
|
||||||
groupApplicationAccepted:
|
|
||||||
isSendMsg: false
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: false
|
|
||||||
title: "groupApplicationAccepted title"
|
|
||||||
desc: "groupApplicationAccepted desc"
|
|
||||||
ext: "groupApplicationAccepted ext"
|
|
||||||
|
|
||||||
groupApplicationRejected:
|
|
||||||
isSendMsg: false
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: false
|
|
||||||
title: " title"
|
|
||||||
desc: " desc"
|
|
||||||
ext: " ext"
|
|
||||||
|
|
||||||
|
|
||||||
groupOwnerTransferred:
|
|
||||||
isSendMsg: true
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: false
|
|
||||||
title: "groupOwnerTransferred title"
|
|
||||||
desc: "groupOwnerTransferred desc"
|
|
||||||
ext: "groupOwnerTransferred ext"
|
|
||||||
|
|
||||||
memberKicked:
|
|
||||||
isSendMsg: true
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: false
|
|
||||||
title: "memberKicked title"
|
|
||||||
desc: "memberKicked desc"
|
|
||||||
ext: "memberKicked ext"
|
|
||||||
|
|
||||||
memberInvited:
|
|
||||||
isSendMsg: true
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: false
|
|
||||||
title: "memberInvited title"
|
|
||||||
desc: "memberInvited desc"
|
|
||||||
ext: "memberInvited ext"
|
|
||||||
|
|
||||||
memberEnter:
|
|
||||||
isSendMsg: true
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: false
|
|
||||||
title: "memberEnter title"
|
|
||||||
desc: "memberEnter desc"
|
|
||||||
ext: "memberEnter ext"
|
|
||||||
|
|
||||||
groupDismissed:
|
|
||||||
isSendMsg: true
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: false
|
|
||||||
title: "groupDismissed title"
|
|
||||||
desc: "groupDismissed desc"
|
|
||||||
ext: "groupDismissed ext"
|
|
||||||
|
|
||||||
groupMuted:
|
|
||||||
isSendMsg: true
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: false
|
|
||||||
title: "groupMuted title"
|
|
||||||
desc: "groupMuted desc"
|
|
||||||
ext: "groupMuted ext"
|
|
||||||
|
|
||||||
groupCancelMuted:
|
|
||||||
isSendMsg: true
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: false
|
|
||||||
title: "groupCancelMuted title"
|
|
||||||
desc: "groupCancelMuted desc"
|
|
||||||
ext: "groupCancelMuted ext"
|
|
||||||
defaultTips:
|
|
||||||
tips: "group Cancel Muted"
|
|
||||||
|
|
||||||
|
|
||||||
groupMemberMuted:
|
|
||||||
isSendMsg: true
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: false
|
|
||||||
title: "groupMemberMuted title"
|
|
||||||
desc: "groupMemberMuted desc"
|
|
||||||
ext: "groupMemberMuted ext"
|
|
||||||
|
|
||||||
groupMemberCancelMuted:
|
|
||||||
isSendMsg: true
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: false
|
|
||||||
title: "groupMemberCancelMuted title"
|
|
||||||
desc: "groupMemberCancelMuted desc"
|
|
||||||
ext: "groupMemberCancelMuted ext"
|
|
||||||
|
|
||||||
groupMemberInfoSet:
|
|
||||||
isSendMsg: false
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: false
|
|
||||||
title: "groupMemberInfoSet title"
|
|
||||||
desc: "groupMemberInfoSet desc"
|
|
||||||
ext: "groupMemberInfoSet ext"
|
|
||||||
|
|
||||||
groupInfoSetAnnouncement:
|
|
||||||
isSendMsg: true
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: false
|
|
||||||
title: "groupInfoSetAnnouncement title"
|
|
||||||
desc: "groupInfoSetAnnouncement desc"
|
|
||||||
ext: "groupInfoSetAnnouncement ext"
|
|
||||||
|
|
||||||
|
|
||||||
groupInfoSetName:
|
|
||||||
isSendMsg: true
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: false
|
|
||||||
title: "groupInfoSetName title"
|
|
||||||
desc: "groupInfoSetName desc"
|
|
||||||
ext: "groupInfoSetName ext"
|
|
||||||
|
|
||||||
|
|
||||||
#############################friend#################################
|
|
||||||
friendApplicationAdded:
|
|
||||||
isSendMsg: false
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: false
|
|
||||||
title: "Somebody applies to add you as a friend"
|
|
||||||
desc: "Somebody applies to add you as a friend"
|
|
||||||
ext: "Somebody applies to add you as a friend"
|
|
||||||
|
|
||||||
friendApplicationApproved:
|
|
||||||
isSendMsg: true
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: true
|
|
||||||
title: "Someone applies to add your friend application"
|
|
||||||
desc: "Someone applies to add your friend application"
|
|
||||||
ext: "Someone applies to add your friend application"
|
|
||||||
|
|
||||||
friendApplicationRejected:
|
|
||||||
isSendMsg: false
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: true
|
|
||||||
title: "Someone rejected your friend application"
|
|
||||||
desc: "Someone rejected your friend application"
|
|
||||||
ext: "Someone rejected your friend application"
|
|
||||||
|
|
||||||
friendAdded:
|
|
||||||
isSendMsg: false
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: true
|
|
||||||
title: "We have become friends"
|
|
||||||
desc: "We have become friends"
|
|
||||||
ext: "We have become friends"
|
|
||||||
|
|
||||||
friendDeleted:
|
|
||||||
isSendMsg: false
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: true
|
|
||||||
title: "deleted a friend"
|
|
||||||
desc: "deleted a friend"
|
|
||||||
ext: "deleted a friend"
|
|
||||||
|
|
||||||
friendRemarkSet:
|
|
||||||
isSendMsg: false
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: true
|
|
||||||
title: "Your friend's profile has been changed"
|
|
||||||
desc: "Your friend's profile has been changed"
|
|
||||||
ext: "Your friend's profile has been changed"
|
|
||||||
|
|
||||||
blackAdded:
|
|
||||||
isSendMsg: false
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: true
|
|
||||||
title: "blocked a user"
|
|
||||||
desc: "blocked a user"
|
|
||||||
ext: "blocked a user"
|
|
||||||
|
|
||||||
blackDeleted:
|
|
||||||
isSendMsg: false
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: true
|
|
||||||
title: "Remove a blocked user"
|
|
||||||
desc: "Remove a blocked user"
|
|
||||||
ext: "Remove a blocked user"
|
|
||||||
|
|
||||||
friendInfoUpdated:
|
|
||||||
isSendMsg: false
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: true
|
|
||||||
title: "friend info updated"
|
|
||||||
desc: "friend info updated"
|
|
||||||
ext: "friend info updated"
|
|
||||||
|
|
||||||
#####################user#########################
|
|
||||||
userInfoUpdated:
|
|
||||||
isSendMsg: false
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: true
|
|
||||||
title: "Remove a blocked user"
|
|
||||||
desc: "Remove a blocked user"
|
|
||||||
ext: "Remove a blocked user"
|
|
||||||
|
|
||||||
userStatusChanged:
|
|
||||||
isSendMsg: false
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: false
|
|
||||||
title: "user status changed"
|
|
||||||
desc: "user status changed"
|
|
||||||
ext: "user status changed"
|
|
||||||
|
|
||||||
#####################conversation#########################
|
|
||||||
conversationChanged:
|
|
||||||
isSendMsg: false
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: true
|
|
||||||
title: "conversation changed"
|
|
||||||
desc: "conversation changed"
|
|
||||||
ext: "conversation changed"
|
|
||||||
|
|
||||||
conversationSetPrivate:
|
|
||||||
isSendMsg: true
|
|
||||||
reliabilityLevel: 1
|
|
||||||
unreadCount: false
|
|
||||||
offlinePush:
|
|
||||||
enable: true
|
|
||||||
title: "burn after reading"
|
|
||||||
desc: "burn after reading"
|
|
||||||
ext: "burn after reading"
|
|
@ -1,173 +0,0 @@
|
|||||||
upstream im_msg_gateway{
|
|
||||||
server 127.0.0.1:10001; #IM Message server address Multiple can be specified according to the deployment
|
|
||||||
}
|
|
||||||
upstream im_api{
|
|
||||||
server 127.0.0.1:10002; #IM Group user api server address Multiple can be specified according to the deployment
|
|
||||||
}
|
|
||||||
upstream im_grafana{
|
|
||||||
server 127.0.0.1:10007; #IM Statistical server address The machine where docker-compose starts
|
|
||||||
}
|
|
||||||
upstream im_chat_api{
|
|
||||||
server 127.0.0.1:10008; #IM Business version login registration server address Multiple can be specified according to the deployment
|
|
||||||
}
|
|
||||||
upstream im_admin_api{
|
|
||||||
server 127.0.0.1:10009; #IM The admin address of the commercial version can specify multiple units according to the deployment situation
|
|
||||||
}
|
|
||||||
upstream im_open_rtc{
|
|
||||||
server 127.0.0.1:7880; #rtc Audio and video call server address Multiple devices can be specified according to the deployment
|
|
||||||
}
|
|
||||||
upstream minio_s3_2 {
|
|
||||||
least_conn;
|
|
||||||
server 127.0.0.1:10005;
|
|
||||||
}
|
|
||||||
|
|
||||||
upstream minio_console_2 {
|
|
||||||
least_conn;
|
|
||||||
server 127.0.0.1:9090;
|
|
||||||
}
|
|
||||||
server {
|
|
||||||
listen 443;
|
|
||||||
server_name your-domain.com; #your-domain.com
|
|
||||||
|
|
||||||
ssl on;
|
|
||||||
ssl_certificate /etc/nginx/conf.d/ssl/your-domain.com.crt; #2 Certificate
|
|
||||||
ssl_certificate_key /etc/nginx/conf.d/ssl/your-domain.com.key; #3 Certificate
|
|
||||||
ssl_session_timeout 5m;
|
|
||||||
gzip on;
|
|
||||||
gzip_min_length 1k;
|
|
||||||
gzip_buffers 4 16k;
|
|
||||||
gzip_comp_level 2;
|
|
||||||
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png application/wasm;
|
|
||||||
gzip_vary off;
|
|
||||||
gzip_disable "MSIE [1-6]\.";
|
|
||||||
error_page 405 =200 $uri;
|
|
||||||
|
|
||||||
default_type application/wasm;
|
|
||||||
location /{ #web demo
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
proxy_set_header X-Real-Ip $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $remote_addr;
|
|
||||||
proxy_set_header X-NginX-Proxy true;
|
|
||||||
root /data1/online/Pc-Web-Demo/build/; # web im static resource storage path
|
|
||||||
index index.html;
|
|
||||||
try_files $uri $uri/ /index.html;
|
|
||||||
}
|
|
||||||
location /msg_gateway { #10001 ws
|
|
||||||
proxy_http_version 1.1;
|
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
|
||||||
proxy_set_header Connection "Upgrade";
|
|
||||||
proxy_set_header X-real-ip $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $remote_addr;
|
|
||||||
proxy_pass http://im_msg_gateway/;
|
|
||||||
}
|
|
||||||
location ^~/api/ { #10002 api
|
|
||||||
proxy_http_version 1.1;
|
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
|
||||||
proxy_set_header Connection "Upgrade";
|
|
||||||
proxy_set_header X-real-ip $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $remote_addr;
|
|
||||||
proxy_set_header X-Request-Api $scheme://$host/api;
|
|
||||||
proxy_pass http://im_api/;
|
|
||||||
}
|
|
||||||
location ^~/grafana/ { #10007 prometheus
|
|
||||||
proxy_http_version 1.1;
|
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
|
||||||
proxy_set_header Connection "Upgrade";
|
|
||||||
proxy_set_header X-real-ip $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $remote_addr;
|
|
||||||
proxy_pass http://im_grafana/;
|
|
||||||
}
|
|
||||||
location ^~/chat/ { #10008 im_chat_api
|
|
||||||
proxy_http_version 1.1;
|
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
|
||||||
proxy_set_header Connection "Upgrade";
|
|
||||||
proxy_set_header X-real-ip $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $remote_addr;
|
|
||||||
proxy_pass http://im_chat_api/;
|
|
||||||
}
|
|
||||||
location ^~/complete_admin/ { #10009 admin
|
|
||||||
proxy_http_version 1.1;
|
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
|
||||||
proxy_set_header Connection "Upgrade";
|
|
||||||
proxy_set_header X-real-ip $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $remote_addr;
|
|
||||||
proxy_pass http://im_admin_api/;
|
|
||||||
}
|
|
||||||
location ^~/open_rtc/ { #7880 rtc
|
|
||||||
proxy_http_version 1.1;
|
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
|
||||||
proxy_set_header Connection "Upgrade";
|
|
||||||
proxy_set_header X-real-ip $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $remote_addr;
|
|
||||||
proxy_pass http://im_open_rtc/;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
server {
|
|
||||||
listen 80;
|
|
||||||
server_name test-web.rentsoft.cn ; #1 web im end domain name
|
|
||||||
rewrite ^(.*)$ https://${server_name}$1 permanent;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
server {
|
|
||||||
listen 443;
|
|
||||||
|
|
||||||
server_name your-domain.com; #your-domain.com
|
|
||||||
ssl on;
|
|
||||||
ssl_certificate /etc/nginx/conf.d/ssl/your-domain.com.crt; #Certificate
|
|
||||||
ssl_certificate_key /etc/nginx/conf.d/ssl/your-domain.com.key; #Certificate
|
|
||||||
gzip on;
|
|
||||||
gzip_min_length 1k;
|
|
||||||
gzip_buffers 4 16k;
|
|
||||||
gzip_comp_level 2;
|
|
||||||
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png application/wasm;
|
|
||||||
gzip_vary off;
|
|
||||||
gzip_disable "MSIE [1-6]\.";
|
|
||||||
# Allow special characters in headers
|
|
||||||
ignore_invalid_headers off;
|
|
||||||
# Allow any size file to be uploaded.
|
|
||||||
# Set to a value such as 1000m; to restrict file size to a specific value
|
|
||||||
client_max_body_size 0;
|
|
||||||
# Disable buffering
|
|
||||||
proxy_buffering off;
|
|
||||||
proxy_request_buffering off;
|
|
||||||
|
|
||||||
location / {
|
|
||||||
proxy_set_header Host $http_host;
|
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
|
||||||
|
|
||||||
proxy_connect_timeout 300;
|
|
||||||
# Default is HTTP/1, keepalive is only enabled in HTTP/1.1
|
|
||||||
proxy_http_version 1.1;
|
|
||||||
proxy_set_header Connection "";
|
|
||||||
chunked_transfer_encoding off;
|
|
||||||
|
|
||||||
proxy_pass http://minio_s3_2; # This uses the upstream directive definition to load balance
|
|
||||||
}
|
|
||||||
|
|
||||||
location /minio/ui {
|
|
||||||
rewrite ^/minio/ui/(.*) /$1 break;
|
|
||||||
proxy_set_header Host $http_host;
|
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
|
||||||
proxy_set_header X-NginX-Proxy true;
|
|
||||||
|
|
||||||
# This is necessary to pass the correct IP to be hashed
|
|
||||||
real_ip_header X-Real-IP;
|
|
||||||
|
|
||||||
proxy_connect_timeout 300;
|
|
||||||
|
|
||||||
# To support websockets in MinIO versions released after January 2023
|
|
||||||
proxy_http_version 1.1;
|
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
|
||||||
proxy_set_header Connection "upgrade";
|
|
||||||
|
|
||||||
chunked_transfer_encoding off;
|
|
||||||
|
|
||||||
proxy_pass http://minio_console_2; # This uses the upstream directive definition to load balance
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
@ -1,99 +0,0 @@
|
|||||||
# 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.
|
|
||||||
|
|
||||||
# my global config
|
|
||||||
global:
|
|
||||||
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
|
|
||||||
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
|
|
||||||
# scrape_timeout is set to the global default (10s).
|
|
||||||
|
|
||||||
# Alertmanager configuration
|
|
||||||
alerting:
|
|
||||||
alertmanagers:
|
|
||||||
- static_configs:
|
|
||||||
- targets: ['172.28.0.1:19093']
|
|
||||||
|
|
||||||
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
|
|
||||||
rule_files:
|
|
||||||
- "instance-down-rules.yml"
|
|
||||||
# - "first_rules.yml"
|
|
||||||
# - "second_rules.yml"
|
|
||||||
|
|
||||||
# A scrape configuration containing exactly one endpoint to scrape:
|
|
||||||
# Here it's Prometheus itself.
|
|
||||||
scrape_configs:
|
|
||||||
# The job name is added as a label "job='job_name'"" to any timeseries scraped from this config.
|
|
||||||
# Monitored information captured by prometheus
|
|
||||||
- job_name: 'node-exporter'
|
|
||||||
static_configs:
|
|
||||||
- targets: [ '172.28.0.1:19100' ]
|
|
||||||
labels:
|
|
||||||
namespace: 'default'
|
|
||||||
|
|
||||||
# prometheus fetches application services
|
|
||||||
- job_name: 'openimserver-openim-api'
|
|
||||||
static_configs:
|
|
||||||
- targets: [ '172.28.0.1:20100' ]
|
|
||||||
labels:
|
|
||||||
namespace: 'default'
|
|
||||||
- job_name: 'openimserver-openim-msggateway'
|
|
||||||
static_configs:
|
|
||||||
- targets: [ '172.28.0.1:20140' ]
|
|
||||||
labels:
|
|
||||||
namespace: 'default'
|
|
||||||
- job_name: 'openimserver-openim-msgtransfer'
|
|
||||||
static_configs:
|
|
||||||
- targets: [ 172.28.0.1:21400, 172.28.0.1:21401, 172.28.0.1:21402, 172.28.0.1:21403 ]
|
|
||||||
labels:
|
|
||||||
namespace: 'default'
|
|
||||||
- job_name: 'openimserver-openim-push'
|
|
||||||
static_configs:
|
|
||||||
- targets: [ '172.28.0.1:20170' ]
|
|
||||||
labels:
|
|
||||||
namespace: 'default'
|
|
||||||
- job_name: 'openimserver-openim-rpc-auth'
|
|
||||||
static_configs:
|
|
||||||
- targets: [ '172.28.0.1:20160' ]
|
|
||||||
labels:
|
|
||||||
namespace: 'default'
|
|
||||||
- job_name: 'openimserver-openim-rpc-conversation'
|
|
||||||
static_configs:
|
|
||||||
- targets: [ '172.28.0.1:20230' ]
|
|
||||||
labels:
|
|
||||||
namespace: 'default'
|
|
||||||
- job_name: 'openimserver-openim-rpc-friend'
|
|
||||||
static_configs:
|
|
||||||
- targets: [ '172.28.0.1:20120' ]
|
|
||||||
labels:
|
|
||||||
namespace: 'default'
|
|
||||||
- job_name: 'openimserver-openim-rpc-group'
|
|
||||||
static_configs:
|
|
||||||
- targets: [ '172.28.0.1:20150' ]
|
|
||||||
labels:
|
|
||||||
namespace: 'default'
|
|
||||||
- job_name: 'openimserver-openim-rpc-msg'
|
|
||||||
static_configs:
|
|
||||||
- targets: [ '172.28.0.1:20130' ]
|
|
||||||
labels:
|
|
||||||
namespace: 'default'
|
|
||||||
- job_name: 'openimserver-openim-rpc-third'
|
|
||||||
static_configs:
|
|
||||||
- targets: [ '172.28.0.1:21301' ]
|
|
||||||
labels:
|
|
||||||
namespace: 'default'
|
|
||||||
- job_name: 'openimserver-openim-rpc-user'
|
|
||||||
static_configs:
|
|
||||||
- targets: [ '172.28.0.1:20110' ]
|
|
||||||
labels:
|
|
||||||
namespace: 'default'
|
|
@ -1,6 +0,0 @@
|
|||||||
|
|
||||||
schema: openim
|
|
||||||
address: [ localhost:12181 ]
|
|
||||||
username: ''
|
|
||||||
password: ''
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
|||||||
|
// Copyright © 2024 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.
|
||||||
|
|
||||||
|
package kubernetes // import "github.com/openimsdk/open-im-server/v3/pkg/common/discoveryregister/etcd"
|
@ -1,44 +0,0 @@
|
|||||||
// 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.
|
|
||||||
|
|
||||||
package zookeeper
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
// getEnv returns the value of an environment variable if it exists, otherwise it returns the fallback value.
|
|
||||||
func getEnv(key, fallback string) string {
|
|
||||||
if value, exists := os.LookupEnv(key); exists {
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
return fallback
|
|
||||||
}
|
|
||||||
|
|
||||||
// getZkAddrFromEnv returns the Zookeeper addresses combined from the ZOOKEEPER_ADDRESS and ZOOKEEPER_PORT environment variables.
|
|
||||||
// If the environment variables are not set, it returns the fallback value.
|
|
||||||
func getZkAddrFromEnv(fallback []string) []string {
|
|
||||||
address, addrExists := os.LookupEnv("ZOOKEEPER_ADDRESS")
|
|
||||||
port, portExists := os.LookupEnv("ZOOKEEPER_PORT")
|
|
||||||
|
|
||||||
if addrExists && portExists {
|
|
||||||
addresses := strings.Split(address, ",")
|
|
||||||
for i, addr := range addresses {
|
|
||||||
addresses[i] = addr + ":" + port
|
|
||||||
}
|
|
||||||
return addresses
|
|
||||||
}
|
|
||||||
return fallback
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
CHANGELOG
|
|
||||||
go.mod
|
|
||||||
go.sum
|
|
||||||
third_party/
|
|
||||||
translations/
|
|
||||||
logs
|
|
||||||
.git
|
|
||||||
.golangci.yml
|
|
||||||
docs/readme/README_uk.md
|
|
||||||
docs/readme/README_cs.md
|
|
||||||
docs/readme/README_hu.md
|
|
||||||
docs/readme/README_es.md
|
|
||||||
docs/readme/README_fa.md
|
|
||||||
docs/readme/README_fr.md
|
|
||||||
docs/readme/README_de.md
|
|
||||||
docs/readme/README_pl.md
|
|
||||||
docs/readme/README_id.md
|
|
||||||
docs/readme/README_fi.md
|
|
||||||
docs/readme/README_ml.md
|
|
||||||
docs/readme/README_ja.md
|
|
||||||
docs/readme/README_nl.md
|
|
||||||
docs/readme/README_it.md
|
|
||||||
docs/readme/README_ru.md
|
|
||||||
docs/readme/README_pt_BR
|
|
||||||
docs/readme/README_eo.md
|
|
||||||
docs/readme/README_ko.md
|
|
||||||
docs/readme/README_ar.md
|
|
||||||
docs/readme/README_vi.md
|
|
||||||
docs/readme/README_da.md
|
|
||||||
docs/readme/README_el.md
|
|
||||||
docs/readme/README_tr.md
|
|
@ -1,311 +0,0 @@
|
|||||||
# OpenIM Scripts Directory Structure
|
|
||||||
|
|
||||||
- [OpenIM Scripts Directory Structure](#openim-scripts-directory-structure)
|
|
||||||
- [log directory](#log-directory)
|
|
||||||
- [Supported platforms](#supported-platforms)
|
|
||||||
- [Get started quickly - demo.sh](#get-started-quickly---demosh)
|
|
||||||
- [Guide: Using and Understanding OpenIM Utility Functions](#guide-using-and-understanding-openim-utility-functions)
|
|
||||||
- [Table of Contents](#table-of-contents)
|
|
||||||
- [1. Checking the Status of Services by Ports](#1-checking-the-status-of-services-by-ports)
|
|
||||||
- [Function: `openim::util::check_ports`](#function-openimutilcheck_ports)
|
|
||||||
- [Example:](#example)
|
|
||||||
- [2. Checking the Status of Services by Process Names](#2-checking-the-status-of-services-by-process-names)
|
|
||||||
- [Function: `openim::util::check_process_names`](#function-openimutilcheck_process_names)
|
|
||||||
- [Example:](#example-1)
|
|
||||||
- [3. Stopping Services by Ports](#3-stopping-services-by-ports)
|
|
||||||
- [Function: `openim::util::stop_services_on_ports`](#function-openimutilstop_services_on_ports)
|
|
||||||
- [Example:](#example-2)
|
|
||||||
- [4. Stopping Services by Process Names](#4-stopping-services-by-process-names)
|
|
||||||
- [Function: `openim::util::stop_services_with_name`](#function-openimutilstop_services_with_name)
|
|
||||||
- [Example:](#example-3)
|
|
||||||
- [system management and installation of openim via Linux system](#system-management-and-installation-of-openim-via-linux-system)
|
|
||||||
- [examples](#examples)
|
|
||||||
|
|
||||||
|
|
||||||
This document outlines the directory structure for scripts in the OpenIM Server project. These scripts play a critical role in various areas like building, deploying, running and managing the services of OpenIM.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
scripts/
|
|
||||||
├── README.md # Documentation for the scripts directory.
|
|
||||||
├── advertise.sh # Script to advertise or broadcast services.
|
|
||||||
├── batch_start_all.sh # Batch script to start all services.
|
|
||||||
├── build-all-service.sh # Script to build all services.
|
|
||||||
├── build.cmd # Command script for building (usually for Windows).
|
|
||||||
├── check-all.sh # Check script for all components or services.
|
|
||||||
├── cherry-pick.sh # Helper script for git cherry-pick operations.
|
|
||||||
├── common.sh # Common utilities and shared functions.
|
|
||||||
├── coverage.awk # AWK script for processing code coverage data.
|
|
||||||
├── coverage.sh # Script to gather and report code coverage.
|
|
||||||
├── demo.sh # Demonstration or example script.
|
|
||||||
├── docker-check-service.sh # Docker script to check services' status.
|
|
||||||
├── docker-start-all.sh # Docker script to start all containers/services.
|
|
||||||
├── ensure-tag.sh # Ensure correct tags or labeling.
|
|
||||||
├── env_check.sh # Environment verification and checking.
|
|
||||||
├── gen-swagger-docs.sh # Script to generate Swagger documentation.
|
|
||||||
├── genconfig.sh # Generate configuration files.
|
|
||||||
├── gendoc.sh # General documentation generation script.
|
|
||||||
├── githooks # Directory containing git hooks.
|
|
||||||
│ ├── commit-msg # Git hook for commit messages.
|
|
||||||
│ ├── pre-commit # Pre-commit git hook.
|
|
||||||
│ └── pre-push # Pre-push git hook.
|
|
||||||
├── golangci.yml # Configuration for GolangCI linting.
|
|
||||||
├── init-config.sh # Initialize configurations.
|
|
||||||
├── init-env.sh # Initialize the environment.
|
|
||||||
├── init-pwd.sh # Initialize or set password.
|
|
||||||
├── install # Installation scripts directory.
|
|
||||||
│ ├── README.md # Installation documentation.
|
|
||||||
│ ├── common.sh # Common utilities for installation.
|
|
||||||
│ ├── dependency.sh # Script to install dependencies.
|
|
||||||
│ ├── environment.sh # Set up the environment during installation.
|
|
||||||
│ ├── install-protobuf.sh # Install Protocol Buffers.
|
|
||||||
│ ├── install.sh # Main installation script.
|
|
||||||
│ ├── openim-api.sh # Install OpenIM API.
|
|
||||||
│ ├── openim-crontask.sh # Install OpenIM crontask.
|
|
||||||
│ ├── openim-man.sh # Install OpenIM management tool.
|
|
||||||
│ ├── openim-msggateway.sh # Install OpenIM message gateway.
|
|
||||||
│ ├── openim-msgtransfer.sh # Install OpenIM message transfer.
|
|
||||||
│ ├── openim-push.sh # Install OpenIM push service.
|
|
||||||
│ ├── openim-rpc.sh # Install OpenIM RPC.
|
|
||||||
│ ├── openim-tools.sh # Install OpenIM tools.
|
|
||||||
│ ├── test.sh # Installation testing script.
|
|
||||||
│ └── vimrc # Vim configuration file.
|
|
||||||
├── install-im-server.sh # Script to install the OpenIM server.
|
|
||||||
├── install_im_compose.sh # Install OpenIM using Docker Compose.
|
|
||||||
├── lib # Library or utility scripts directory.
|
|
||||||
│ ├── chat.sh # Utilities related to chat.
|
|
||||||
│ ├── color.sh # Color-related utilities.
|
|
||||||
│ ├── golang.sh # Golang utilities.
|
|
||||||
│ ├── init.sh # Initialization utilities.
|
|
||||||
│ ├── logging.sh # Logging utilities.
|
|
||||||
│ ├── release.sh # Release related utilities.
|
|
||||||
│ ├── util.sh # General utility functions.
|
|
||||||
│ └── version.sh # Version management utilities.
|
|
||||||
├── list-feature-tests.sh # Script to list feature tests.
|
|
||||||
├── make-rules # Makefile rule templates.
|
|
||||||
│ ├── common.mk # Common make rules.
|
|
||||||
│ ├── copyright.mk # Copyright related make rules.
|
|
||||||
│ ├── dependencies.mk # Dependency management rules.
|
|
||||||
│ ├── gen.mk # Generic or general rules.
|
|
||||||
│ ├── golang.mk # Golang-specific make rules.
|
|
||||||
│ ├── image.mk # Image or container-related rules.
|
|
||||||
│ ├── release.mk # Release specific rules.
|
|
||||||
│ ├── swagger.mk # Swagger documentation rules.
|
|
||||||
│ └── tools.mk # Tooling-related make rules.
|
|
||||||
├── mongo-init.sh # MongoDB initialization script.
|
|
||||||
├── release.sh # Script for releasing or deployment.
|
|
||||||
├── run-in-gopath.sh # Script to run commands within GOPATH.
|
|
||||||
├── start-all.sh # Script to start all services.
|
|
||||||
├── start.bat # Batch file to start services (usually for Windows).
|
|
||||||
├── stop-all.sh # Script to stop all services.
|
|
||||||
├── template # Directory containing template files.
|
|
||||||
│ ├── LICENSE # License template.
|
|
||||||
│ ├── LICENSE_TEMPLATES # Collection of license templates.
|
|
||||||
│ ├── boilerplate.txt # Boilerplate template.
|
|
||||||
│ ├── footer.md.tmpl # Footer template for markdown.
|
|
||||||
│ ├── head.md.tmpl # Header template for markdown.
|
|
||||||
│ └── project_README.md # Project README template.
|
|
||||||
├── update-generated-docs.sh # Update generated documentation.
|
|
||||||
├── update-yamlfmt.sh # Update YAML formatting.
|
|
||||||
├── verify-pkg-names.sh # Verify package names.
|
|
||||||
├── verify-shellcheck.sh # Shell script linting verification.
|
|
||||||
├── verify-spelling.sh # Spelling verification script.
|
|
||||||
├── verify-typecheck.sh # Type checking verification.
|
|
||||||
├── verify-yamlfmt.sh # Verify YAML format.
|
|
||||||
└── wait-for-it.sh # Script to wait for a condition or service to be ready.
|
|
||||||
```
|
|
||||||
|
|
||||||
The purpose of having a structured scripts directory like this is to make the operations of OpenIM Server clear and easy to manage. Each script has its own responsibility, making it easier to maintain and update. It's also helpful for newcomers who can easily understand what each part of the system is doing by just looking at this directory structure.
|
|
||||||
|
|
||||||
Each directory and script in the structure should be understood as a part of a larger whole. All scripts work together to ensure the smooth operation and maintenance of the OpenIM Server.
|
|
||||||
|
|
||||||
|
|
||||||
## log directory
|
|
||||||
|
|
||||||
**PATH:** `scripts/lib/logging.sh`
|
|
||||||
|
|
||||||
+ [log details](../docs/contrib/bash-log.md)
|
|
||||||
|
|
||||||
## Supported platforms
|
|
||||||
|
|
||||||
- Linux x86_64 (linux_amd64) : 64-bit Linux for most desktop and server systems.
|
|
||||||
|
|
||||||
- Windows x86_64 (windows_amd64) : 64-bit version for most Windows operating systems.
|
|
||||||
|
|
||||||
- macOS x86_64 (darwin_amd64) : 64-bit version for Apple Macintosh computers.
|
|
||||||
|
|
||||||
- Linux ARM64 (linux_arm64) : For ARM-based 64-bit Linux systems such as Raspberry Pi 4 and Jetson Nano.
|
|
||||||
|
|
||||||
- Linux s390x (linux_s390x) : 64-bit Linux for IBM System z hosts.
|
|
||||||
|
|
||||||
- Linux MIPS64 (linux_mips64) : 64-bit Linux for MIPS architecture.
|
|
||||||
|
|
||||||
- Linux MIPS64LE (linux_mips64le) : Suitable for 64-bit Linux systems with little endian MIPS architecture.
|
|
||||||
|
|
||||||
## Get started quickly - demo.sh
|
|
||||||
|
|
||||||
Is the `demo.sh` script teaching you how to quickly get started with OpenIM development and use
|
|
||||||
|
|
||||||
|
|
||||||
Steps to run demo:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ make demo
|
|
||||||
```
|
|
||||||
|
|
||||||
More about `make` read:
|
|
||||||
|
|
||||||
+ [makefile](../docs/contrib/go-code.md)
|
|
||||||
|
|
||||||
Instructions for producing the demo movie:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Create temporary directory
|
|
||||||
mkdir /tmp/kb-demo
|
|
||||||
cd /tmp/kb-demo
|
|
||||||
|
|
||||||
asciinema rec
|
|
||||||
<path-to-KB-repo>/scripts/demo/run.sh
|
|
||||||
|
|
||||||
<CTRL-C> to terminate the script
|
|
||||||
<CTRL-D> to terminate the asciinema recording
|
|
||||||
<CTRL-C> to save the recording locally
|
|
||||||
|
|
||||||
# Edit the recorded file by editing the controller-gen path
|
|
||||||
# Once you are happy with the recording, use svg-term program to generate the svg
|
|
||||||
|
|
||||||
svg-term --cast=<movie-id> --out _output/demo.svg --window
|
|
||||||
```
|
|
||||||
|
|
||||||
Here you will learn how to test a script, We take the four functions for starting and checking a service as an example.
|
|
||||||
|
|
||||||
## Guide: Using and Understanding OpenIM Utility Functions
|
|
||||||
|
|
||||||
This document provides an overview of the four utility functions designed for managing processes and services. These functions can check the status of services based on ports and process names, as well as stop services based on the same criteria.
|
|
||||||
|
|
||||||
### Table of Contents
|
|
||||||
- [1. Checking the Status of Services by Ports](#checking-the-status-of-services-by-ports)
|
|
||||||
- [2. Checking the Status of Services by Process Names](#checking-the-status-of-services-by-process-names)
|
|
||||||
- [3. Stopping Services by Ports](#stopping-services-by-ports)
|
|
||||||
- [4. Stopping Services by Process Names](#stopping-services-by-process-names)
|
|
||||||
|
|
||||||
### 1. Checking the Status of Services by Ports
|
|
||||||
|
|
||||||
#### Function: `openim::util::check_ports`
|
|
||||||
|
|
||||||
This function checks the status of services running on specified ports.
|
|
||||||
|
|
||||||
**Usage**:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ openim::util::check_ports <port1> <port2> ...
|
|
||||||
```
|
|
||||||
|
|
||||||
**Design**:
|
|
||||||
|
|
||||||
- The function iterates through each provided port.
|
|
||||||
- It uses the `lsof` command to identify if there is a service running on the specified port.
|
|
||||||
- If a service is running, it logs the command, PID, and start time of the service.
|
|
||||||
- If a service is not running, it logs that the port is not started.
|
|
||||||
- If any service is not running, the function returns a status of 1.
|
|
||||||
|
|
||||||
#### Example:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ openim::util::check_ports 8080 8081 8082
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. Checking the Status of Services by Process Names
|
|
||||||
|
|
||||||
#### Function: `openim::util::check_process_names`
|
|
||||||
|
|
||||||
This function checks the status of services based on their process names.
|
|
||||||
|
|
||||||
**Usage**:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ openim::util::check_process_names <process_name1> <process_name2> ...
|
|
||||||
```
|
|
||||||
|
|
||||||
**Design**:
|
|
||||||
|
|
||||||
- The function uses `pgrep` to find process IDs associated with the given process names.
|
|
||||||
- If processes are found, it logs the command, PID, associated port, and start time.
|
|
||||||
- If no processes are found for a name, it logs that the process is not started.
|
|
||||||
- If any process is not running, the function returns a status of 1.
|
|
||||||
|
|
||||||
#### Example:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ openim::util::check_process_names nginx mysql redis
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. Stopping Services by Ports
|
|
||||||
|
|
||||||
#### Function: `openim::util::stop_services_on_ports`
|
|
||||||
|
|
||||||
This function attempts to stop services running on the specified ports.
|
|
||||||
|
|
||||||
**Usage**:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ openim::util::stop_services_on_ports <port1> <port2> ...
|
|
||||||
```
|
|
||||||
|
|
||||||
**Design**:
|
|
||||||
|
|
||||||
- The function uses the `lsof` command to identify services running on the specified ports.
|
|
||||||
- If a service is running on a port, it tries to terminate the associated process using the `kill` command.
|
|
||||||
- It logs successful terminations and any failures.
|
|
||||||
- If any service couldn't be stopped, the function returns a status of 1.
|
|
||||||
|
|
||||||
#### Example:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ openim::util::stop_services_on_ports 8080 8081 8082
|
|
||||||
```
|
|
||||||
|
|
||||||
### 4. Stopping Services by Process Names
|
|
||||||
|
|
||||||
#### Function: `openim::util::stop_services_with_name`
|
|
||||||
|
|
||||||
This function attempts to stop services based on their process names.
|
|
||||||
|
|
||||||
**Usage**:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ openim::util::stop_services_with_name <process_name1> <process_name2> ...
|
|
||||||
```
|
|
||||||
|
|
||||||
**Design**:
|
|
||||||
|
|
||||||
- The function uses `pgrep` to identify processes associated with the specified names.
|
|
||||||
- If processes are found, it tries to terminate them using the `kill` command.
|
|
||||||
- It logs successful terminations and any failures.
|
|
||||||
- If any service couldn't be stopped, the function returns a status of 1.
|
|
||||||
|
|
||||||
#### Example:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ openim::util::stop_services_with_name nginx apache
|
|
||||||
```
|
|
||||||
|
|
||||||
### system management and installation of openim via Linux system
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ ./scripts/install/install.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
## examples
|
|
||||||
Scripts to perform various build, install, analysis, etc operations.
|
|
||||||
|
|
||||||
The script directory design of OpenIM and the writing of scripts and tools refer to many excellent open source projects, such as helm, iam, kubernetes, docker, etc.
|
|
||||||
|
|
||||||
Maybe they'll give you inspiration for later maintenance...
|
|
||||||
|
|
||||||
These scripts keep the root level Makefile small and simple.
|
|
||||||
|
|
||||||
Examples:
|
|
||||||
|
|
||||||
* https://github.com/kubernetes/helm/tree/master/scripts
|
|
||||||
* https://github.com/cockroachdb/cockroach/tree/master/scripts
|
|
||||||
* https://github.com/hashicorp/terraform/tree/master/scripts
|
|
@ -1,112 +0,0 @@
|
|||||||
#!/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.
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
|
|
||||||
. $(dirname ${BASH_SOURCE})/lib/init.sh
|
|
||||||
|
|
||||||
trap 'openim::util::onCtrlC' INT
|
|
||||||
|
|
||||||
print_with_delay() {
|
|
||||||
text="$1"
|
|
||||||
delay="$2"
|
|
||||||
|
|
||||||
for i in $(seq 0 $((${#text}-1))); do
|
|
||||||
printf "${text:$i:1}"
|
|
||||||
sleep $delay
|
|
||||||
done
|
|
||||||
printf "\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
print_progress() {
|
|
||||||
total="$1"
|
|
||||||
delay="$2"
|
|
||||||
|
|
||||||
printf "["
|
|
||||||
for i in $(seq 1 $total); do
|
|
||||||
printf "#"
|
|
||||||
sleep $delay
|
|
||||||
done
|
|
||||||
printf "]\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
function openim_logo() {
|
|
||||||
# Set text color to cyan for header and URL
|
|
||||||
echo -e "\033[0;36m"
|
|
||||||
|
|
||||||
# Display fancy ASCII Art logo
|
|
||||||
# look http://patorjk.com/software/taag/#p=display&h=1&v=1&f=Doh&t=OpenIM
|
|
||||||
print_with_delay '
|
|
||||||
|
|
||||||
|
|
||||||
OOOOOOOOO IIIIIIIIIIMMMMMMMM MMMMMMMM
|
|
||||||
OO:::::::::OO I::::::::IM:::::::M M:::::::M
|
|
||||||
OO:::::::::::::OO I::::::::IM::::::::M M::::::::M
|
|
||||||
O:::::::OOO:::::::O II::::::IIM:::::::::M M:::::::::M
|
|
||||||
O::::::O O::::::Oppppp ppppppppp eeeeeeeeeeee nnnn nnnnnnnn I::::I M::::::::::M M::::::::::M
|
|
||||||
O:::::O O:::::Op::::ppp:::::::::p ee::::::::::::ee n:::nn::::::::nn I::::I M:::::::::::M M:::::::::::M
|
|
||||||
O:::::O O:::::Op:::::::::::::::::p e::::::eeeee:::::een::::::::::::::nn I::::I M:::::::M::::M M::::M:::::::M
|
|
||||||
O:::::O O:::::Opp::::::ppppp::::::pe::::::e e:::::enn:::::::::::::::n I::::I M::::::M M::::M M::::M M::::::M
|
|
||||||
O:::::O O:::::O p:::::p p:::::pe:::::::eeeee::::::e n:::::nnnn:::::n I::::I M::::::M M::::M::::M M::::::M
|
|
||||||
O:::::O O:::::O p:::::p p:::::pe:::::::::::::::::e n::::n n::::n I::::I M::::::M M:::::::M M::::::M
|
|
||||||
O:::::O O:::::O p:::::p p:::::pe::::::eeeeeeeeeee n::::n n::::n I::::I M::::::M M:::::M M::::::M
|
|
||||||
O::::::O O::::::O p:::::p p::::::pe:::::::e n::::n n::::n I::::I M::::::M MMMMM M::::::M
|
|
||||||
O:::::::OOO:::::::O p:::::ppppp:::::::pe::::::::e n::::n n::::nII::::::IIM::::::M M::::::M
|
|
||||||
OO:::::::::::::OO p::::::::::::::::p e::::::::eeeeeeee n::::n n::::nI::::::::IM::::::M M::::::M
|
|
||||||
OO:::::::::OO p::::::::::::::pp ee:::::::::::::e n::::n n::::nI::::::::IM::::::M M::::::M
|
|
||||||
OOOOOOOOO p::::::pppppppp eeeeeeeeeeeeee nnnnnn nnnnnnIIIIIIIIIIMMMMMMMM MMMMMMMM
|
|
||||||
p:::::p
|
|
||||||
p:::::p
|
|
||||||
p:::::::p
|
|
||||||
p:::::::p
|
|
||||||
p:::::::p
|
|
||||||
ppppppppp
|
|
||||||
|
|
||||||
' 0.0001
|
|
||||||
|
|
||||||
# Display product URL
|
|
||||||
print_with_delay "Discover more and contribute at: https://github.com/openimsdk/open-im-server" 0.01
|
|
||||||
|
|
||||||
# Reset text color back to normal
|
|
||||||
echo -e "\033[0m"
|
|
||||||
|
|
||||||
# Set text color to green for product description
|
|
||||||
echo -e "\033[1;32m"
|
|
||||||
|
|
||||||
print_with_delay "Open-IM-Server: Reinventing Instant Messaging" 0.01
|
|
||||||
print_progress 50 0.02
|
|
||||||
|
|
||||||
print_with_delay "Open-IM-Server is not just a product; it's a revolution. It's about bringing the power of seamless," 0.01
|
|
||||||
print_with_delay "real-time messaging to your fingertips. And it's about joining a global community of developers, dedicated to pushing the boundaries of what's possible." 0.01
|
|
||||||
|
|
||||||
print_progress 50 0.02
|
|
||||||
|
|
||||||
# Reset text color back to normal
|
|
||||||
echo -e "\033[0m"
|
|
||||||
|
|
||||||
# Set text color to yellow for the Slack link
|
|
||||||
echo -e "\033[1;33m"
|
|
||||||
|
|
||||||
print_with_delay "Join our developer community on Slack: https://join.slack.com/t/openimsdk/shared_invite/zt-22720d66b-o_FvKxMTGXtcnnnHiMqe9Q" 0.01
|
|
||||||
|
|
||||||
# Reset text color back to normal
|
|
||||||
echo -e "\033[0m"
|
|
||||||
}
|
|
||||||
|
|
||||||
function main() {
|
|
||||||
openim_logo
|
|
||||||
}
|
|
||||||
main "$@"
|
|
@ -1,173 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
#**************************************************************************
|
|
||||||
# Copyright (C) 2011, Paul Lutus *
|
|
||||||
# *
|
|
||||||
# This program is free software; you can redistribute it and/or modify *
|
|
||||||
# it under the terms of the GNU General Public License as published by *
|
|
||||||
# the Free Software Foundation; either version 2 of the License, or *
|
|
||||||
# (at your option) any later version. *
|
|
||||||
# *
|
|
||||||
# This program is distributed in the hope that it will be useful, *
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
# GNU General Public License for more details. *
|
|
||||||
# *
|
|
||||||
# You should have received a copy of the GNU General Public License *
|
|
||||||
# along with this program; if not, write to the *
|
|
||||||
# Free Software Foundation, Inc., *
|
|
||||||
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
||||||
#**************************************************************************
|
|
||||||
|
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
|
|
||||||
PVERSION = '1.0'
|
|
||||||
|
|
||||||
|
|
||||||
class BeautifyBash:
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self.tab_str = ' '
|
|
||||||
self.tab_size = 2
|
|
||||||
|
|
||||||
def read_file(self, fp):
|
|
||||||
with open(fp) as f:
|
|
||||||
return f.read()
|
|
||||||
|
|
||||||
def write_file(self, fp, data):
|
|
||||||
with open(fp, 'w') as f:
|
|
||||||
f.write(data)
|
|
||||||
|
|
||||||
def beautify_string(self, data, path=''):
|
|
||||||
tab = 0
|
|
||||||
case_stack = []
|
|
||||||
in_here_doc = False
|
|
||||||
defer_ext_quote = False
|
|
||||||
in_ext_quote = False
|
|
||||||
ext_quote_string = ''
|
|
||||||
here_string = ''
|
|
||||||
output = []
|
|
||||||
line = 1
|
|
||||||
for record in re.split('\n', data):
|
|
||||||
record = record.rstrip()
|
|
||||||
stripped_record = record.strip()
|
|
||||||
|
|
||||||
# collapse multiple quotes between ' ... '
|
|
||||||
test_record = re.sub(r'\'.*?\'', '', stripped_record)
|
|
||||||
# collapse multiple quotes between " ... "
|
|
||||||
test_record = re.sub(r'".*?"', '', test_record)
|
|
||||||
# collapse multiple quotes between ` ... `
|
|
||||||
test_record = re.sub(r'`.*?`', '', test_record)
|
|
||||||
# collapse multiple quotes between \` ... ' (weird case)
|
|
||||||
test_record = re.sub(r'\\`.*?\'', '', test_record)
|
|
||||||
# strip out any escaped single characters
|
|
||||||
test_record = re.sub(r'\\.', '', test_record)
|
|
||||||
# remove '#' comments
|
|
||||||
test_record = re.sub(r'(\A|\s)(#.*)', '', test_record, 1)
|
|
||||||
if(not in_here_doc):
|
|
||||||
if(re.search('<<-?', test_record)):
|
|
||||||
here_string = re.sub(
|
|
||||||
'.*<<-?\s*[\'|"]?([_|\w]+)[\'|"]?.*', '\\1', stripped_record, 1)
|
|
||||||
in_here_doc = (len(here_string) > 0)
|
|
||||||
if(in_here_doc): # pass on with no changes
|
|
||||||
output.append(record)
|
|
||||||
# now test for here-doc termination string
|
|
||||||
if(re.search(here_string, test_record) and not re.search('<<', test_record)):
|
|
||||||
in_here_doc = False
|
|
||||||
else: # not in here doc
|
|
||||||
if(in_ext_quote):
|
|
||||||
if(re.search(ext_quote_string, test_record)):
|
|
||||||
# provide line after quotes
|
|
||||||
test_record = re.sub(
|
|
||||||
'.*%s(.*)' % ext_quote_string, '\\1', test_record, 1)
|
|
||||||
in_ext_quote = False
|
|
||||||
else: # not in ext quote
|
|
||||||
if(re.search(r'(\A|\s)(\'|")', test_record)):
|
|
||||||
# apply only after this line has been processed
|
|
||||||
defer_ext_quote = True
|
|
||||||
ext_quote_string = re.sub(
|
|
||||||
'.*([\'"]).*', '\\1', test_record, 1)
|
|
||||||
# provide line before quote
|
|
||||||
test_record = re.sub(
|
|
||||||
'(.*)%s.*' % ext_quote_string, '\\1', test_record, 1)
|
|
||||||
if(in_ext_quote):
|
|
||||||
# pass on unchanged
|
|
||||||
output.append(record)
|
|
||||||
else: # not in ext quote
|
|
||||||
inc = len(re.findall(
|
|
||||||
'(\s|\A|;)(case|then|do)(;|\Z|\s)', test_record))
|
|
||||||
inc += len(re.findall('(\{|\(|\[)', test_record))
|
|
||||||
outc = len(re.findall(
|
|
||||||
'(\s|\A|;)(esac|fi|done|elif)(;|\)|\||\Z|\s)', test_record))
|
|
||||||
outc += len(re.findall('(\}|\)|\])', test_record))
|
|
||||||
if(re.search(r'\besac\b', test_record)):
|
|
||||||
if(len(case_stack) == 0):
|
|
||||||
sys.stderr.write(
|
|
||||||
'File %s: error: "esac" before "case" in line %d.\n' % (
|
|
||||||
path, line)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
outc += case_stack.pop()
|
|
||||||
# sepcial handling for bad syntax within case ... esac
|
|
||||||
if(len(case_stack) > 0):
|
|
||||||
if(re.search('\A[^(]*\)', test_record)):
|
|
||||||
# avoid overcount
|
|
||||||
outc -= 2
|
|
||||||
case_stack[-1] += 1
|
|
||||||
if(re.search(';;', test_record)):
|
|
||||||
outc += 1
|
|
||||||
case_stack[-1] -= 1
|
|
||||||
# an ad-hoc solution for the "else" keyword
|
|
||||||
else_case = (
|
|
||||||
0, -1)[re.search('^(else)', test_record) != None]
|
|
||||||
net = inc - outc
|
|
||||||
tab += min(net, 0)
|
|
||||||
extab = tab + else_case
|
|
||||||
extab = max(0, extab)
|
|
||||||
output.append(
|
|
||||||
(self.tab_str * self.tab_size * extab) + stripped_record)
|
|
||||||
tab += max(net, 0)
|
|
||||||
if(defer_ext_quote):
|
|
||||||
in_ext_quote = True
|
|
||||||
defer_ext_quote = False
|
|
||||||
if(re.search(r'\bcase\b', test_record)):
|
|
||||||
case_stack.append(0)
|
|
||||||
line += 1
|
|
||||||
error = (tab != 0)
|
|
||||||
if(error):
|
|
||||||
sys.stderr.write(
|
|
||||||
'File %s: error: indent/outdent mismatch: %d.\n' % (path, tab))
|
|
||||||
return '\n'.join(output), error
|
|
||||||
|
|
||||||
def beautify_file(self, path):
|
|
||||||
error = False
|
|
||||||
if(path == '-'):
|
|
||||||
data = sys.stdin.read()
|
|
||||||
result, error = self.beautify_string(data, '(stdin)')
|
|
||||||
sys.stdout.write(result)
|
|
||||||
else: # named file
|
|
||||||
data = self.read_file(path)
|
|
||||||
result, error = self.beautify_string(data, path)
|
|
||||||
if(data != result):
|
|
||||||
# make a backup copy
|
|
||||||
self.write_file(path + '~', data)
|
|
||||||
self.write_file(path, result)
|
|
||||||
return error
|
|
||||||
|
|
||||||
def main(self):
|
|
||||||
error = False
|
|
||||||
sys.argv.pop(0)
|
|
||||||
if(len(sys.argv) < 1):
|
|
||||||
sys.stderr.write(
|
|
||||||
'usage: shell script filenames or \"-\" for stdin.\n')
|
|
||||||
else:
|
|
||||||
for path in sys.argv:
|
|
||||||
error |= self.beautify_file(path)
|
|
||||||
sys.exit((0, 1)[error])
|
|
||||||
|
|
||||||
# if not called as a module
|
|
||||||
if(__name__ == '__main__'):
|
|
||||||
BeautifyBash().main()
|
|
||||||
|
|
@ -1,72 +0,0 @@
|
|||||||
#!/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 runs `make build` command.
|
|
||||||
# The command compiles all Makefile configs.
|
|
||||||
# Args:
|
|
||||||
# WHAT: Directory names to build. If any of these directories has a 'main'
|
|
||||||
# package, the build will produce executable files under $(OUT_DIR)/bin/platforms OR $(OUT_DIR)/bin—tools/platforms.
|
|
||||||
# If not specified, "everything" will be built.
|
|
||||||
# Usage: `scripts/build-all-service.sh`.
|
|
||||||
# Example: `scripts/build-go.sh WHAT=cmd/kubelet`.
|
|
||||||
|
|
||||||
|
|
||||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
|
||||||
source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
|
||||||
|
|
||||||
# CPU core number
|
|
||||||
pushd "${OPENIM_ROOT}/tools/ncpu" >/dev/null
|
|
||||||
cpu_count=$(go run .)
|
|
||||||
popd >/dev/null
|
|
||||||
|
|
||||||
openim::color::echo ${GREEN_PREFIX} "======> cpu_count=$cpu_count"
|
|
||||||
|
|
||||||
openim::log::info "Building OpenIM, Parallel compilation compile=$cpu_count"
|
|
||||||
compile_count=$((cpu_count / 2))
|
|
||||||
|
|
||||||
# For help output
|
|
||||||
ARGHELP=""
|
|
||||||
if [[ "$#" -gt 0 ]]; then
|
|
||||||
ARGHELP="'$*'"
|
|
||||||
fi
|
|
||||||
|
|
||||||
openim::color::echo $COLOR_CYAN "NOTE: $0 has been replaced by 'make multiarch' or 'make build'"
|
|
||||||
echo
|
|
||||||
echo "The equivalent of this invocation is: "
|
|
||||||
echo " make build ${ARGHELP}"
|
|
||||||
echo " ./scripts/build-all-service.sh ${ARGHELP}"
|
|
||||||
echo
|
|
||||||
echo " Example: "
|
|
||||||
echo " Print a single binary:"
|
|
||||||
echo " make build BINS=openim-api"
|
|
||||||
echo " ./scripts/build-all-service.sh BINS=openim-api"
|
|
||||||
echo " Print : Enable debugging and logging"
|
|
||||||
echo " make build BINS=openim-api V=1 DEBUG=1"
|
|
||||||
echo " ./scripts/build-all-service.sh BINS=openim-api V=1 DEBUG=1"
|
|
||||||
echo
|
|
||||||
|
|
||||||
if [ -z "$*" ]; then
|
|
||||||
openim::log::info "no args, build all service"
|
|
||||||
make --no-print-directory -C "${OPENIM_ROOT}" -j$compile_count build
|
|
||||||
else
|
|
||||||
openim::log::info "build service: $*"
|
|
||||||
make --no-print-directory -C "${OPENIM_ROOT}" -j$compile_count build "$*"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
openim::log::success "all service build success, run 'make start' or './scripts/start-all.sh'"
|
|
||||||
else
|
|
||||||
openim::log::error "make build Error, script exits"
|
|
||||||
fi
|
|
@ -1,113 +0,0 @@
|
|||||||
#!/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 is check openim service is running normally
|
|
||||||
#
|
|
||||||
# Usage: `scripts/check-all.sh`.
|
|
||||||
# Encapsulated as: `make check`.
|
|
||||||
# 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"
|
|
||||||
|
|
||||||
if openim::util::is_running_in_container; then
|
|
||||||
exec >> ${DOCKER_LOG_FILE} 2>&1
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
OPENIM_VERBOSE=4
|
|
||||||
|
|
||||||
openim::log::info "\n# Begin to check all OpenIM service"
|
|
||||||
|
|
||||||
openim::log::status "Check all dependent service ports"
|
|
||||||
# Elegant printing function
|
|
||||||
# Elegant printing function
|
|
||||||
print_services_and_ports() {
|
|
||||||
local service_names=("$@")
|
|
||||||
local half_length=$((${#service_names[@]} / 2))
|
|
||||||
local service_ports=("${service_names[@]:half_length}")
|
|
||||||
|
|
||||||
echo "+-------------------------+----------+"
|
|
||||||
echo "| Service Name | Port |"
|
|
||||||
echo "+-------------------------+----------+"
|
|
||||||
|
|
||||||
for ((index=0; index < half_length; index++)); do
|
|
||||||
printf "| %-23s | %-8s |\n" "${service_names[$index]}" "${service_ports[$index]}"
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "+-------------------------+----------+"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Assuming OPENIM_SERVER_NAME_TARGETS and OPENIM_SERVER_PORT_TARGETS are defined
|
|
||||||
# Similarly for OPENIM_DEPENDENCY_TARGETS and OPENIM_DEPENDENCY_PORT_TARGETS
|
|
||||||
|
|
||||||
# Print out services and their ports
|
|
||||||
print_services_and_ports "${OPENIM_SERVER_NAME_TARGETS[@]}" "${OPENIM_SERVER_PORT_TARGETS[@]}"
|
|
||||||
|
|
||||||
# Print out dependencies and their ports
|
|
||||||
print_services_and_ports "${OPENIM_DEPENDENCY_TARGETS[@]}" "${OPENIM_DEPENDENCY_PORT_TARGETS[@]}"
|
|
||||||
|
|
||||||
# OpenIM check
|
|
||||||
#echo "++ The port being checked: ${OPENIM_SERVER_PORT_LISTARIES[@]}"
|
|
||||||
openim::log::info "\n## Check all dependent components service ports"
|
|
||||||
#echo "++ The port being checked: ${OPENIM_DEPENDENCY_PORT_LISTARIES[@]}"
|
|
||||||
|
|
||||||
|
|
||||||
# Later, after discarding Docker, the Docker keyword is unreliable, and Kubepods is used
|
|
||||||
if grep -qE 'docker|kubepods' /proc/1/cgroup || [ -f /.dockerenv ]; then
|
|
||||||
openim::color::echo ${COLOR_CYAN} "Environment in the interior of the container"
|
|
||||||
else
|
|
||||||
openim::color::echo ${COLOR_CYAN}"The environment is outside the container"
|
|
||||||
openim::util::check_ports ${OPENIM_DEPENDENCY_PORT_LISTARIES[@]}
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $? -ne 0 ]]; then
|
|
||||||
openim::log::error_exit "The service does not start properly, please check the port, query variable definition!"
|
|
||||||
echo "+++ https://github.com/openimsdk/open-im-server/tree/main/scripts/install/environment.sh +++"
|
|
||||||
else
|
|
||||||
openim::log::success "All components depended on by OpenIM are running normally! "
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
openim::log::status "Check OpenIM service:"
|
|
||||||
openim::log::colorless "${OPENIM_OUTPUT_HOSTBIN}/openim-msgtransfer"
|
|
||||||
result=$(. $(dirname ${BASH_SOURCE})/install/openim-msgtransfer.sh openim::msgtransfer::check)
|
|
||||||
if [[ $? -ne 0 ]]; then
|
|
||||||
#echo "+++ cat openim log file >>> ${LOG_FILE}"
|
|
||||||
|
|
||||||
openim::log::error "The service is not running properly, please check the logs $result"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
openim::log::status "Check OpenIM service:"
|
|
||||||
for item in "${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]}"; do
|
|
||||||
openim::log::colorless "$item"
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
result=$(openim::util::check_process_names ${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]})
|
|
||||||
if [[ $? -ne 0 ]]; then
|
|
||||||
#echo "+++ cat OpenIM log file >>> ${LOG_FILE}"
|
|
||||||
openim::log::error "The service is not running properly, please check the logs "
|
|
||||||
echo "$result"
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
openim::log::status "List the ports listened to by the OpenIM service:"
|
|
||||||
openim::util::find_ports_for_all_services ${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]}
|
|
||||||
openim::util::find_ports_for_all_services ${OPENIM_MSGTRANSFER_BINARY[@]}
|
|
||||||
openim::log::success "All OpenIM services are running normally! "
|
|
||||||
fi
|
|
@ -1,252 +0,0 @@
|
|||||||
#!/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.
|
|
||||||
|
|
||||||
|
|
||||||
# Usage Instructions: https://github.com/openimsdk/open-im-server/tree/main/docs/contrib/gitcherry-pick.md
|
|
||||||
|
|
||||||
# Checkout a PR from GitHub. (Yes, this is sitting in a Git tree. How
|
|
||||||
# meta.) Assumes you care about pulls from remote "upstream" and
|
|
||||||
# checks them out to a branch named:
|
|
||||||
# automated-cherry-pick-of-<pr>-<target branch>-<timestamp>
|
|
||||||
|
|
||||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
|
||||||
source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
|
||||||
|
|
||||||
REPO_ROOT="$(git rev-parse --show-toplevel)"
|
|
||||||
declare -r REPO_ROOT
|
|
||||||
cd "${REPO_ROOT}"
|
|
||||||
|
|
||||||
STARTINGBRANCH=$(git symbolic-ref --short HEAD)
|
|
||||||
declare -r STARTINGBRANCH
|
|
||||||
declare -r REBASEMAGIC="${REPO_ROOT}/.git/rebase-apply"
|
|
||||||
DRY_RUN=${DRY_RUN:-""}
|
|
||||||
REGENERATE_DOCS=${REGENERATE_DOCS:-""}
|
|
||||||
UPSTREAM_REMOTE=${UPSTREAM_REMOTE:-upstream}
|
|
||||||
FORK_REMOTE=${FORK_REMOTE:-origin}
|
|
||||||
MAIN_REPO_ORG=${MAIN_REPO_ORG:-$(git remote get-url "$UPSTREAM_REMOTE" | awk '{gsub(/webhook[s]:\/\/|git@/,"")}1' | awk -F'[@:./]' 'NR==1{print $3}')}
|
|
||||||
MAIN_REPO_NAME=${MAIN_REPO_NAME:-$(git remote get-url "$UPSTREAM_REMOTE" | awk '{gsub(/webhook[s]:\/\/|git@/,"")}1' | awk -F'[@:./]' 'NR==1{print $4}')}
|
|
||||||
|
|
||||||
if [[ -z ${GITHUB_USER:-} ]]; then
|
|
||||||
openim::log::error_exit "Please export GITHUB_USER=<your-user> (or GH organization, if that's where your fork lives)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! command -v gh > /dev/null; then
|
|
||||||
openim::log::error_exit "Can't find 'gh' tool in PATH, please install from https://github.com/cli/cli"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "$#" -lt 2 ]]; then
|
|
||||||
echo "${0} <remote branch> <pr-number>...: cherry pick one or more <pr> onto <remote branch> and leave instructions for proposing pull request"
|
|
||||||
echo
|
|
||||||
echo " Checks out <remote branch> and handles the cherry-pick of <pr> (possibly multiple) for you."
|
|
||||||
echo " Examples:"
|
|
||||||
echo " $0 upstream/release-v3.1 12345 # Cherry-picks PR 12345 onto upstream/release-v3.1 and proposes that as a PR."
|
|
||||||
echo " $0 upstream/release-v3.1 12345 56789 # Cherry-picks PR 12345, then 56789 and proposes the combination as a single PR."
|
|
||||||
echo
|
|
||||||
echo " Set the DRY_RUN environment var to skip git push and creating PR."
|
|
||||||
echo " This is useful for creating patches to a release branch without making a PR."
|
|
||||||
echo " When DRY_RUN is set the script will leave you in a branch containing the commits you cherry-picked."
|
|
||||||
echo
|
|
||||||
echo " Set the REGENERATE_DOCS environment var to regenerate documentation for the target branch after picking the specified commits."
|
|
||||||
echo " This is useful when picking commits containing changes to API documentation."
|
|
||||||
echo
|
|
||||||
echo " Set UPSTREAM_REMOTE (default: upstream) and FORK_REMOTE (default: origin)"
|
|
||||||
echo " to override the default remote names to what you have locally."
|
|
||||||
echo
|
|
||||||
echo " For merge process info, see https://github.com/openimsdk/open-im-server/tree/main/docs/contrib/gitcherry-pick.md"
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Checks if you are logged in. Will error/bail if you are not.
|
|
||||||
gh auth status
|
|
||||||
|
|
||||||
if git_status=$(git status --porcelain --untracked=no 2>/dev/null) && [[ -n "${git_status}" ]]; then
|
|
||||||
openim::log::error_exit "!!! Dirty tree. Clean up and try again."
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -e "${REBASEMAGIC}" ]]; then
|
|
||||||
openim::log::error_exit "!!! 'git rebase' or 'git am' in progress. Clean up and try again."
|
|
||||||
fi
|
|
||||||
|
|
||||||
declare -r BRANCH="$1"
|
|
||||||
shift 1
|
|
||||||
declare -r PULLS=( "$@" )
|
|
||||||
|
|
||||||
function join { local IFS="$1"; shift; echo "$*"; }
|
|
||||||
PULLDASH=$(join - "${PULLS[@]/#/#}") # Generates something like "#12345-#56789"
|
|
||||||
declare -r PULLDASH
|
|
||||||
PULLSUBJ=$(join " " "${PULLS[@]/#/#}") # Generates something like "#12345 #56789"
|
|
||||||
declare -r PULLSUBJ
|
|
||||||
|
|
||||||
openim::log::status "Updating remotes..."
|
|
||||||
git remote update "${UPSTREAM_REMOTE}" "${FORK_REMOTE}"
|
|
||||||
|
|
||||||
if ! git log -n1 --format=%H "${BRANCH}" >/dev/null 2>&1; then
|
|
||||||
openim::log::error " '${BRANCH}' not found. The second argument should be something like ${UPSTREAM_REMOTE}/release-0.21."
|
|
||||||
openim::log::error " (In particular, it needs to be a valid, existing remote branch that I can 'git checkout'.)"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
NEWBRANCHREQ="automated-cherry-pick-of-${PULLDASH}" # "Required" portion for tools.
|
|
||||||
declare -r NEWBRANCHREQ
|
|
||||||
NEWBRANCH="$(echo "${NEWBRANCHREQ}-${BRANCH}" | sed 's/\//-/g')"
|
|
||||||
declare -r NEWBRANCH
|
|
||||||
NEWBRANCHUNIQ="${NEWBRANCH}-$(date +%s)"
|
|
||||||
declare -r NEWBRANCHUNIQ
|
|
||||||
openim::log::info "+++ Creating local branch ${NEWBRANCHUNIQ}"
|
|
||||||
|
|
||||||
cleanbranch=""
|
|
||||||
gitamcleanup=false
|
|
||||||
function return_to_kansas {
|
|
||||||
if [[ "${gitamcleanup}" == "true" ]]; then
|
|
||||||
echo
|
|
||||||
openim::log::status "Aborting in-progress git am."
|
|
||||||
git am --abort >/dev/null 2>&1 || true
|
|
||||||
fi
|
|
||||||
|
|
||||||
# return to the starting branch and delete the PR text file
|
|
||||||
if [[ -z "${DRY_RUN}" ]]; then
|
|
||||||
echo
|
|
||||||
openim::log::status "Returning you to the ${STARTINGBRANCH} branch and cleaning up."
|
|
||||||
git checkout -f "${STARTINGBRANCH}" >/dev/null 2>&1 || true
|
|
||||||
if [[ -n "${cleanbranch}" ]]; then
|
|
||||||
git branch -D "${cleanbranch}" >/dev/null 2>&1 || true
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
trap return_to_kansas EXIT
|
|
||||||
|
|
||||||
SUBJECTS=()
|
|
||||||
function make-a-pr() {
|
|
||||||
local rel
|
|
||||||
rel="$(basename "${BRANCH}")"
|
|
||||||
echo
|
|
||||||
openim::log::status "Creating a pull request on GitHub at ${GITHUB_USER}:${NEWBRANCH}"
|
|
||||||
|
|
||||||
local numandtitle
|
|
||||||
numandtitle=$(printf '%s\n' "${SUBJECTS[@]}")
|
|
||||||
prtext=$(cat <<EOF
|
|
||||||
Cherry pick of ${PULLSUBJ} on ${rel}.
|
|
||||||
|
|
||||||
${numandtitle}
|
|
||||||
|
|
||||||
For details on the cherry pick process, see the [cherry pick requests](https://github.com/openimsdk/open-im-server/tree/main/docs/contrib/gitcherry-pick.md) page.
|
|
||||||
|
|
||||||
\`\`\`release-note
|
|
||||||
|
|
||||||
\`\`\`
|
|
||||||
EOF
|
|
||||||
)
|
|
||||||
|
|
||||||
gh pr create --title="Automated cherry pick of ${numandtitle}" --body="${prtext}" --head "${GITHUB_USER}:${NEWBRANCH}" --base "${rel}" --repo="${MAIN_REPO_ORG}/${MAIN_REPO_NAME}"
|
|
||||||
}
|
|
||||||
|
|
||||||
git checkout -b "${NEWBRANCHUNIQ}" "${BRANCH}"
|
|
||||||
cleanbranch="${NEWBRANCHUNIQ}"
|
|
||||||
|
|
||||||
gitamcleanup=true
|
|
||||||
for pull in "${PULLS[@]}"; do
|
|
||||||
openim::log::status "Downloading patch to /tmp/${pull}.patch (in case you need to do this again)"
|
|
||||||
|
|
||||||
curl -o "/tmp/${pull}.patch" -sSL "https://github.com/${MAIN_REPO_ORG}/${MAIN_REPO_NAME}/pull/${pull}.patch"
|
|
||||||
echo
|
|
||||||
openim::log::status "About to attempt cherry pick of PR. To reattempt:"
|
|
||||||
echo " $ git am -3 /tmp/${pull}.patch"
|
|
||||||
echo
|
|
||||||
git am -3 "/tmp/${pull}.patch" || {
|
|
||||||
conflicts=false
|
|
||||||
while unmerged=$(git status --porcelain | grep ^U) && [[ -n ${unmerged} ]] \
|
|
||||||
|| [[ -e "${REBASEMAGIC}" ]]; do
|
|
||||||
conflicts=true # <-- We should have detected conflicts once
|
|
||||||
echo
|
|
||||||
openim::log::status "Conflicts detected:"
|
|
||||||
echo
|
|
||||||
(git status --porcelain | grep ^U) || echo "!!! None. Did you git am --continue?"
|
|
||||||
echo
|
|
||||||
openim::log::status "Please resolve the conflicts in another window (and remember to 'git add / git am --continue')"
|
|
||||||
read -p "+++ Proceed (anything other than 'y' aborts the cherry-pick)? [y/n] " -r
|
|
||||||
echo
|
|
||||||
if ! [[ "${REPLY}" =~ ^[yY]$ ]]; then
|
|
||||||
echo "Aborting." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [[ "${conflicts}" != "true" ]]; then
|
|
||||||
echo "!!! git am failed, likely because of an in-progress 'git am' or 'git rebase'"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# set the subject
|
|
||||||
subject=$(grep -m 1 "^Subject" "/tmp/${pull}.patch" | sed -e 's/Subject: \[PATCH//g' | sed 's/.*] //')
|
|
||||||
SUBJECTS+=("#${pull}: ${subject}")
|
|
||||||
|
|
||||||
# remove the patch file from /tmp
|
|
||||||
rm -f "/tmp/${pull}.patch"
|
|
||||||
done
|
|
||||||
gitamcleanup=false
|
|
||||||
|
|
||||||
# Re-generate docs (if needed)
|
|
||||||
if [[ -n "${REGENERATE_DOCS}" ]]; then
|
|
||||||
echo
|
|
||||||
echo "Regenerating docs..."
|
|
||||||
if ! scripts/generate-docs.sh; then
|
|
||||||
echo
|
|
||||||
echo "scripts/gendoc.sh FAILED to complete."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -n "${DRY_RUN}" ]]; then
|
|
||||||
openim::log::error "!!! Skipping git push and PR creation because you set DRY_RUN."
|
|
||||||
echo "To return to the branch you were in when you invoked this script:"
|
|
||||||
echo
|
|
||||||
echo " git checkout ${STARTINGBRANCH}"
|
|
||||||
echo
|
|
||||||
echo "To delete this branch:"
|
|
||||||
echo
|
|
||||||
echo " git branch -D ${NEWBRANCHUNIQ}"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
if git remote -v | grep ^"${FORK_REMOTE}" | grep "${MAIN_REPO_ORG}/${MAIN_REPO_NAME}.git"; then
|
|
||||||
echo "!!! You have ${FORK_REMOTE} configured as your ${MAIN_REPO_ORG}/${MAIN_REPO_NAME}.git"
|
|
||||||
echo "This isn't normal. Leaving you with push instructions:"
|
|
||||||
echo
|
|
||||||
openim::log::status "First manually push the branch this script created:"
|
|
||||||
echo
|
|
||||||
echo " git push REMOTE ${NEWBRANCHUNIQ}:${NEWBRANCH}"
|
|
||||||
echo
|
|
||||||
echo "where REMOTE is your personal fork (maybe ${UPSTREAM_REMOTE}? Consider swapping those.)."
|
|
||||||
echo "OR consider setting UPSTREAM_REMOTE and FORK_REMOTE to different values."
|
|
||||||
echo
|
|
||||||
make-a-pr
|
|
||||||
cleanbranch=""
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo
|
|
||||||
openim::log::status "I'm about to do the following to push to GitHub (and I'm assuming ${FORK_REMOTE} is your personal fork):"
|
|
||||||
echo
|
|
||||||
echo " git push ${FORK_REMOTE} ${NEWBRANCHUNIQ}:${NEWBRANCH}"
|
|
||||||
echo
|
|
||||||
read -p "+++ Proceed (anything other than 'y' aborts the cherry-pick)? [y/n] " -r
|
|
||||||
if ! [[ "${REPLY}" =~ ^[yY]$ ]]; then
|
|
||||||
echo "Aborting." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
git push "${FORK_REMOTE}" -f "${NEWBRANCHUNIQ}:${NEWBRANCH}"
|
|
||||||
make-a-pr
|
|
@ -1,516 +0,0 @@
|
|||||||
#!/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.
|
|
||||||
|
|
||||||
|
|
||||||
# shellcheck disable=SC2034 # Variables sourced in other scripts.
|
|
||||||
|
|
||||||
# Common utilities, variables and checks for all build scripts.
|
|
||||||
|
|
||||||
# Unset CDPATH, having it set messes up with script import paths
|
|
||||||
unset CDPATH
|
|
||||||
|
|
||||||
USER_ID=$(id -u)
|
|
||||||
GROUP_ID=$(id -g)
|
|
||||||
|
|
||||||
DOCKER_OPTS=${DOCKER_OPTS:-""}
|
|
||||||
IFS=" " read -r -a DOCKER <<< "docker ${DOCKER_OPTS}"
|
|
||||||
DOCKER_HOST=${DOCKER_HOST:-""}
|
|
||||||
DOCKER_MACHINE_NAME=${DOCKER_MACHINE_NAME:-"openim-dev"}
|
|
||||||
readonly DOCKER_MACHINE_DRIVER=${DOCKER_MACHINE_DRIVER:-"virtualbox --virtualbox-cpu-count -1"}
|
|
||||||
|
|
||||||
# This will canonicalize the path
|
|
||||||
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd -P)
|
|
||||||
|
|
||||||
# Please do not refer to lib after referring to common
|
|
||||||
. $(dirname ${BASH_SOURCE})/lib/init.sh
|
|
||||||
|
|
||||||
# Constants
|
|
||||||
readonly OPENIM_BUILD_IMAGE_REPO=openim-build
|
|
||||||
#readonly OPENIM_BUILD_IMAGE_CROSS_TAG="$(cat "${OPENIM_ROOT}/build/build-image/cross/VERSION")"
|
|
||||||
|
|
||||||
readonly OPENIM_DOCKER_REGISTRY="${OPENIM_DOCKER_REGISTRY:-k8s.gcr.io}"
|
|
||||||
readonly OPENIM_BASE_IMAGE_REGISTRY="${OPENIM_BASE_IMAGE_REGISTRY:-us.gcr.io/k8s-artifacts-prod/build-image}"
|
|
||||||
|
|
||||||
# This version number is used to cause everyone to rebuild their data containers
|
|
||||||
# and build image. This is especially useful for automated build systems like
|
|
||||||
# Jenkins.
|
|
||||||
#
|
|
||||||
# Increment/change this number if you change the build image (anything under
|
|
||||||
# build/build-image) or change the set of volumes in the data container.
|
|
||||||
#readonly OPENIM_BUILD_IMAGE_VERSION_BASE="$(cat "${OPENIM_ROOT}/build/build-image/VERSION")"
|
|
||||||
#readonly OPENIM_BUILD_IMAGE_VERSION="${OPENIM_BUILD_IMAGE_VERSION_BASE}-${OPENIM_BUILD_IMAGE_CROSS_TAG}"
|
|
||||||
|
|
||||||
# Here we map the output directories across both the local and remote _output
|
|
||||||
# directories:
|
|
||||||
#
|
|
||||||
# *_OUTPUT_ROOT - the base of all output in that environment.
|
|
||||||
# *_OUTPUT_SUBPATH - location where golang stuff is built/cached. Also
|
|
||||||
# persisted across docker runs with a volume mount.
|
|
||||||
# *_OUTPUT_BINPATH - location where final binaries are placed. If the remote
|
|
||||||
# is really remote, this is the stuff that has to be copied
|
|
||||||
# back.
|
|
||||||
# OUT_DIR can come in from the Makefile, so honor it.
|
|
||||||
readonly LOCAL_OUTPUT_ROOT="${OPENIM_ROOT}/${OUT_DIR:-_output}"
|
|
||||||
readonly LOCAL_OUTPUT_SUBPATH="${LOCAL_OUTPUT_ROOT}/bin"
|
|
||||||
readonly LOCAL_OUTPUT_BINPATH="${LOCAL_OUTPUT_SUBPATH}/platforms"
|
|
||||||
readonly LOCAL_OUTPUT_BINTOOLSPATH="${LOCAL_OUTPUT_SUBPATH}/tools"
|
|
||||||
readonly LOCAL_OUTPUT_GOPATH="${LOCAL_OUTPUT_SUBPATH}/go"
|
|
||||||
readonly LOCAL_OUTPUT_IMAGE_STAGING="${LOCAL_OUTPUT_ROOT}/images"
|
|
||||||
|
|
||||||
# This is the port on the workstation host to expose RSYNC on. Set this if you
|
|
||||||
# are doing something fancy with ssh tunneling.
|
|
||||||
readonly OPENIM_RSYNC_PORT="${OPENIM_RSYNC_PORT:-}"
|
|
||||||
|
|
||||||
# This is the port that rsync is running on *inside* the container. This may be
|
|
||||||
# mapped to OPENIM_RSYNC_PORT via docker networking.
|
|
||||||
readonly OPENIM_CONTAINER_RSYNC_PORT=8730
|
|
||||||
|
|
||||||
# Get the set of master binaries that run in Docker (on Linux)
|
|
||||||
# Entry format is "<name-of-binary>,<base-image>".
|
|
||||||
# Binaries are placed in /usr/local/bin inside the image.
|
|
||||||
#
|
|
||||||
# $1 - server architecture
|
|
||||||
openim::build::get_docker_wrapped_binaries() {
|
|
||||||
local arch=$1
|
|
||||||
local debian_base_version=v2.1.0
|
|
||||||
local debian_iptables_version=v12.1.0
|
|
||||||
### If you change any of these lists, please also update DOCKERIZED_BINARIES
|
|
||||||
### in build/BUILD. And openim::golang::server_image_targets
|
|
||||||
|
|
||||||
local targets=(
|
|
||||||
"openim-api,${OPENIM_BASE_IMAGE_REGISTRY}/debian-base-${arch}:${debian_base_version}"
|
|
||||||
"openim-cmdutils,${OPENIM_BASE_IMAGE_REGISTRY}/debian-base-${arch}:${debian_base_version}"
|
|
||||||
"openim-crontask,${OPENIM_BASE_IMAGE_REGISTRY}/debian-base-${arch}:${debian_base_version}"
|
|
||||||
"openim-msggateway,${OPENIM_BASE_IMAGE_REGISTRY}/debian-base-${arch}:${debian_base_version}"
|
|
||||||
"openim-msgtransfer,${OPENIM_BASE_IMAGE_REGISTRY}/debian-base-${arch}:${debian_base_version}"
|
|
||||||
"openim-push,${OPENIM_BASE_IMAGE_REGISTRY}/debian-base-${arch}:${debian_base_version}"
|
|
||||||
"openim-rpc-auth,${OPENIM_BASE_IMAGE_REGISTRY}/debian-base-${arch}:${debian_base_version}"
|
|
||||||
"openim-rpc-conversation,${OPENIM_BASE_IMAGE_REGISTRY}/debian-base-${arch}:${debian_base_version}"
|
|
||||||
"openim-rpc-friend,${OPENIM_BASE_IMAGE_REGISTRY}/debian-base-${arch}:${debian_base_version}"
|
|
||||||
"openim-rpc-group,${OPENIM_BASE_IMAGE_REGISTRY}/debian-base-${arch}:${debian_base_version}"
|
|
||||||
"openim-rpc-msg,${OPENIM_BASE_IMAGE_REGISTRY}/debian-base-${arch}:${debian_base_version}"
|
|
||||||
"openim-rpc-third,${OPENIM_BASE_IMAGE_REGISTRY}/debian-base-${arch}:${debian_base_version}"
|
|
||||||
"openim-rpc-user,${OPENIM_BASE_IMAGE_REGISTRY}/debian-base-${arch}:${debian_base_version}"
|
|
||||||
)
|
|
||||||
echo "${targets[@]}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# Basic setup functions
|
|
||||||
|
|
||||||
# Verify that the right utilities and such are installed for building openim. Set
|
|
||||||
# up some dynamic constants.
|
|
||||||
# Args:
|
|
||||||
# $1 - boolean of whether to require functioning docker (default true)
|
|
||||||
#
|
|
||||||
# Vars set:
|
|
||||||
# OPENIM_ROOT_HASH
|
|
||||||
# OPENIM_BUILD_IMAGE_TAG_BASE
|
|
||||||
# OPENIM_BUILD_IMAGE_TAG
|
|
||||||
# OPENIM_BUILD_IMAGE
|
|
||||||
# OPENIM_BUILD_CONTAINER_NAME_BASE
|
|
||||||
# OPENIM_BUILD_CONTAINER_NAME
|
|
||||||
# OPENIM_DATA_CONTAINER_NAME_BASE
|
|
||||||
# OPENIM_DATA_CONTAINER_NAME
|
|
||||||
# OPENIM_RSYNC_CONTAINER_NAME_BASE
|
|
||||||
# OPENIM_RSYNC_CONTAINER_NAME
|
|
||||||
# DOCKER_MOUNT_ARGS
|
|
||||||
# LOCAL_OUTPUT_BUILD_CONTEXT
|
|
||||||
function openim::build::verify_prereqs() {
|
|
||||||
local -r require_docker=${1:-true}
|
|
||||||
openim::log::status "Verifying Prerequisites...."
|
|
||||||
openim::build::ensure_tar || return 1
|
|
||||||
openim::build::ensure_rsync || return 1
|
|
||||||
if ${require_docker}; then
|
|
||||||
openim::build::ensure_docker_in_path || return 1
|
|
||||||
openim::util::ensure_docker_daemon_connectivity || return 1
|
|
||||||
|
|
||||||
if (( OPENIM_VERBOSE > 6 )); then
|
|
||||||
openim::log::status "Docker Version:"
|
|
||||||
"${DOCKER[@]}" version | openim::log::info_from_stdin
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
OPENIM_GIT_BRANCH=$(git symbolic-ref --short -q HEAD 2>/dev/null || true)
|
|
||||||
OPENIM_ROOT_HASH=$(openim::build::short_hash "${HOSTNAME:-}:${OPENIM_ROOT}:${OPENIM_GIT_BRANCH}")
|
|
||||||
OPENIM_BUILD_IMAGE_TAG_BASE="build-${OPENIM_ROOT_HASH}"
|
|
||||||
#OPENIM_BUILD_IMAGE_TAG="${OPENIM_BUILD_IMAGE_TAG_BASE}-${OPENIM_BUILD_IMAGE_VERSION}"
|
|
||||||
#OPENIM_BUILD_IMAGE="${OPENIM_BUILD_IMAGE_REPO}:${OPENIM_BUILD_IMAGE_TAG}"
|
|
||||||
OPENIM_BUILD_CONTAINER_NAME_BASE="openim-build-${OPENIM_ROOT_HASH}"
|
|
||||||
#OPENIM_BUILD_CONTAINER_NAME="${OPENIM_BUILD_CONTAINER_NAME_BASE}-${OPENIM_BUILD_IMAGE_VERSION}"
|
|
||||||
OPENIM_RSYNC_CONTAINER_NAME_BASE="openim-rsync-${OPENIM_ROOT_HASH}"
|
|
||||||
#OPENIM_RSYNC_CONTAINER_NAME="${OPENIM_RSYNC_CONTAINER_NAME_BASE}-${OPENIM_BUILD_IMAGE_VERSION}"
|
|
||||||
OPENIM_DATA_CONTAINER_NAME_BASE="openim-build-data-${OPENIM_ROOT_HASH}"
|
|
||||||
#OPENIM_DATA_CONTAINER_NAME="${OPENIM_DATA_CONTAINER_NAME_BASE}-${OPENIM_BUILD_IMAGE_VERSION}"
|
|
||||||
#DOCKER_MOUNT_ARGS=(--volumes-from "${OPENIM_DATA_CONTAINER_NAME}")
|
|
||||||
#LOCAL_OUTPUT_BUILD_CONTEXT="${LOCAL_OUTPUT_IMAGE_STAGING}/${OPENIM_BUILD_IMAGE}"
|
|
||||||
|
|
||||||
openim::version::get_version_vars
|
|
||||||
#openim::version::save_version_vars "${OPENIM_ROOT}/.dockerized-openim-version-defs"
|
|
||||||
}
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# Utility functions
|
|
||||||
|
|
||||||
function openim::build::docker_available_on_osx() {
|
|
||||||
if [[ -z "${DOCKER_HOST}" ]]; then
|
|
||||||
if [[ -S "/var/run/docker.sock" ]]; then
|
|
||||||
openim::log::status "Using Docker for MacOS"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
openim::log::status "No docker host is set. Checking options for setting one..."
|
|
||||||
if [[ -z "$(which docker-machine)" ]]; then
|
|
||||||
openim::log::status "It looks like you're running Mac OS X, yet neither Docker for Mac nor docker-machine can be found."
|
|
||||||
openim::log::status "See: https://docs.docker.com/engine/installation/mac/ for installation instructions."
|
|
||||||
return 1
|
|
||||||
elif [[ -n "$(which docker-machine)" ]]; then
|
|
||||||
openim::build::prepare_docker_machine
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function openim::build::prepare_docker_machine() {
|
|
||||||
openim::log::status "docker-machine was found."
|
|
||||||
|
|
||||||
local available_memory_bytes
|
|
||||||
available_memory_bytes=$(sysctl -n hw.memsize 2>/dev/null)
|
|
||||||
|
|
||||||
local bytes_in_mb=1048576
|
|
||||||
|
|
||||||
# Give virtualbox 1/2 the system memory. Its necessary to divide by 2, instead
|
|
||||||
# of multiple by .5, because bash can only multiply by ints.
|
|
||||||
local memory_divisor=2
|
|
||||||
|
|
||||||
local virtualbox_memory_mb=$(( available_memory_bytes / (bytes_in_mb * memory_divisor) ))
|
|
||||||
|
|
||||||
docker-machine inspect "${DOCKER_MACHINE_NAME}" &> /dev/null || {
|
|
||||||
openim::log::status "Creating a machine to build OPENIM"
|
|
||||||
docker-machine create --driver "${DOCKER_MACHINE_DRIVER}" \
|
|
||||||
--virtualbox-memory "${virtualbox_memory_mb}" \
|
|
||||||
--engine-env HTTP_PROXY="${OPENIMRNETES_HTTP_PROXY:-}" \
|
|
||||||
--engine-env HTTPS_PROXY="${OPENIMRNETES_HTTPS_PROXY:-}" \
|
|
||||||
--engine-env NO_PROXY="${OPENIMRNETES_NO_PROXY:-127.0.0.1}" \
|
|
||||||
"${DOCKER_MACHINE_NAME}" > /dev/null || {
|
|
||||||
openim::log::error "Something went wrong creating a machine."
|
|
||||||
openim::log::error "Try the following: "
|
|
||||||
openim::log::error "docker-machine create -d ${DOCKER_MACHINE_DRIVER} --virtualbox-memory ${virtualbox_memory_mb} ${DOCKER_MACHINE_NAME}"
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
docker-machine start "${DOCKER_MACHINE_NAME}" &> /dev/null
|
|
||||||
# it takes `docker-machine env` a few seconds to work if the machine was just started
|
|
||||||
local docker_machine_out
|
|
||||||
while ! docker_machine_out=$(docker-machine env "${DOCKER_MACHINE_NAME}" 2>&1); do
|
|
||||||
if [[ ${docker_machine_out} =~ "Error checking TLS connection" ]]; then
|
|
||||||
echo "${docker_machine_out}"
|
|
||||||
docker-machine regenerate-certs "${DOCKER_MACHINE_NAME}"
|
|
||||||
else
|
|
||||||
sleep 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
eval "$(docker-machine env "${DOCKER_MACHINE_NAME}")"
|
|
||||||
openim::log::status "A Docker host using docker-machine named '${DOCKER_MACHINE_NAME}' is ready to go!"
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
function openim::build::is_gnu_sed() {
|
|
||||||
[[ $(sed --version 2>&1) == *GNU* ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
function openim::build::ensure_rsync() {
|
|
||||||
if [[ -z "$(which rsync)" ]]; then
|
|
||||||
openim::log::error "Can't find 'rsync' in PATH, please fix and retry."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function openim::build::update_dockerfile() {
|
|
||||||
if openim::build::is_gnu_sed; then
|
|
||||||
sed_opts=(-i)
|
|
||||||
else
|
|
||||||
sed_opts=(-i '')
|
|
||||||
fi
|
|
||||||
sed "${sed_opts[@]}" "s/OPENIM_BUILD_IMAGE_CROSS_TAG/${OPENIM_BUILD_IMAGE_CROSS_TAG}/" "${LOCAL_OUTPUT_BUILD_CONTEXT}/Dockerfile"
|
|
||||||
}
|
|
||||||
|
|
||||||
function openim::build::set_proxy() {
|
|
||||||
if [[ -n "${OPENIMRNETES_HTTPS_PROXY:-}" ]]; then
|
|
||||||
echo "ENV https_proxy $OPENIMRNETES_HTTPS_PROXY" >> "${LOCAL_OUTPUT_BUILD_CONTEXT}/Dockerfile"
|
|
||||||
fi
|
|
||||||
if [[ -n "${OPENIMRNETES_HTTP_PROXY:-}" ]]; then
|
|
||||||
echo "ENV http_proxy $OPENIMRNETES_HTTP_PROXY" >> "${LOCAL_OUTPUT_BUILD_CONTEXT}/Dockerfile"
|
|
||||||
fi
|
|
||||||
if [[ -n "${OPENIMRNETES_NO_PROXY:-}" ]]; then
|
|
||||||
echo "ENV no_proxy $OPENIMRNETES_NO_PROXY" >> "${LOCAL_OUTPUT_BUILD_CONTEXT}/Dockerfile"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function openim::build::ensure_docker_in_path() {
|
|
||||||
if [[ -z "$(which docker)" ]]; then
|
|
||||||
openim::log::error "Can't find 'docker' in PATH, please fix and retry."
|
|
||||||
openim::log::error "See https://docs.docker.com/installation/#installation for installation instructions."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function openim::build::ensure_tar() {
|
|
||||||
if [[ -n "${TAR:-}" ]]; then
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Find gnu tar if it is available, bomb out if not.
|
|
||||||
TAR=tar
|
|
||||||
if which gtar &>/dev/null; then
|
|
||||||
TAR=gtar
|
|
||||||
else
|
|
||||||
if which gnutar &>/dev/null; then
|
|
||||||
TAR=gnutar
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if ! "${TAR}" --version | grep -q GNU; then
|
|
||||||
echo " !!! Cannot find GNU tar. Build on Linux or install GNU tar"
|
|
||||||
echo " on Mac OS X (brew install gnu-tar)."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function openim::build::has_docker() {
|
|
||||||
which docker &> /dev/null
|
|
||||||
}
|
|
||||||
|
|
||||||
function openim::build::has_ip() {
|
|
||||||
which ip &> /dev/null && ip -Version | grep 'iproute2' &> /dev/null
|
|
||||||
}
|
|
||||||
|
|
||||||
# Detect if a specific image exists
|
|
||||||
#
|
|
||||||
# $1 - image repo name
|
|
||||||
# $2 - image tag
|
|
||||||
function openim::build::docker_image_exists() {
|
|
||||||
[[ -n $1 && -n $2 ]] || {
|
|
||||||
openim::log::error "Internal error. Image not specified in docker_image_exists."
|
|
||||||
exit 2
|
|
||||||
}
|
|
||||||
|
|
||||||
[[ $("${DOCKER[@]}" images -q "${1}:${2}") ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
# Delete all images that match a tag prefix except for the "current" version
|
|
||||||
#
|
|
||||||
# $1: The image repo/name
|
|
||||||
# $2: The tag base. We consider any image that matches $2*
|
|
||||||
# $3: The current image not to delete if provided
|
|
||||||
function openim::build::docker_delete_old_images() {
|
|
||||||
# In Docker 1.12, we can replace this with
|
|
||||||
# docker images "$1" --format "{{.Tag}}"
|
|
||||||
for tag in $("${DOCKER[@]}" images "${1}" | tail -n +2 | awk '{print $2}') ; do
|
|
||||||
if [[ "${tag}" != "${2}"* ]] ; then
|
|
||||||
V=3 openim::log::status "Keeping image ${1}:${tag}"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -z "${3:-}" || "${tag}" != "${3}" ]] ; then
|
|
||||||
V=2 openim::log::status "Deleting image ${1}:${tag}"
|
|
||||||
"${DOCKER[@]}" rmi "${1}:${tag}" >/dev/null
|
|
||||||
else
|
|
||||||
V=3 openim::log::status "Keeping image ${1}:${tag}"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# Stop and delete all containers that match a pattern
|
|
||||||
#
|
|
||||||
# $1: The base container prefix
|
|
||||||
# $2: The current container to keep, if provided
|
|
||||||
function openim::build::docker_delete_old_containers() {
|
|
||||||
# In Docker 1.12 we can replace this line with
|
|
||||||
# docker ps -a --format="{{.Names}}"
|
|
||||||
for container in $("${DOCKER[@]}" ps -a | tail -n +2 | awk '{print $NF}') ; do
|
|
||||||
if [[ "${container}" != "${1}"* ]] ; then
|
|
||||||
V=3 openim::log::status "Keeping container ${container}"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
if [[ -z "${2:-}" || "${container}" != "${2}" ]] ; then
|
|
||||||
V=2 openim::log::status "Deleting container ${container}"
|
|
||||||
openim::build::destroy_container "${container}"
|
|
||||||
else
|
|
||||||
V=3 openim::log::status "Keeping container ${container}"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# Takes $1 and computes a short has for it. Useful for unique tag generation
|
|
||||||
function openim::build::short_hash() {
|
|
||||||
[[ $# -eq 1 ]] || {
|
|
||||||
openim::log::error "Internal error. No data based to short_hash."
|
|
||||||
exit 2
|
|
||||||
}
|
|
||||||
|
|
||||||
local short_hash
|
|
||||||
if which md5 >/dev/null 2>&1; then
|
|
||||||
short_hash=$(md5 -q -s "$1")
|
|
||||||
else
|
|
||||||
short_hash=$(echo -n "$1" | md5sum)
|
|
||||||
fi
|
|
||||||
echo "${short_hash:0:10}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Pedantically kill, wait-on and remove a container. The -f -v options
|
|
||||||
# to rm don't actually seem to get the job done, so force kill the
|
|
||||||
# container, wait to ensure it's stopped, then try the remove. This is
|
|
||||||
# a workaround for bug https://github.com/docker/docker/issues/3968.
|
|
||||||
function openim::build::destroy_container() {
|
|
||||||
"${DOCKER[@]}" kill "$1" >/dev/null 2>&1 || true
|
|
||||||
if [[ $("${DOCKER[@]}" version --format '{{.Server.Version}}') = 17.06.0* ]]; then
|
|
||||||
# Workaround https://github.com/moby/moby/issues/33948.
|
|
||||||
# TODO: remove when 17.06.0 is not relevant anymore
|
|
||||||
DOCKER_API_VERSION=v1.29 "${DOCKER[@]}" wait "$1" >/dev/null 2>&1 || true
|
|
||||||
else
|
|
||||||
"${DOCKER[@]}" wait "$1" >/dev/null 2>&1 || true
|
|
||||||
fi
|
|
||||||
"${DOCKER[@]}" rm -f -v "$1" >/dev/null 2>&1 || true
|
|
||||||
}
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# Building
|
|
||||||
|
|
||||||
|
|
||||||
function openim::build::clean() {
|
|
||||||
if openim::build::has_docker ; then
|
|
||||||
openim::build::docker_delete_old_containers "${OPENIM_BUILD_CONTAINER_NAME_BASE}"
|
|
||||||
openim::build::docker_delete_old_containers "${OPENIM_RSYNC_CONTAINER_NAME_BASE}"
|
|
||||||
openim::build::docker_delete_old_containers "${OPENIM_DATA_CONTAINER_NAME_BASE}"
|
|
||||||
openim::build::docker_delete_old_images "${OPENIM_BUILD_IMAGE_REPO}" "${OPENIM_BUILD_IMAGE_TAG_BASE}"
|
|
||||||
|
|
||||||
V=2 openim::log::status "Cleaning all untagged docker images"
|
|
||||||
"${DOCKER[@]}" rmi "$("${DOCKER[@]}" images -q --filter 'dangling=true')" 2> /dev/null || true
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -d "${LOCAL_OUTPUT_ROOT}" ]]; then
|
|
||||||
openim::log::status "Removing _output directory"
|
|
||||||
rm -rf "${LOCAL_OUTPUT_ROOT}"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Set up the context directory for the openim-build image and build it.
|
|
||||||
function openim::build::build_image() {
|
|
||||||
mkdir -p "${LOCAL_OUTPUT_BUILD_CONTEXT}"
|
|
||||||
# Make sure the context directory owned by the right user for syncing sources to container.
|
|
||||||
chown -R "${USER_ID}":"${GROUP_ID}" "${LOCAL_OUTPUT_BUILD_CONTEXT}"
|
|
||||||
|
|
||||||
cp /etc/localtime "${LOCAL_OUTPUT_BUILD_CONTEXT}/"
|
|
||||||
|
|
||||||
cp "${OPENIM_ROOT}/build/build-image/Dockerfile" "${LOCAL_OUTPUT_BUILD_CONTEXT}/Dockerfile"
|
|
||||||
cp "${OPENIM_ROOT}/build/build-image/rsyncd.sh" "${LOCAL_OUTPUT_BUILD_CONTEXT}/"
|
|
||||||
dd if=/dev/urandom bs=512 count=1 2>/dev/null | LC_ALL=C tr -dc 'A-Za-z0-9' | dd bs=32 count=1 2>/dev/null > "${LOCAL_OUTPUT_BUILD_CONTEXT}/rsyncd.password"
|
|
||||||
chmod go= "${LOCAL_OUTPUT_BUILD_CONTEXT}/rsyncd.password"
|
|
||||||
|
|
||||||
openim::build::update_dockerfile
|
|
||||||
openim::build::set_proxy
|
|
||||||
openim::build::docker_build "${OPENIM_BUILD_IMAGE}" "${LOCAL_OUTPUT_BUILD_CONTEXT}" 'false'
|
|
||||||
|
|
||||||
# Clean up old versions of everything
|
|
||||||
openim::build::docker_delete_old_containers "${OPENIM_BUILD_CONTAINER_NAME_BASE}" "${OPENIM_BUILD_CONTAINER_NAME}"
|
|
||||||
openim::build::docker_delete_old_containers "${OPENIM_RSYNC_CONTAINER_NAME_BASE}" "${OPENIM_RSYNC_CONTAINER_NAME}"
|
|
||||||
openim::build::docker_delete_old_containers "${OPENIM_DATA_CONTAINER_NAME_BASE}" "${OPENIM_DATA_CONTAINER_NAME}"
|
|
||||||
openim::build::docker_delete_old_images "${OPENIM_BUILD_IMAGE_REPO}" "${OPENIM_BUILD_IMAGE_TAG_BASE}" "${OPENIM_BUILD_IMAGE_TAG}"
|
|
||||||
|
|
||||||
openim::build::ensure_data_container
|
|
||||||
openim::build::sync_to_container
|
|
||||||
}
|
|
||||||
|
|
||||||
# Build a docker image from a Dockerfile.
|
|
||||||
# $1 is the name of the image to build
|
|
||||||
# $2 is the location of the "context" directory, with the Dockerfile at the root.
|
|
||||||
# $3 is the value to set the --pull flag for docker build; true by default
|
|
||||||
function openim::build::docker_build() {
|
|
||||||
local -r image=$1
|
|
||||||
local -r context_dir=$2
|
|
||||||
local -r pull="${3:-true}"
|
|
||||||
local -ra build_cmd=("${DOCKER[@]}" build -t "${image}" "--pull=${pull}" "${context_dir}")
|
|
||||||
|
|
||||||
openim::log::status "Building Docker image ${image}"
|
|
||||||
local docker_output
|
|
||||||
docker_output=$("${build_cmd[@]}" 2>&1) || {
|
|
||||||
cat <<EOF >&2
|
|
||||||
+++ Docker build command failed for ${image}
|
|
||||||
|
|
||||||
${docker_output}
|
|
||||||
|
|
||||||
To retry manually, run:
|
|
||||||
|
|
||||||
${build_cmd[*]}
|
|
||||||
|
|
||||||
EOF
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function openim::build::ensure_data_container() {
|
|
||||||
# If the data container exists AND exited successfully, we can use it.
|
|
||||||
# Otherwise nuke it and start over.
|
|
||||||
local ret=0
|
|
||||||
local code=0
|
|
||||||
|
|
||||||
code=$(docker inspect \
|
|
||||||
-f '{{.State.ExitCode}}' \
|
|
||||||
"${OPENIM_DATA_CONTAINER_NAME}" 2>/dev/null) || ret=$?
|
|
||||||
if [[ "${ret}" == 0 && "${code}" != 0 ]]; then
|
|
||||||
openim::build::destroy_container "${OPENIM_DATA_CONTAINER_NAME}"
|
|
||||||
ret=1
|
|
||||||
fi
|
|
||||||
if [[ "${ret}" != 0 ]]; then
|
|
||||||
openim::log::status "Creating data container ${OPENIM_DATA_CONTAINER_NAME}"
|
|
||||||
# We have to ensure the directory exists, or else the docker run will
|
|
||||||
# create it as root.
|
|
||||||
mkdir -p "${LOCAL_OUTPUT_GOPATH}"
|
|
||||||
# We want this to run as root to be able to chown, so non-root users can
|
|
||||||
# later use the result as a data container. This run both creates the data
|
|
||||||
# container and chowns the GOPATH.
|
|
||||||
#
|
|
||||||
# The data container creates volumes for all of the directories that store
|
|
||||||
# intermediates for the Go build. This enables incremental builds across
|
|
||||||
# Docker sessions. The *_cgo paths are re-compiled versions of the go std
|
|
||||||
# libraries for true static building.
|
|
||||||
local -ra docker_cmd=(
|
|
||||||
"${DOCKER[@]}" run
|
|
||||||
--volume "${REMOTE_ROOT}" # white-out the whole output dir
|
|
||||||
--volume /usr/local/go/pkg/linux_386_cgo
|
|
||||||
--volume /usr/local/go/pkg/linux_amd64_cgo
|
|
||||||
--volume /usr/local/go/pkg/linux_arm_cgo
|
|
||||||
--volume /usr/local/go/pkg/linux_arm64_cgo
|
|
||||||
--volume /usr/local/go/pkg/linux_ppc64le_cgo
|
|
||||||
--volume /usr/local/go/pkg/darwin_amd64_cgo
|
|
||||||
--volume /usr/local/go/pkg/darwin_386_cgo
|
|
||||||
--volume /usr/local/go/pkg/windows_amd64_cgo
|
|
||||||
--volume /usr/local/go/pkg/windows_386_cgo
|
|
||||||
--name "${OPENIM_DATA_CONTAINER_NAME}"
|
|
||||||
--hostname "${HOSTNAME}"
|
|
||||||
"${OPENIM_BUILD_IMAGE}"
|
|
||||||
chown -R "${USER_ID}":"${GROUP_ID}"
|
|
||||||
"${REMOTE_ROOT}"
|
|
||||||
/usr/local/go/pkg/
|
|
||||||
)
|
|
||||||
"${docker_cmd[@]}"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Build all openim commands.
|
|
||||||
function openim::build::build_command() {
|
|
||||||
openim::log::status "Running build command..."
|
|
||||||
make -C "${OPENIM_ROOT}" multiarch
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
#!/usr/bin/env awk
|
|
||||||
|
|
||||||
{
|
|
||||||
print $0
|
|
||||||
if (match($0, /^total:/)) {
|
|
||||||
sub(/%/, "", $NF);
|
|
||||||
printf("test coverage is %s%(quality gate is %s%)\n", $NF, target)
|
|
||||||
if (strtonum($NF) < target) {
|
|
||||||
printf("test coverage does not meet expectations: %d%, please add test cases!\n", target)
|
|
||||||
exit 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
#!/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.
|
|
||||||
|
|
||||||
# http://stackoverflow.com/a/21142256/2055281
|
|
||||||
|
|
||||||
echo "mode: atomic" > coverage.txt
|
|
||||||
|
|
||||||
for d in $(find ./* -maxdepth 10 -type d); do
|
|
||||||
if ls $d/*.go &> /dev/null; then
|
|
||||||
go test -coverprofile=profile.out -covermode=atomic $d
|
|
||||||
if [ -f profile.out ]; then
|
|
||||||
cat profile.out | grep -v "mode: " >> /tmp/coverage.txt
|
|
||||||
rm profile.out
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
@ -1,26 +0,0 @@
|
|||||||
#!/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.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#fixme This scripts is the total startup scripts
|
|
||||||
#fixme The full name of the shell scripts that needs to be started is placed in the need_to_start_server_shell array
|
|
||||||
|
|
||||||
cd /openim/openim-server
|
|
||||||
mage start
|
|
||||||
tail -f /dev/null
|
|
@ -1,26 +0,0 @@
|
|||||||
#!/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.
|
|
||||||
|
|
||||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
|
||||||
|
|
||||||
version="${VERSION}"
|
|
||||||
if [ "${version}" == "" ];then
|
|
||||||
version=v$(${OPENIM_ROOT}/_output/tools/gsemver bump)
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$(git tag -l ${version})" ];then
|
|
||||||
git tag -a -m "release version ${version}" ${version}
|
|
||||||
fi
|
|
@ -1,73 +0,0 @@
|
|||||||
#!/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.
|
|
||||||
|
|
||||||
# Script to generate docs from the latest swagger spec.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# The root of the build/dist directory
|
|
||||||
OPENIM_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
|
|
||||||
source "${OPENIM_ROOT}"/scripts/lib/util.sh
|
|
||||||
|
|
||||||
mkdir -p ${OPENIM_OUTPUT_TMP}
|
|
||||||
cd ${OPENIM_OUTPUT_TMP}
|
|
||||||
|
|
||||||
# gendocs takes "input.json" as the input swagger spec.
|
|
||||||
# $1 is expected to be <group>_<version>
|
|
||||||
cp ${OPENIM_OUTPUT_TMP}/swagger-source/"$1".json ${OPENIM_OUTPUT_TMP}/input.json
|
|
||||||
|
|
||||||
./gradle-2.5/bin/gradle gendocs --info
|
|
||||||
|
|
||||||
#insert a TOC for top level API objects
|
|
||||||
buf="== Top Level API Objects\n\n"
|
|
||||||
top_level_models=$(grep '&[A-Za-z]*{},' /register.go | sed 's/.*&//;s/{},//')
|
|
||||||
|
|
||||||
# check if the top level models exist in the definitions.adoc. If they exist,
|
|
||||||
# their name will be <version>.<model_name>
|
|
||||||
VERSION="${1#*_}"
|
|
||||||
for m in ${top_level_models}
|
|
||||||
do
|
|
||||||
if grep -xq "=== ${VERSION}.${m}" ./definitions.adoc
|
|
||||||
then
|
|
||||||
buf+="* <<${VERSION}.${m}>>\n"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
sed -i "1i ${buf}" ./definitions.adoc
|
|
||||||
|
|
||||||
# fix the links in .adoc, replace <<x.y>> with link:definitions.html#_x_y[x.y], and lowercase the _x_y part
|
|
||||||
sed -i -e 's|<<\(.*\)\.\(.*\)>>|link:#_\L\1_\2\E[\1.\2]|g' ./definitions.adoc
|
|
||||||
sed -i -e 's|<<\(.*\)\.\(.*\)>>|link:../definitions#_\L\1_\2\E[\1.\2]|g' ./paths.adoc
|
|
||||||
|
|
||||||
# fix the link to <<any>>
|
|
||||||
sed -i -e 's|<<any>>|link:#_any[any]|g' ./definitions.adoc
|
|
||||||
sed -i -e 's|<<any>>|link:../definitions#_any[any]|g' ./paths.adoc
|
|
||||||
|
|
||||||
# change the title of paths.adoc from "paths" to "operations"
|
|
||||||
sed -i 's|== Paths|== Operations|g' ./paths.adoc
|
|
||||||
|
|
||||||
# $$ has special meaning in asciidoc, we need to escape it
|
|
||||||
sed -i 's|\$\$|+++$$+++|g' ./definitions.adoc
|
|
||||||
|
|
||||||
echo -e "=== any\nRepresents an untyped JSON map - see the description of the field for more info about the structure of this object." >> ./definitions.adoc
|
|
||||||
|
|
||||||
asciidoctor definitions.adoc
|
|
||||||
asciidoctor paths.adoc
|
|
||||||
|
|
||||||
cp "$OPENIM_OUTPUT_TMP/definitions.html" "$OPENIM_OUTPUT_TMP/_output/"
|
|
||||||
cp "$OPENIM_OUTPUT_TMP/paths.html" "$OPENIM_OUTPUT_TMP/_output/operations.html"
|
|
||||||
|
|
||||||
success "SUCCESS"
|
|
@ -1,84 +0,0 @@
|
|||||||
#!/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.
|
|
||||||
|
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
DEFAULT_DIRS=("pkg")
|
|
||||||
BASE_URL="github.com/openimsdk/open-im-server/v3"
|
|
||||||
REMOVE_DOC=false
|
|
||||||
|
|
||||||
usage() {
|
|
||||||
echo "Usage: $0 [OPTIONS]"
|
|
||||||
echo
|
|
||||||
echo "This script iterates over directories. By default, it generates doc.go files for 'pkg' and 'internal/pkg'."
|
|
||||||
echo
|
|
||||||
echo "Options:"
|
|
||||||
echo " -d DIRS, --dirs DIRS Specify directories to process, separated by commas (e.g., 'pkg,internal/pkg')."
|
|
||||||
echo " -u URL, --url URL Set the base URL for the import path. Default is '$BASE_URL'."
|
|
||||||
echo " -r, --remove Remove all doc.go files in the specified directories."
|
|
||||||
echo " -h, --help Show this help message."
|
|
||||||
echo
|
|
||||||
}
|
|
||||||
|
|
||||||
process_dir() {
|
|
||||||
local dir="$1"
|
|
||||||
local base_url="$2"
|
|
||||||
local remove_doc="$3"
|
|
||||||
|
|
||||||
find "$dir" -type d | while read -r d; do
|
|
||||||
if [ "$remove_doc" = true ]; then
|
|
||||||
if [ -f "$d/doc.go" ]; then
|
|
||||||
echo "Removing $d/doc.go"
|
|
||||||
rm -f "$d/doc.go"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
if [ ! -f "$d/doc.go" ] && ls "$d/"*.go &>/dev/null; then
|
|
||||||
echo "Creating $d/doc.go"
|
|
||||||
echo "package $(basename "$d") // import \"$base_url/$(echo "$d" | sed "s|^\./||")\"" >"$d/doc.go"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
|
||||||
case "$1" in
|
|
||||||
-d|--dirs)
|
|
||||||
IFS=',' read -ra DIRS <<< "$2"
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
-u|--url)
|
|
||||||
BASE_URL="$2"
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
-r|--remove)
|
|
||||||
REMOVE_DOC=true
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
-h|--help)
|
|
||||||
usage
|
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
usage
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
DIRS=(${DIRS:-"${DEFAULT_DIRS[@]}"})
|
|
||||||
|
|
||||||
for dir in "${DIRS[@]}"; do
|
|
||||||
process_dir "$dir" "$BASE_URL" "$REMOVE_DOC"
|
|
||||||
done
|
|
@ -1,265 +0,0 @@
|
|||||||
#!/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 automatically initializes various configuration files and can generate example files.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Root directory of the OpenIM project
|
|
||||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
|
||||||
|
|
||||||
# Source initialization script
|
|
||||||
source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
|
||||||
|
|
||||||
# Default environment file
|
|
||||||
readonly ENV_FILE=${ENV_FILE:-"${OPENIM_ROOT}/scripts/install/environment.sh"}
|
|
||||||
|
|
||||||
# Templates for configuration files
|
|
||||||
declare -A TEMPLATES=(
|
|
||||||
["${OPENIM_ROOT}/deployments/templates/env-template.yaml"]="${OPENIM_ROOT}/.env"
|
|
||||||
["${OPENIM_ROOT}/deployments/templates/config.yaml"]="${OPENIM_ROOT}/config/config.yaml"
|
|
||||||
["${OPENIM_ROOT}/deployments/templates/prometheus.yml"]="${OPENIM_ROOT}/config/prometheus.yml"
|
|
||||||
["${OPENIM_ROOT}/deployments/templates/alertmanager.yml"]="${OPENIM_ROOT}/config/alertmanager.yml"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Templates for example files
|
|
||||||
declare -A EXAMPLES=(
|
|
||||||
["${OPENIM_ROOT}/deployments/templates/env-template.yaml"]="${OPENIM_ROOT}/config/templates/env.template"
|
|
||||||
["${OPENIM_ROOT}/deployments/templates/config.yaml"]="${OPENIM_ROOT}/config/templates/config.yaml.template"
|
|
||||||
["${OPENIM_ROOT}/deployments/templates/prometheus.yml"]="${OPENIM_ROOT}/config/templates/prometheus.yml.template"
|
|
||||||
["${OPENIM_ROOT}/deployments/templates/alertmanager.yml"]="${OPENIM_ROOT}/config/templates/alertmanager.yml.template"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Templates for config Copy file
|
|
||||||
declare -A COPY_TEMPLATES=(
|
|
||||||
["${OPENIM_ROOT}/deployments/templates/email.tmpl"]="${OPENIM_ROOT}/config/email.tmpl"
|
|
||||||
["${OPENIM_ROOT}/deployments/templates/instance-down-rules.yml"]="${OPENIM_ROOT}/config/instance-down-rules.yml"
|
|
||||||
["${OPENIM_ROOT}/deployments/templates/notification.yaml"]="${OPENIM_ROOT}/config/notification.yaml"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Templates for config Copy file
|
|
||||||
declare -A COPY_EXAMPLES=(
|
|
||||||
["${OPENIM_ROOT}/deployments/templates/email.tmpl"]="${OPENIM_ROOT}/config/templates/email.tmpl.template"
|
|
||||||
["${OPENIM_ROOT}/deployments/templates/instance-down-rules.yml"]="${OPENIM_ROOT}/config/templates/instance-down-rules.yml.template"
|
|
||||||
["${OPENIM_ROOT}/deployments/templates/notification.yaml"]="${OPENIM_ROOT}/config/templates/notification.yaml.template"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Command-line options
|
|
||||||
FORCE_OVERWRITE=false
|
|
||||||
SKIP_EXISTING=false
|
|
||||||
GENERATE_EXAMPLES=false
|
|
||||||
CLEAN_CONFIG=false
|
|
||||||
CLEAN_EXAMPLES=false
|
|
||||||
|
|
||||||
FILES_PROCESSED=false
|
|
||||||
|
|
||||||
# Function to display help information
|
|
||||||
show_help() {
|
|
||||||
echo "Usage: $(basename "$0") [options]"
|
|
||||||
echo "Options:"
|
|
||||||
echo " -h, --help Show this help message"
|
|
||||||
echo " --force Overwrite existing files without prompt"
|
|
||||||
echo " --skip Skip generation if file exists"
|
|
||||||
echo " --examples Generate example files"
|
|
||||||
echo " --clean-config Clean all configuration files"
|
|
||||||
echo " --clean-examples Clean all example files"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Function to generate and copy configuration files
|
|
||||||
generate_config_files() {
|
|
||||||
# Handle TEMPLATES array
|
|
||||||
for template in "${!TEMPLATES[@]}"; do
|
|
||||||
local output_file="${TEMPLATES[$template]}"
|
|
||||||
process_file "$template" "$output_file" true
|
|
||||||
done
|
|
||||||
|
|
||||||
# Handle COPY_TEMPLATES array
|
|
||||||
for template in "${!COPY_TEMPLATES[@]}"; do
|
|
||||||
local output_file="${COPY_TEMPLATES[$template]}"
|
|
||||||
process_file "$template" "$output_file" false
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# Function to generate example files
|
|
||||||
generate_example_files() {
|
|
||||||
env_cmd="env -i"
|
|
||||||
|
|
||||||
env_vars["OPENIM_IP"]="127.0.0.1"
|
|
||||||
env_vars["LOG_STORAGE_LOCATION"]="../../"
|
|
||||||
|
|
||||||
for var in "${!env_vars[@]}"; do
|
|
||||||
env_cmd+=" $var='${env_vars[$var]}'"
|
|
||||||
done
|
|
||||||
|
|
||||||
# Processing EXAMPLES array
|
|
||||||
for template in "${!EXAMPLES[@]}"; do
|
|
||||||
local example_file="${EXAMPLES[$template]}"
|
|
||||||
process_file "$template" "$example_file" true
|
|
||||||
done
|
|
||||||
|
|
||||||
# Processing COPY_EXAMPLES array
|
|
||||||
for template in "${!COPY_EXAMPLES[@]}"; do
|
|
||||||
local example_file="${COPY_EXAMPLES[$template]}"
|
|
||||||
process_file "$template" "$example_file" false
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# Function to process a single file, either by generating or copying
|
|
||||||
process_file() {
|
|
||||||
local template=$1
|
|
||||||
local output_file=$2
|
|
||||||
local use_genconfig=$3
|
|
||||||
|
|
||||||
if [[ -f "${output_file}" ]]; then
|
|
||||||
if [[ "${FORCE_OVERWRITE}" == true ]]; then
|
|
||||||
openim::log::info "Force overwriting ${output_file}."
|
|
||||||
elif [[ "${SKIP_EXISTING}" == true ]]; then
|
|
||||||
#openim::log::info "Skipping generation of ${output_file} as it already exists."
|
|
||||||
return
|
|
||||||
else
|
|
||||||
echo -n "File ${output_file} already exists. Overwrite? (Y/N): "
|
|
||||||
read -r -n 1 REPLY
|
|
||||||
echo
|
|
||||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
|
||||||
openim::log::info "Skipping generation of ${output_file}."
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
if [[ "${SKIP_EXISTING}" == true ]]; then
|
|
||||||
openim::log::info "Generating ${output_file} as it does not exist."
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "$use_genconfig" == true ]]; then
|
|
||||||
openim::log::info "⌚ Working with template file: ${template} to generate ${output_file}..."
|
|
||||||
if [[ ! -f "${OPENIM_ROOT}/scripts/genconfig.sh" ]]; then
|
|
||||||
openim::log::error "genconfig.sh script not found"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
if [[ -n "${env_cmd}" ]]; then
|
|
||||||
|
|
||||||
{
|
|
||||||
printf "debugggggggggggggggggggg file: %s template: %s\n" "${ENV_FILE}" "${template}"
|
|
||||||
} | tee /tmp/debug.log
|
|
||||||
|
|
||||||
|
|
||||||
eval "$env_cmd ${OPENIM_ROOT}/scripts/genconfig.sh '${ENV_FILE}' '${template}' > '${output_file}'" || {
|
|
||||||
openim::log::error "Error processing template file ${template}"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
else
|
|
||||||
"${OPENIM_ROOT}/scripts/genconfig.sh" "${ENV_FILE}" "${template}" > "${output_file}" || {
|
|
||||||
openim::log::error "Error processing template file ${template}"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
openim::log::info "📋 Copying ${template} to ${output_file}..."
|
|
||||||
cp "${template}" "${output_file}" || {
|
|
||||||
openim::log::error "Error copying template file ${template}"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
FILES_PROCESSED=true
|
|
||||||
}
|
|
||||||
|
|
||||||
clean_config_files() {
|
|
||||||
local all_templates=("${TEMPLATES[@]}" "${COPY_TEMPLATES[@]}")
|
|
||||||
|
|
||||||
for output_file in "${all_templates[@]}"; do
|
|
||||||
if [[ -f "${output_file}" ]]; then
|
|
||||||
rm -f "${output_file}"
|
|
||||||
openim::log::info "Removed configuration file: ${output_file}"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# Function to clean example files
|
|
||||||
clean_example_files() {
|
|
||||||
local all_examples=("${EXAMPLES[@]}" "${COPY_EXAMPLES[@]}")
|
|
||||||
|
|
||||||
for example_file in "${all_examples[@]}"; do
|
|
||||||
if [[ -f "${example_file}" ]]; then
|
|
||||||
rm -f "${example_file}"
|
|
||||||
openim::log::info "Removed example file: ${example_file}"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
|
||||||
case "$1" in
|
|
||||||
-h|--help)
|
|
||||||
show_help
|
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
--force)
|
|
||||||
FORCE_OVERWRITE=true
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
--skip)
|
|
||||||
SKIP_EXISTING=true
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
--examples)
|
|
||||||
GENERATE_EXAMPLES=true
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
--clean-config)
|
|
||||||
CLEAN_CONFIG=true
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
--clean-examples)
|
|
||||||
CLEAN_EXAMPLES=true
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Unknown option: $1"
|
|
||||||
show_help
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
# Clean configuration files if --clean-config option is provided
|
|
||||||
if [[ "${CLEAN_CONFIG}" == true ]]; then
|
|
||||||
clean_config_files
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Clean example files if --clean-examples option is provided
|
|
||||||
if [[ "${CLEAN_EXAMPLES}" == true ]]; then
|
|
||||||
clean_example_files
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Generate configuration files if requested
|
|
||||||
if [[ "${FORCE_OVERWRITE}" == true || "${SKIP_EXISTING}" == false ]] && [[ "${CLEAN_CONFIG}" == false ]]; then
|
|
||||||
generate_config_files
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Generate configuration files if requested
|
|
||||||
if [[ "${SKIP_EXISTING}" == true ]]; then
|
|
||||||
generate_config_files
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Generate example files if --examples option is provided
|
|
||||||
if [[ "${GENERATE_EXAMPLES}" == true ]] && [[ "${CLEAN_EXAMPLES}" == false ]]; then
|
|
||||||
generate_example_files
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "${FILES_PROCESSED}" == true ]]; then
|
|
||||||
openim::log::success "Configuration and example files operation complete!"
|
|
||||||
fi
|
|
@ -1,33 +0,0 @@
|
|||||||
#!/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.
|
|
||||||
|
|
||||||
#FIXME This script is the startup script for multiple servers.
|
|
||||||
#FIXME The full names of the shell scripts that need to be started are placed in the `need_to_start_server_shell` array.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd -P)
|
|
||||||
source "${OPENIM_ROOT}/scripts/install/common.sh"
|
|
||||||
|
|
||||||
openim::log::info "\n# Begin Install OpenIM Config"
|
|
||||||
|
|
||||||
for file in "${OPENIM_SERVER_TARGETS[@]}"; do
|
|
||||||
VARNAME="$(echo $file | tr '[:lower:]' '[:upper:]' | tr '.' '_' | tr '-' '_')"
|
|
||||||
VARVALUE="$OPENIM_OUTPUT_HOSTBIN/$file"
|
|
||||||
# /etc/profile.d/openim-env.sh
|
|
||||||
echo "export $VARNAME=$VARVALUE" > /etc/profile.d/openim-env.sh
|
|
||||||
source /etc/profile.d/openim-env.sh
|
|
||||||
done
|
|
@ -1,100 +0,0 @@
|
|||||||
#!/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.
|
|
||||||
#
|
|
||||||
# -----------------------------------------------------------------------------
|
|
||||||
# init-githooks.sh
|
|
||||||
#
|
|
||||||
# This script assists in managing Git hooks for the OpenIM project.
|
|
||||||
# When executed:
|
|
||||||
# 1. It prompts the user to enable git hooks.
|
|
||||||
# 2. If the user accepts, it copies predefined hook scripts to the appropriate
|
|
||||||
# Git directory, making them executable.
|
|
||||||
# 3. If requested, it can delete the added hooks.
|
|
||||||
#
|
|
||||||
# This script equal runs `make init-githooks` command.
|
|
||||||
# Usage:
|
|
||||||
# ./init-githooks.sh Prompt to enable git hooks.
|
|
||||||
# ./init-githooks.sh --delete Delete previously added git hooks.
|
|
||||||
# ./init-githooks.sh --help Show the help message.
|
|
||||||
#
|
|
||||||
# Example: `scripts/build-go.sh --help`.
|
|
||||||
# Documentation & related context can be found at:
|
|
||||||
# https://gist.github.com/cubxxw/126b72104ac0b0ca484c9db09c3e5694
|
|
||||||
#
|
|
||||||
# -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
|
||||||
HOOKS_DIR="${OPENIM_ROOT}/.git/hooks"
|
|
||||||
|
|
||||||
help_info() {
|
|
||||||
echo "Usage: $0 [options]"
|
|
||||||
echo
|
|
||||||
echo "This script helps to manage git hooks."
|
|
||||||
echo
|
|
||||||
echo "Options:"
|
|
||||||
echo " -h, --help Show this help message and exit."
|
|
||||||
echo " -d, --delete Delete the hooks that have been added."
|
|
||||||
echo " By default, it will prompt to enable git hooks."
|
|
||||||
}
|
|
||||||
|
|
||||||
delete_hooks() {
|
|
||||||
for file in "${OPENIM_ROOT}"/scripts/githooks/*.sh; do
|
|
||||||
hook_name=$(basename "$file" .sh) # This removes the .sh extension
|
|
||||||
rm -f "$HOOKS_DIR/$hook_name"
|
|
||||||
done
|
|
||||||
echo "Git hooks have been deleted."
|
|
||||||
}
|
|
||||||
|
|
||||||
enable_hooks() {
|
|
||||||
echo "Would you like to:"
|
|
||||||
echo "1) Enable git hooks mode"
|
|
||||||
echo "2) Delete existing git hooks"
|
|
||||||
echo "Please select a number (or any other key to exit):"
|
|
||||||
read -r choice
|
|
||||||
|
|
||||||
case "$choice" in
|
|
||||||
1)
|
|
||||||
for file in ${OPENIM_ROOT}/scripts/githooks/*.sh; do
|
|
||||||
hook_name=$(basename "$file" .sh) # This removes the .sh extension
|
|
||||||
cp -f "$file" "$HOOKS_DIR/$hook_name"
|
|
||||||
done
|
|
||||||
|
|
||||||
chmod +x $HOOKS_DIR/*
|
|
||||||
|
|
||||||
echo "Git hooks mode has been enabled."
|
|
||||||
echo "With git hooks enabled, every time you perform a git action (e.g. git commit), the corresponding hooks script will be triggered automatically."
|
|
||||||
echo "This means that if the size of the file you're committing exceeds the set limit (e.g. 42MB), the commit will be rejected."
|
|
||||||
;;
|
|
||||||
2)
|
|
||||||
delete_hooks
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Exiting without making changes."
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
case "$1" in
|
|
||||||
-h|--help)
|
|
||||||
help_info
|
|
||||||
;;
|
|
||||||
-d|--delete)
|
|
||||||
delete_hooks
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
enable_hooks
|
|
||||||
;;
|
|
||||||
esac
|
|
@ -1,86 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
# Copyright © 2024 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.
|
|
||||||
|
|
||||||
#
|
|
||||||
# OpenIM Docker Deployment Script
|
|
||||||
#
|
|
||||||
# This script automates the process of building the OpenIM server image
|
|
||||||
# and deploying it using Docker Compose.
|
|
||||||
#
|
|
||||||
# Variables:
|
|
||||||
# - SERVER_IMAGE_VERSION: Version of the server image (default: test)
|
|
||||||
# - IMAGE_REGISTRY: Docker image registry (default: openim)
|
|
||||||
# - DOCKER_COMPOSE_FILE_URL: URL to the docker-compose.yml file
|
|
||||||
#
|
|
||||||
# Usage:
|
|
||||||
# SERVER_IMAGE_VERSION=latest IMAGE_REGISTRY=myregistry ./this_script.sh
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
|
||||||
source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
|
||||||
|
|
||||||
trap 'openim::util::onCtrlC' INT
|
|
||||||
|
|
||||||
chmod +x "${OPENIM_ROOT}"/scripts/*.sh
|
|
||||||
|
|
||||||
openim::util::ensure_docker_daemon_connectivity
|
|
||||||
|
|
||||||
# Default values for variables
|
|
||||||
: ${SERVER_IMAGE_VERSION:=test}
|
|
||||||
: ${IMAGE_REGISTRY:=openim}
|
|
||||||
: ${DOCKER_COMPOSE_FILE_URL:="https://raw.githubusercontent.com/openimsdk/openim-docker/main/docker-compose.yaml"}
|
|
||||||
|
|
||||||
DOCKER_COMPOSE_COMMAND=
|
|
||||||
# Check if docker-compose command is available
|
|
||||||
openim::util::check_docker_and_compose_versions
|
|
||||||
if command -v docker compose &> /dev/null; then
|
|
||||||
openim::log::info "docker compose command is available"
|
|
||||||
DOCKER_COMPOSE_COMMAND="docker compose"
|
|
||||||
else
|
|
||||||
DOCKER_COMPOSE_COMMAND="docker-compose"
|
|
||||||
fi
|
|
||||||
|
|
||||||
export SERVER_IMAGE_VERSION
|
|
||||||
export IMAGE_REGISTRY
|
|
||||||
"${OPENIM_ROOT}"/scripts/init-config.sh
|
|
||||||
|
|
||||||
pushd "${OPENIM_ROOT}"
|
|
||||||
docker build -t "${IMAGE_REGISTRY}/openim-server:${SERVER_IMAGE_VERSION}" .
|
|
||||||
${DOCKER_COMPOSE_COMMAND} stop
|
|
||||||
curl "${DOCKER_COMPOSE_FILE_URL}" -o docker-compose.yml
|
|
||||||
${DOCKER_COMPOSE_COMMAND} up -d
|
|
||||||
|
|
||||||
# Function to check container status
|
|
||||||
check_containers() {
|
|
||||||
if ! ${DOCKER_COMPOSE_COMMAND} ps | grep -q 'Up'; then
|
|
||||||
echo "Error: One or more docker containers failed to start."
|
|
||||||
${DOCKER_COMPOSE_COMMAND} logs openim-server
|
|
||||||
${DOCKER_COMPOSE_COMMAND} logs openim-chat
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
# Wait for a short period to allow containers to initialize
|
|
||||||
sleep 100
|
|
||||||
|
|
||||||
${DOCKER_COMPOSE_COMMAND} ps
|
|
||||||
|
|
||||||
check_containers
|
|
||||||
|
|
||||||
popd
|
|
@ -1,116 +0,0 @@
|
|||||||
# OpenIM Suite Scripts
|
|
||||||
|
|
||||||
The OpenIM Suite represents a comprehensive collection of scripts, each tailored to manage and operate specific services within the OpenIM ecosystem. These scripts offer consistent, reliable, and efficient tools for initializing, controlling, and managing various OpenIM services on a Linux platform.
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
- **Robustness:** Built with Bash's error handling mechanisms (`errexit`, `nounset`, and `pipefail`), ensuring scripts fail fast and provide relevant error messages.
|
|
||||||
- **Modularity:** Each script is dedicated to a particular service, promoting clarity and ease of maintenance.
|
|
||||||
- **Comprehensive Logging:** Integrated logging utilities offer real-time insights into operations, enhancing transparency and debuggability.
|
|
||||||
- **Systemd Integration:** Where applicable, scripts integrate with the systemd service manager, offering standardized service controls like start, stop, restart, and status checks.
|
|
||||||
|
|
||||||
## Scripts Overview
|
|
||||||
|
|
||||||
1. **openim-api:** Control interface for the OpenIM API service.
|
|
||||||
2. **openim-cmdutils:** Utility toolkit for common OpenIM command-line operations.
|
|
||||||
3. **openim-crontask:** Manages the OpenIM CronTask service, with both direct and systemctl installation methods.
|
|
||||||
4. **openim-msggateway:** Script to operate the OpenIM Message Gateway service.
|
|
||||||
5. **openim-msgtransfer:** Manages the OpenIM Message Transfer functionalities.
|
|
||||||
6. **openim-push:** Interface for controlling the OpenIM Push Notification service.
|
|
||||||
7. **openim-rpc-auth:** Script dedicated to the OpenIM RPC Authentication service.
|
|
||||||
8. **openim-rpc-conversation:** Manages operations related to the OpenIM RPC Conversation service.
|
|
||||||
9. **openim-rpc-friend:** Control interface for the OpenIM RPC Friend functionalities.
|
|
||||||
10. **openim-rpc-group:** Script for managing the OpenIM RPC Group service.
|
|
||||||
11. **openim-rpc-msg:** Operates the OpenIM RPC Messaging service.
|
|
||||||
12. **openim-rpc-third:** Script dedicated to third-party integrations with OpenIM RPC.
|
|
||||||
13. **openim-rpc-user:** Control interface for OpenIM RPC User operations.
|
|
||||||
|
|
||||||
## OpenIM Server Installation Script Usage
|
|
||||||
|
|
||||||
The scripts within the OpenIM Suite generally adhere to two primary execution methodologies. To illustrate these methodologies, we'll use `openim-crontask` as a representative example.
|
|
||||||
|
|
||||||
1. **Direct Script Execution:** Running the script directly, typically for straightforward start/stop operations.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
./[script-name].sh
|
|
||||||
```
|
|
||||||
|
|
||||||
2. **Function-based Execution:** Invoking specific functions within the script for more specialized operations (e.g., install, uninstall).
|
|
||||||
|
|
||||||
```bash
|
|
||||||
./scripts/install/install.sh [options]
|
|
||||||
```
|
|
||||||
|
|
||||||
**Description:**
|
|
||||||
This script is designed to handle the installation, uninstallation, and status checking of OpenIM components on the server. OpenIM is a presumed communication or messaging platform.
|
|
||||||
|
|
||||||
### Commands:
|
|
||||||
- **-i, --install**:
|
|
||||||
Initiate the installation of all OpenIM components.
|
|
||||||
|
|
||||||
- **-u, --uninstall**:
|
|
||||||
Uninstall or remove all OpenIM components from the server.
|
|
||||||
|
|
||||||
- **-s, --status**:
|
|
||||||
Check and report the current operational status of the installed OpenIM components.
|
|
||||||
|
|
||||||
- **-h, --help**:
|
|
||||||
Display the help menu for available commands.
|
|
||||||
|
|
||||||
### Example Usage:
|
|
||||||
To install all OpenIM components:
|
|
||||||
```bash
|
|
||||||
./scripts/install/install.sh -i
|
|
||||||
```
|
|
||||||
or
|
|
||||||
```bash
|
|
||||||
./scripts/install/install.sh --install
|
|
||||||
```
|
|
||||||
> **Note**:
|
|
||||||
> Ensure you have the necessary privileges to execute installation or uninstallation operations. It's generally recommended to take a backup before making major changes.
|
|
||||||
|
|
||||||
|
|
||||||
### 1. Direct Script Execution
|
|
||||||
|
|
||||||
This method involves invoking the script directly, initiating its default behavior. For instance, with `openim-crontask`, direct execution will start the OpenIM CronTask as a background process.
|
|
||||||
|
|
||||||
**Example:**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
./openim-crontask.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
Upon execution, the script will source any necessary configurations, log the start of the CronTask, and finally run the CronTask in the background. The log messages will provide feedback about the process, ensuring the user is informed of the task's progress.
|
|
||||||
|
|
||||||
### 2. Function-based Execution
|
|
||||||
|
|
||||||
This approach is more specialized, enabling users to call specific functions defined within the script. This is particularly useful for tasks like installation, uninstallation, and status checks.
|
|
||||||
|
|
||||||
For the `openim-crontask` script:
|
|
||||||
|
|
||||||
- **Installation**: It includes building the service, generating configuration files, setting up systemd services, and starting the service.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
./openim-crontask.sh openim::crontask::install
|
|
||||||
```
|
|
||||||
|
|
||||||
- **Uninstallation**: Stops the service, removes associated binaries, configuration files, and systemd service files.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
./openim-crontask.sh openim::crontask::uninstall
|
|
||||||
```
|
|
||||||
|
|
||||||
- **Status Check**: Verifies the running status of the service, checking for active processes and listening ports.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
./openim-crontask.sh openim::crontask::status
|
|
||||||
```
|
|
||||||
|
|
||||||
It's crucial to familiarize oneself with the available functions within each script. This ensures optimal utilization of the provided tools and a deeper understanding of the underlying operations.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
- Always ensure you have the correct permissions before executing any script.
|
|
||||||
- Environment variables may need to be set or sourced depending on your installation and configuration.
|
|
@ -1,155 +0,0 @@
|
|||||||
#!/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.
|
|
||||||
|
|
||||||
|
|
||||||
# Common utilities, variables and checks for all build scripts.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Sourced flag
|
|
||||||
COMMON_SOURCED=true
|
|
||||||
# The root of the build/dist directory
|
|
||||||
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
|
|
||||||
source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
|
||||||
# Make sure the environment is only called via common to avoid too much nesting
|
|
||||||
source "${OPENIM_ROOT}/scripts/install/environment.sh"
|
|
||||||
|
|
||||||
# This function returns a list of Prometheus ports for various services
|
|
||||||
# based on the provided configuration. Each service has its own dedicated
|
|
||||||
# port for monitoring purposes.
|
|
||||||
openim::common::prometheus_port() {
|
|
||||||
# Declare an array to hold all the Prometheus ports for different services
|
|
||||||
local targets=(
|
|
||||||
${USER_PROM_PORT} # Prometheus port for user service
|
|
||||||
${FRIEND_PROM_PORT} # Prometheus port for friend service
|
|
||||||
${MESSAGE_PROM_PORT} # Prometheus port for message service
|
|
||||||
${MSG_GATEWAY_PROM_PORT} # Prometheus port for message gateway service
|
|
||||||
${GROUP_PROM_PORT} # Prometheus port for group service
|
|
||||||
${AUTH_PROM_PORT} # Prometheus port for authentication service
|
|
||||||
${PUSH_PROM_PORT} # Prometheus port for push notification service
|
|
||||||
${CONVERSATION_PROM_PORT} # Prometheus port for conversation service
|
|
||||||
${RTC_PROM_PORT} # Prometheus port for real-time communication service
|
|
||||||
${THIRD_PROM_PORT} # Prometheus port for third-party integrations service
|
|
||||||
${MSG_TRANSFER_PROM_PORT} # Prometheus port for message transfer service
|
|
||||||
)
|
|
||||||
# Print the list of ports
|
|
||||||
echo "${targets[@]}"
|
|
||||||
}
|
|
||||||
IFS=" " read -ra OPENIM_PROM_PORT_TARGETS <<< "$(openim::common::prometheus_port)"
|
|
||||||
readonly OPENIM_PROM_PORT_TARGETS
|
|
||||||
readonly OPENIM_PROM_PORT_LISTARIES=("${OPENIM_PROM_PORT_TARGETS[@]##*/}")
|
|
||||||
|
|
||||||
openim::common::service_name() {
|
|
||||||
local targets=(
|
|
||||||
openim-user
|
|
||||||
openim-friend
|
|
||||||
openim-msg
|
|
||||||
openim-msg-gateway
|
|
||||||
openim-group
|
|
||||||
openim-auth
|
|
||||||
openim-push
|
|
||||||
openim-conversation
|
|
||||||
openim-third
|
|
||||||
# openim-msg-transfer
|
|
||||||
|
|
||||||
# api
|
|
||||||
openim-api
|
|
||||||
openim-ws
|
|
||||||
)
|
|
||||||
echo "${targets[@]}"
|
|
||||||
}
|
|
||||||
|
|
||||||
IFS=" " read -ra OPENIM_SERVER_NAME_TARGETS <<< "$(openim::common::service_name)"
|
|
||||||
readonly OPENIM_SERVER_NAME_TARGETS
|
|
||||||
|
|
||||||
# Storing all the defined ports in an array for easy management and access.
|
|
||||||
# This array consolidates the port numbers for all the services defined above.
|
|
||||||
openim::common::service_port() {
|
|
||||||
local targets=(
|
|
||||||
${OPENIM_USER_PORT} # User service
|
|
||||||
${OPENIM_FRIEND_PORT} # Friend service
|
|
||||||
${OPENIM_MESSAGE_PORT} # Message service
|
|
||||||
${OPENIM_MESSAGE_GATEWAY_PORT} # Message gateway
|
|
||||||
${OPENIM_GROUP_PORT} # Group service
|
|
||||||
${OPENIM_AUTH_PORT} # Authorization service
|
|
||||||
${OPENIM_PUSH_PORT} # Push service
|
|
||||||
${OPENIM_CONVERSATION_PORT} # Conversation service
|
|
||||||
${OPENIM_THIRD_PORT} # Third-party service
|
|
||||||
|
|
||||||
# API PORT
|
|
||||||
${API_OPENIM_PORT} # API service
|
|
||||||
${OPENIM_WS_PORT} # WebSocket service
|
|
||||||
)
|
|
||||||
echo "${targets[@]}"
|
|
||||||
}
|
|
||||||
IFS=" " read -ra OPENIM_SERVER_PORT_TARGETS <<< "$(openim::common::service_port)"
|
|
||||||
readonly OPENIM_SERVER_PORT_TARGETS
|
|
||||||
readonly OPENIM_SERVER_PORT_LISTARIES=("${OPENIM_SERVER_PORT_TARGETS[@]##*/}")
|
|
||||||
|
|
||||||
|
|
||||||
OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER=()
|
|
||||||
|
|
||||||
for target in "${OPENIM_SERVER_BINARIES_NO_TRANSFER[@]}"; do
|
|
||||||
OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER+=("${OPENIM_OUTPUT_HOSTBIN}/${target}")
|
|
||||||
done
|
|
||||||
readonly OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
OPENIM_ALL_SERVICE_LIBRARIES=()
|
|
||||||
for target in "${OPENIM_SERVER_BINARIES_NO_CMDUTILS[@]}"; do
|
|
||||||
OPENIM_ALL_SERVICE_LIBRARIES+=("${OPENIM_OUTPUT_HOSTBIN}/${target}")
|
|
||||||
done
|
|
||||||
readonly OPENIM_ALL_SERVICE_LIBRARIES
|
|
||||||
|
|
||||||
openim::common::dependency_name() {
|
|
||||||
local targets=(
|
|
||||||
redis
|
|
||||||
zookeeper
|
|
||||||
kafka
|
|
||||||
mongodb
|
|
||||||
minio
|
|
||||||
)
|
|
||||||
echo "${targets[@]}"
|
|
||||||
}
|
|
||||||
|
|
||||||
IFS=" " read -ra OPENIM_DEPENDENCY_TARGETS <<< "$(openim::common::dependency_name)"
|
|
||||||
readonly OPENIM_DEPENDENCY_TARGETS
|
|
||||||
|
|
||||||
# This function returns a list of ports for various services
|
|
||||||
# - zookeeper
|
|
||||||
# - kafka
|
|
||||||
# - mongodb
|
|
||||||
# - redis
|
|
||||||
# - minio
|
|
||||||
openim::common::dependency_port() {
|
|
||||||
local targets=(
|
|
||||||
${REDIS_PORT} # Redis port
|
|
||||||
${ZOOKEEPER_PORT} # Zookeeper port
|
|
||||||
${KAFKA_PORT} # Kafka port
|
|
||||||
${MONGO_PORT} # MongoDB port
|
|
||||||
${MINIO_PORT} # MinIO port
|
|
||||||
)
|
|
||||||
echo "${targets[@]}"
|
|
||||||
}
|
|
||||||
IFS=" " read -ra OPENIM_DEPENDENCY_PORT_TARGETS <<< "$(openim::common::dependency_port)"
|
|
||||||
readonly OPENIM_DEPENDENCY_PORT_TARGETS
|
|
||||||
readonly OPENIM_DEPENDENCY_PORT_LISTARIES=("${OPENIM_DEPENDENCY_PORT_TARGETS[@]##*/}")
|
|
||||||
|
|
||||||
# Execute commands that require root permission without entering a password
|
|
||||||
function openim::common::sudo {
|
|
||||||
echo ${LINUX_PASSWORD} | sudo -S $1
|
|
||||||
}
|
|
@ -1,89 +0,0 @@
|
|||||||
#!/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 will install the dependencies required for openim
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
|
|
||||||
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
|
|
||||||
|
|
||||||
# Start MongoDB service
|
|
||||||
docker run -d \
|
|
||||||
--name mongo \
|
|
||||||
-p 37017:27017 \
|
|
||||||
-v "${DATA_DIR}/components/mongodb/data/db:/data/db" \
|
|
||||||
-v "${DATA_DIR}/components/mongodb/data/logs:/data/logs" \
|
|
||||||
-v "${DATA_DIR}/components/mongodb/data/conf:/etc/mongo" \
|
|
||||||
-v "./scripts/mongo-init.sh:/docker-entrypoint-initdb.d/mongo-init.sh:ro" \
|
|
||||||
-e TZ=Asia/Shanghai \
|
|
||||||
-e wiredTigerCacheSizeGB=1 \
|
|
||||||
-e MONGO_INITDB_ROOT_USERNAME=${OPENIM_USER} \
|
|
||||||
-e MONGO_INITDB_ROOT_PASSWORD=${PASSWORD} \
|
|
||||||
-e MONGO_INITDB_DATABASE=openim_v3 \
|
|
||||||
-e MONGO_OPENIM_USERNAME=${OPENIM_USER} \
|
|
||||||
-e MONGO_OPENIM_PASSWORD=${PASSWORD} \
|
|
||||||
--restart always \
|
|
||||||
mongo:6.0.2 --wiredTigerCacheSizeGB 1 --auth
|
|
||||||
|
|
||||||
# Start Redis service
|
|
||||||
docker run -d \
|
|
||||||
--name redis \
|
|
||||||
-p 16379:6379 \
|
|
||||||
-v "${DATA_DIR}/components/redis/data:/data" \
|
|
||||||
-v "${DATA_DIR}/components/redis/config/redis.conf:/usr/local/redis/config/redis.conf" \
|
|
||||||
-e TZ=Asia/Shanghai \
|
|
||||||
--sysctl net.core.somaxconn=1024 \
|
|
||||||
--restart always \
|
|
||||||
redis:7.0.0 redis-server --requirepass ${PASSWORD} --appendonly yes
|
|
||||||
|
|
||||||
# Start Zookeeper service
|
|
||||||
docker run -d \
|
|
||||||
--name zookeeper \
|
|
||||||
-p 2181:2181 \
|
|
||||||
-v "/etc/localtime:/etc/localtime" \
|
|
||||||
-e TZ=Asia/Shanghai \
|
|
||||||
--restart always \
|
|
||||||
wurstmeister/zookeeper
|
|
||||||
|
|
||||||
# Start Kafka service
|
|
||||||
docker run -d \
|
|
||||||
--name kafka \
|
|
||||||
-p 9092:9092 \
|
|
||||||
-e TZ=Asia/Shanghai \
|
|
||||||
-e KAFKA_BROKER_ID=0 \
|
|
||||||
-e KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 \
|
|
||||||
-e KAFKA_CREATE_TOPICS="latestMsgToRedis:8:1,msgToPush:8:1,offlineMsgToMongoMysql:8:1" \
|
|
||||||
-e KAFKA_ADVERTISED_LISTENERS="INSIDE://127.0.0.1:9092,OUTSIDE://103.116.45.174:9092" \
|
|
||||||
-e KAFKA_LISTENERS="INSIDE://:9092,OUTSIDE://:9093" \
|
|
||||||
-e KAFKA_LISTENER_SECURITY_PROTOCOL_MAP="INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT" \
|
|
||||||
-e KAFKA_INTER_BROKER_LISTENER_NAME=INSIDE \
|
|
||||||
--restart always \
|
|
||||||
--link zookeeper \
|
|
||||||
wurstmeister/kafka
|
|
||||||
|
|
||||||
# Start MinIO service
|
|
||||||
docker run -d \
|
|
||||||
--name minio \
|
|
||||||
-p 10005:9000 \
|
|
||||||
-p 9090:9090 \
|
|
||||||
-v "/mnt/data:/data" \
|
|
||||||
-v "/mnt/config:/root/.minio" \
|
|
||||||
-e MINIO_ROOT_USER=${OPENIM_USER} \
|
|
||||||
-e MINIO_ROOT_PASSWORD=${PASSWORD} \
|
|
||||||
--restart always \
|
|
||||||
minio/minio server /data --console-address ':9090'
|
|
@ -1,118 +0,0 @@
|
|||||||
#!/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.
|
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------
|
|
||||||
# OpenIM Protoc Tool v1.0.0
|
|
||||||
# --------------------------------------------------------------
|
|
||||||
# OpenIM has released its custom Protoc tool version v1.0.0.
|
|
||||||
# This tool is customized to meet the specific needs of OpenIM and resides in its separate repository.
|
|
||||||
# It can be downloaded from the following link:
|
|
||||||
# https://github.com/OpenIMSDK/Open-IM-Protoc/releases/tag/v1.0.0
|
|
||||||
#
|
|
||||||
# About the tool:
|
|
||||||
# https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/protoc-tools.md
|
|
||||||
# Download link (Windows): https://github.com/OpenIMSDK/Open-IM-Protoc/releases/download/v1.0.0/windows.zip
|
|
||||||
# Download link (Linux): https://github.com/OpenIMSDK/Open-IM-Protoc/releases/download/v1.0.0/linux.zip
|
|
||||||
#
|
|
||||||
# Installation steps (taking Windows as an example):
|
|
||||||
# 1. Visit the above link and download the version suitable for Windows.
|
|
||||||
# 2. Extract the downloaded file.
|
|
||||||
# 3. Add the extracted tool to your PATH environment variable so that it can be run directly from the command line.
|
|
||||||
#
|
|
||||||
# Note: The specific installation and usage instructions may vary based on the tool's actual implementation. It's advised to refer to official documentation.
|
|
||||||
# --------------------------------------------------------------
|
|
||||||
|
|
||||||
PROTOC_DOWNLOAD_URL="https://github.com/OpenIMSDK/Open-IM-Protoc/releases/download/v1.0.0/linux.zip"
|
|
||||||
DOWNLOAD_DIR="/tmp/openim-protoc"
|
|
||||||
INSTALL_DIR="/usr/local/bin"
|
|
||||||
|
|
||||||
function help_message {
|
|
||||||
echo "Usage: ./install-protobuf.sh [option]"
|
|
||||||
echo "Options:"
|
|
||||||
echo "-i, --install Install the OpenIM Protoc tool."
|
|
||||||
echo "-u, --uninstall Uninstall the OpenIM Protoc tool."
|
|
||||||
echo "-r, --reinstall Reinstall the OpenIM Protoc tool."
|
|
||||||
echo "-c, --check Check if the OpenIM Protoc tool is installed."
|
|
||||||
echo "-h, --help Display this help message."
|
|
||||||
}
|
|
||||||
|
|
||||||
function install_protobuf {
|
|
||||||
echo "Installing OpenIM Protoc tool..."
|
|
||||||
|
|
||||||
# Create temporary directory and download the zip file
|
|
||||||
mkdir -p $DOWNLOAD_DIR
|
|
||||||
wget $PROTOC_DOWNLOAD_URL -O $DOWNLOAD_DIR/linux.zip
|
|
||||||
|
|
||||||
# Unzip the file
|
|
||||||
unzip -o $DOWNLOAD_DIR/linux.zip -d $DOWNLOAD_DIR
|
|
||||||
|
|
||||||
# Move binaries to the install directory and make them executable
|
|
||||||
sudo cp $DOWNLOAD_DIR/linux/protoc $INSTALL_DIR/
|
|
||||||
sudo cp $DOWNLOAD_DIR/linux/protoc-gen-go $INSTALL_DIR/
|
|
||||||
sudo chmod +x $INSTALL_DIR/protoc
|
|
||||||
sudo chmod +x $INSTALL_DIR/protoc-gen-go
|
|
||||||
|
|
||||||
# Clean up
|
|
||||||
rm -rf $DOWNLOAD_DIR
|
|
||||||
|
|
||||||
echo "OpenIM Protoc tool installed successfully!"
|
|
||||||
}
|
|
||||||
|
|
||||||
function uninstall_protobuf {
|
|
||||||
echo "Uninstalling OpenIM Protoc tool..."
|
|
||||||
|
|
||||||
# Removing binaries from the install directory
|
|
||||||
sudo rm -f $INSTALL_DIR/protoc
|
|
||||||
sudo rm -f $INSTALL_DIR/protoc-gen-go
|
|
||||||
|
|
||||||
echo "OpenIM Protoc tool uninstalled successfully!"
|
|
||||||
}
|
|
||||||
|
|
||||||
function reinstall_protobuf {
|
|
||||||
echo "Reinstalling OpenIM Protoc tool..."
|
|
||||||
uninstall_protobuf
|
|
||||||
install_protobuf
|
|
||||||
}
|
|
||||||
|
|
||||||
function check_protobuf {
|
|
||||||
echo "Checking for OpenIM Protoc tool installation..."
|
|
||||||
|
|
||||||
which protoc > /dev/null 2>&1
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
echo "OpenIM Protoc tool is installed."
|
|
||||||
else
|
|
||||||
echo "OpenIM Protoc tool is not installed."
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
while [ "$1" != "" ]; do
|
|
||||||
case $1 in
|
|
||||||
-i | --install ) install_protobuf
|
|
||||||
;;
|
|
||||||
-u | --uninstall ) uninstall_protobuf
|
|
||||||
;;
|
|
||||||
-r | --reinstall ) reinstall_protobuf
|
|
||||||
;;
|
|
||||||
-c | --check ) check_protobuf
|
|
||||||
;;
|
|
||||||
-h | --help ) help_message
|
|
||||||
exit
|
|
||||||
;;
|
|
||||||
* ) help_message
|
|
||||||
exit 1
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
@ -1,155 +0,0 @@
|
|||||||
#!/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.
|
|
||||||
#
|
|
||||||
# OpenIM Server Installation Script
|
|
||||||
#
|
|
||||||
# Description:
|
|
||||||
# This script is designed to handle the installation, Is a deployment solution
|
|
||||||
# that uses the Linux systen extension. uninstallation, and
|
|
||||||
# status checking of OpenIM components on the server. OpenIM is a presumed
|
|
||||||
# communication or messaging platform based on the context.
|
|
||||||
#
|
|
||||||
# Usage:
|
|
||||||
# To utilize this script, you need to invoke it with specific commands
|
|
||||||
# and options as detailed below.
|
|
||||||
#
|
|
||||||
# Commands:
|
|
||||||
# -i, --install : Use this command to initiate the installation of all
|
|
||||||
# OpenIM components.
|
|
||||||
# -u, --uninstall : Use this command to uninstall or remove all
|
|
||||||
# OpenIM components from the server.
|
|
||||||
# -s, --status : This command can be used to check and report the
|
|
||||||
# current operational status of the installed OpenIM components.
|
|
||||||
# -h, --help : For any assistance or to view the available commands,
|
|
||||||
# use this command to display the help menu.
|
|
||||||
#
|
|
||||||
# Example Usage:
|
|
||||||
# To install all OpenIM components:
|
|
||||||
# ./scripts/install/install.sh -i
|
|
||||||
# or
|
|
||||||
# ./scripts/install/install.sh --install
|
|
||||||
#
|
|
||||||
# Note:
|
|
||||||
# Ensure you have the necessary privileges to execute installation or
|
|
||||||
# uninstallation operations. It's generally recommended to take a backup
|
|
||||||
# before making major changes.
|
|
||||||
#
|
|
||||||
###############################################################################
|
|
||||||
|
|
||||||
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
|
|
||||||
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
|
|
||||||
|
|
||||||
${OPENIM_ROOT}/scripts/install/openim-man.sh
|
|
||||||
${OPENIM_ROOT}/scripts/install/openim-tools.sh
|
|
||||||
${OPENIM_ROOT}/scripts/install/test.sh
|
|
||||||
|
|
||||||
# Detailed help function
|
|
||||||
function openim::install::show_help() {
|
|
||||||
echo "OpenIM Installer"
|
|
||||||
echo "Usage: $0 <command> [options]"
|
|
||||||
echo ""
|
|
||||||
echo "Commands:"
|
|
||||||
echo " -i, --install Install all OpenIM components."
|
|
||||||
echo " -u, --uninstall Remove all OpenIM components."
|
|
||||||
echo " -s, --status Check the current status of OpenIM components."
|
|
||||||
echo " -h, --help Show this help menu."
|
|
||||||
echo ""
|
|
||||||
echo "Example: "
|
|
||||||
echo " $0 -i Will install all OpenIM components."
|
|
||||||
echo " $0 --install Same as above."
|
|
||||||
}
|
|
||||||
|
|
||||||
function openim::install::install_openim() {
|
|
||||||
openim::common::sudo "mkdir -p ${OPENIM_DATA_DIR} ${OPENIM_INSTALL_DIR} ${OPENIM_CONFIG_DIR} ${OPENIM_LOG_DIR}"
|
|
||||||
openim::log::info "check openim dependency"
|
|
||||||
openim::common::sudo "cp -r ${OPENIM_ROOT}/config/* ${OPENIM_CONFIG_DIR}/"
|
|
||||||
|
|
||||||
${OPENIM_ROOT}/scripts/genconfig.sh ${ENV_FILE} ${OPENIM_ROOT}/deployments/templates/config.yaml > ${OPENIM_CONFIG_DIR}/config.yaml
|
|
||||||
${OPENIM_ROOT}/scripts/genconfig.sh ${ENV_FILE} ${OPENIM_ROOT}/deployments/templates/prometheus.yml > ${OPENIM_CONFIG_DIR}/prometheus.yml
|
|
||||||
|
|
||||||
openim::util::check_ports ${OPENIM_DEPENDENCY_PORT_LISTARIES[@]}
|
|
||||||
|
|
||||||
${OPENIM_ROOT}/scripts/install/openim-msggateway.sh openim::msggateway::install || return 1
|
|
||||||
${OPENIM_ROOT}/scripts/install/openim-msgtransfer.sh openim::msgtransfer::install || return 1
|
|
||||||
${OPENIM_ROOT}/scripts/install/openim-push.sh openim::push::install || return 1
|
|
||||||
${OPENIM_ROOT}/scripts/install/openim-crontask.sh openim::crontask::install || return 1
|
|
||||||
${OPENIM_ROOT}/scripts/install/openim-rpc.sh openim::rpc::install || return 1
|
|
||||||
${OPENIM_ROOT}/scripts/install/openim-api.sh openim::api::install || return 1
|
|
||||||
|
|
||||||
openim::common::sudo "cp -r ${OPENIM_ROOT}/deployments/templates/openim.target /etc/systemd/system/openim.target"
|
|
||||||
openim::common::sudo "systemctl daemon-reload"
|
|
||||||
openim::common::sudo "systemctl restart openim.target"
|
|
||||||
openim::common::sudo "systemctl enable openim.target"
|
|
||||||
openim::log::success "openim install success"
|
|
||||||
}
|
|
||||||
|
|
||||||
function openim::uninstall::uninstall_openim() {
|
|
||||||
openim::log::info "uninstall openim"
|
|
||||||
|
|
||||||
${OPENIM_ROOT}/scripts/install/openim-msggateway.sh openim::msggateway::uninstall || return 1
|
|
||||||
${OPENIM_ROOT}/scripts/install/openim-msgtransfer.sh openim::msgtransfer::uninstall || return 1
|
|
||||||
${OPENIM_ROOT}/scripts/install/openim-push.sh openim::push::uninstall || return 1
|
|
||||||
${OPENIM_ROOT}/scripts/install/openim-crontask.sh openim::crontask::uninstall || return 1
|
|
||||||
${OPENIM_ROOT}/scripts/install/openim-rpc.sh openim::rpc::uninstall || return 1
|
|
||||||
${OPENIM_ROOT}/scripts/install/openim-api.sh openim::api::uninstall || return 1
|
|
||||||
|
|
||||||
set +o errexit
|
|
||||||
openim::common::sudo "systemctl stop openim.target"
|
|
||||||
openim::common::sudo "systemctl disable openim.target"
|
|
||||||
openim::common::sudo "rm -f /etc/systemd/system/openim.target"
|
|
||||||
|
|
||||||
openim::log::success "openim uninstall success"
|
|
||||||
}
|
|
||||||
|
|
||||||
function openim::install::status() {
|
|
||||||
openim::log::info "check openim status"
|
|
||||||
|
|
||||||
${OPENIM_ROOT}/scripts/install/openim-msggateway.sh openim::msggateway::status || return 1
|
|
||||||
${OPENIM_ROOT}/scripts/install/openim-msgtransfer.sh openim::msgtransfer::status || return 1
|
|
||||||
${OPENIM_ROOT}/scripts/install/openim-push.sh openim::push::status || return 1
|
|
||||||
${OPENIM_ROOT}/scripts/install/openim-crontask.sh openim::crontask::status || return 1
|
|
||||||
${OPENIM_ROOT}/scripts/install/openim-rpc.sh openim::rpc::status || return 1
|
|
||||||
${OPENIM_ROOT}/scripts/install/openim-api.sh openim::api::status || return 1
|
|
||||||
|
|
||||||
openim::log::success "openim status success"
|
|
||||||
}
|
|
||||||
|
|
||||||
# If no arguments are provided, show help
|
|
||||||
if [[ $# -eq 0 ]]; then
|
|
||||||
openim::install::show_help
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Argument parsing to call functions based on user input
|
|
||||||
while (( "$#" )); do
|
|
||||||
case "$1" in
|
|
||||||
-i|--install)
|
|
||||||
openim::install::install_openim
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
-u|--uninstall)
|
|
||||||
openim::uninstall::uninstall_openim
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
-s|--status)
|
|
||||||
openim::install::status
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
-h|--help|*)
|
|
||||||
openim::install::show_help
|
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
@ -1,169 +0,0 @@
|
|||||||
#!/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.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
|
|
||||||
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
|
|
||||||
|
|
||||||
SERVER_NAME="openim-api"
|
|
||||||
|
|
||||||
readonly OPENIM_API_PORT_TARGETS=(
|
|
||||||
${API_OPENIM_PORT}
|
|
||||||
)
|
|
||||||
readonly OPENIM_API_PORT_LISTARIES=("${OPENIM_API_PORT_TARGETS[@]##*/}")
|
|
||||||
|
|
||||||
readonly OPENIM_API_SERVICE_TARGETS=(
|
|
||||||
openim-api
|
|
||||||
)
|
|
||||||
readonly OPENIM_API_SERVICE_LISTARIES=("${OPENIM_API_SERVICE_TARGETS[@]##*/}")
|
|
||||||
|
|
||||||
readonly OPENIM_API_PROMETHEUS_PORT_TARGETS=(
|
|
||||||
${API_PROM_PORT}
|
|
||||||
)
|
|
||||||
readonly OPENIM_API_PROMETHEUS_PORT_LISTARIES=("${OPENIM_API_PROMETHEUS_PORT_TARGETS[@]##*/}")
|
|
||||||
|
|
||||||
function openim::api::start() {
|
|
||||||
rm -rf "$TMP_LOG_FILE"
|
|
||||||
|
|
||||||
echo "++ OPENIM_API_SERVICE_LISTARIES: ${OPENIM_API_SERVICE_LISTARIES[@]}"
|
|
||||||
echo "++ OPENIM_API_PORT_LISTARIES: ${OPENIM_API_PORT_LISTARIES[@]}"
|
|
||||||
echo "++ OpenIM API config path: ${OPENIM_API_CONFIG}"
|
|
||||||
|
|
||||||
openim::log::info "Starting ${SERVER_NAME} ..."
|
|
||||||
|
|
||||||
readonly OPENIM_API_SERVER_LIBRARIES="${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME}"
|
|
||||||
|
|
||||||
|
|
||||||
printf "+------------------------+--------------+\n"
|
|
||||||
printf "| Service Name | Port |\n"
|
|
||||||
printf "+------------------------+--------------+\n"
|
|
||||||
|
|
||||||
|
|
||||||
local length=${#OPENIM_API_SERVICE_LISTARIES[@]}
|
|
||||||
for ((i=0; i<length; i++)); do
|
|
||||||
printf "| %-22s | %6s |\n" "${OPENIM_API_SERVICE_LISTARIES[$i]}" "${OPENIM_API_PORT_LISTARIES[$i]}"
|
|
||||||
printf "+------------------------+--------------+\n"
|
|
||||||
# Stop services on the specified ports before starting new ones
|
|
||||||
openim::log::info "OpenIM ${OPENIM_API_SERVICE_LISTARIES[$i]} config path: ${OPENIM_API_CONFIG}"
|
|
||||||
|
|
||||||
# Start the service with Prometheus port if specified
|
|
||||||
result=$(openim::api::start_service "${OPENIM_API_SERVICE_LISTARIES[$i]}" "${OPENIM_API_PORT_LISTARIES[$i]}" "${OPENIM_API_PROMETHEUS_PORT_LISTARIES[$i]}")
|
|
||||||
if [[ $? -ne 0 ]]; then
|
|
||||||
openim::log::error "stop ${SERVER_NAME} failed"
|
|
||||||
else
|
|
||||||
openim::log::info "$result"
|
|
||||||
fi
|
|
||||||
|
|
||||||
done
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
function openim::api::start_service() {
|
|
||||||
local binary_name="$1"
|
|
||||||
local service_port="$2"
|
|
||||||
local prometheus_port="$3"
|
|
||||||
|
|
||||||
local cmd="${OPENIM_OUTPUT_HOSTBIN}/${binary_name} --port ${service_port} -c ${OPENIM_API_CONFIG}"
|
|
||||||
|
|
||||||
# Append Prometheus port argument if specified
|
|
||||||
if [ -n "${prometheus_port}" ]; then
|
|
||||||
cmd+=" --prometheus_port ${prometheus_port}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Starting service with command: $cmd"
|
|
||||||
|
|
||||||
#nohup $cmd >> "${LOG_FILE}" 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE" >&2) &
|
|
||||||
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >> "${LOG_FILE}" 2>&1 &
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
openim::log::error_exit "Failed to start ${binary_name} on port ${service_port}."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
###################################### Linux Systemd ######################################
|
|
||||||
SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service"
|
|
||||||
|
|
||||||
# Print the necessary information after installation
|
|
||||||
function openim::api::info() {
|
|
||||||
cat << EOF
|
|
||||||
openim-api listen on: ${OPENIM_API_HOST}:${API_OPENIM_PORT}
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
|
|
||||||
# install openim-api
|
|
||||||
function openim::api::install() {
|
|
||||||
openim::log::info "Installing ${SERVER_NAME} ..."
|
|
||||||
|
|
||||||
pushd "${OPENIM_ROOT}"
|
|
||||||
|
|
||||||
# 1. Build openim-api
|
|
||||||
make build BINS=${SERVER_NAME}
|
|
||||||
openim::common::sudo "cp -r ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
|
|
||||||
openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/${SERVER_NAME}/${SERVER_NAME}"
|
|
||||||
|
|
||||||
# 2. Generate and install the openim-api configuration file (config)
|
|
||||||
openim::log::status "${SERVER_NAME} config file: ${OPENIM_CONFIG_DIR}/config.yaml"
|
|
||||||
|
|
||||||
# 3. Create and install the ${SERVER_NAME} systemd unit file
|
|
||||||
echo ${LINUX_PASSWORD} | sudo -S bash -c \
|
|
||||||
"SERVER_NAME=${SERVER_NAME} ./scripts/genconfig.sh ${ENV_FILE} deployments/templates/openim.service > ${SYSTEM_FILE_PATH}"
|
|
||||||
openim::log::status "${SERVER_NAME} systemd file: ${SYSTEM_FILE_PATH}"
|
|
||||||
|
|
||||||
# 4. Start the openim-api service
|
|
||||||
openim::common::sudo "systemctl daemon-reload"
|
|
||||||
openim::common::sudo "systemctl restart ${SERVER_NAME}"
|
|
||||||
openim::common::sudo "systemctl enable ${SERVER_NAME}"
|
|
||||||
openim::api::status || return 1
|
|
||||||
openim::api::info
|
|
||||||
|
|
||||||
openim::log::info "install ${SERVER_NAME} successfully"
|
|
||||||
popd
|
|
||||||
}
|
|
||||||
|
|
||||||
# Unload
|
|
||||||
function openim::api::uninstall() {
|
|
||||||
openim::log::info "Uninstalling ${SERVER_NAME} ..."
|
|
||||||
|
|
||||||
set +o errexit
|
|
||||||
openim::common::sudo "systemctl stop ${SERVER_NAME}"
|
|
||||||
openim::common::sudo "systemctl disable ${SERVER_NAME}"
|
|
||||||
openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
|
|
||||||
openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
|
|
||||||
openim::common::sudo "rm -f /etc/systemd/system/${SERVER_NAME}.service"
|
|
||||||
|
|
||||||
openim::log::info "uninstall ${SERVER_NAME} successfully"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Status Check
|
|
||||||
function openim::api::status() {
|
|
||||||
openim::log::info "Checking ${SERVER_NAME} status ..."
|
|
||||||
|
|
||||||
# Check the running status of the ${SERVER_NAME}. If active (running) is displayed, the ${SERVER_NAME} is started successfully.
|
|
||||||
systemctl status ${SERVER_NAME}|grep -q 'active' || {
|
|
||||||
openim::log::error "${SERVER_NAME} failed to start, maybe not installed properly"
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
openim::util::check_ports ${OPENIM_API_PORT_LISTARIES[@]}
|
|
||||||
}
|
|
||||||
|
|
||||||
if [[ "$*" =~ openim::api:: ]];then
|
|
||||||
eval $*
|
|
||||||
fi
|
|
@ -1,126 +0,0 @@
|
|||||||
#!/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.
|
|
||||||
#
|
|
||||||
# OpenIM CronTask Control Script
|
|
||||||
#
|
|
||||||
# Description:
|
|
||||||
# This script provides a control interface for the OpenIM CronTask service within a Linux environment. It supports two installation methods: installation via function calls to systemctl, and direct installation through background processes.
|
|
||||||
#
|
|
||||||
# Features:
|
|
||||||
# 1. Robust error handling leveraging Bash built-ins such as 'errexit', 'nounset', and 'pipefail'.
|
|
||||||
# 2. Capability to source common utility functions and configurations, ensuring environmental consistency.
|
|
||||||
# 3. Comprehensive logging tools, offering clear operational insights.
|
|
||||||
# 4. Support for creating, managing, and interacting with Linux systemd services.
|
|
||||||
# 5. Mechanisms to verify the successful running of the service.
|
|
||||||
#
|
|
||||||
# Usage:
|
|
||||||
# 1. Direct Script Execution:
|
|
||||||
# This will start the OpenIM CronTask directly through a background process.
|
|
||||||
# Example: ./openim-crontask.sh openim::crontask::start
|
|
||||||
#
|
|
||||||
# 2. Controlling through Functions for systemctl operations:
|
|
||||||
# Specific operations like installation, uninstallation, and status check can be executed by passing the respective function name as an argument to the script.
|
|
||||||
# Example: ./openim-crontask.sh openim::crontask::install
|
|
||||||
#
|
|
||||||
# Note: Ensure that the appropriate permissions and environmental variables are set prior to script execution.
|
|
||||||
#
|
|
||||||
|
|
||||||
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
|
|
||||||
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
|
|
||||||
|
|
||||||
SERVER_NAME="openim-crontask"
|
|
||||||
|
|
||||||
function openim::crontask::start() {
|
|
||||||
|
|
||||||
rm -rf "$TMP_LOG_FILE"
|
|
||||||
|
|
||||||
openim::log::info "Start OpenIM Cron, binary root: ${SERVER_NAME}"
|
|
||||||
openim::log::status "Start OpenIM Cron, path: ${OPENIM_CRONTASK_BINARY}"
|
|
||||||
|
|
||||||
openim::log::status "start cron_task process, path: ${OPENIM_CRONTASK_BINARY}"
|
|
||||||
#nohup ${OPENIM_CRONTASK_BINARY} -c ${OPENIM_PUSH_CONFIG} >> ${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE" >&2) &
|
|
||||||
cmd="${OPENIM_CRONTASK_BINARY} -c ${OPENIM_PUSH_CONFIG}"
|
|
||||||
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >> "${LOG_FILE}" 2>&1 &
|
|
||||||
return 0
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
###################################### Linux Systemd ######################################
|
|
||||||
SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service"
|
|
||||||
|
|
||||||
# Print the necessary information after installation
|
|
||||||
function openim::crontask::info() {
|
|
||||||
cat << EOF
|
|
||||||
openim-crontask listen on: ${OPENIM_CRONTASK_HOST}
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
|
|
||||||
# install openim-crontask
|
|
||||||
function openim::crontask::install() {
|
|
||||||
pushd "${OPENIM_ROOT}"
|
|
||||||
|
|
||||||
# 1. Build openim-crontask
|
|
||||||
make build BINS=${SERVER_NAME}
|
|
||||||
|
|
||||||
openim::common::sudo "cp -r ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
|
|
||||||
openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/${SERVER_NAME}/${SERVER_NAME}"
|
|
||||||
|
|
||||||
# 2. Generate and install the openim-crontask configuration file (openim-crontask.yaml)
|
|
||||||
openim::log::status "${SERVER_NAME} config file: ${OPENIM_CONFIG_DIR}/config.yaml"
|
|
||||||
|
|
||||||
# 3. Create and install the ${SERVER_NAME} systemd unit file
|
|
||||||
echo ${LINUX_PASSWORD} | sudo -S bash -c \
|
|
||||||
"SERVER_NAME=${SERVER_NAME} ./scripts/genconfig.sh ${ENV_FILE} deployments/templates/openim.service > ${SYSTEM_FILE_PATH}"
|
|
||||||
openim::log::status "${SERVER_NAME} systemd file: ${SYSTEM_FILE_PATH}"
|
|
||||||
|
|
||||||
# 4. Start the openim-crontask service
|
|
||||||
openim::common::sudo "systemctl daemon-reload"
|
|
||||||
openim::common::sudo "systemctl restart ${SERVER_NAME}"
|
|
||||||
openim::common::sudo "systemctl enable ${SERVER_NAME}"
|
|
||||||
openim::crontask::status || return 1
|
|
||||||
openim::crontask::info
|
|
||||||
|
|
||||||
openim::log::info "install ${SERVER_NAME} successfully"
|
|
||||||
popd
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Unload
|
|
||||||
function openim::crontask::uninstall() {
|
|
||||||
set +o errexit
|
|
||||||
openim::common::sudo "systemctl stop ${SERVER_NAME}"
|
|
||||||
openim::common::sudo "systemctl disable ${SERVER_NAME}"
|
|
||||||
openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
|
|
||||||
openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
|
|
||||||
openim::common::sudo "rm -f /etc/systemd/system/${SERVER_NAME}.service"
|
|
||||||
|
|
||||||
openim::log::info "uninstall ${SERVER_NAME} successfully"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Status Check
|
|
||||||
function openim::crontask::status() {
|
|
||||||
# Check the running status of the ${SERVER_NAME}. If active (running) is displayed, the ${SERVER_NAME} is started successfully.
|
|
||||||
if systemctl is-active --quiet "${SERVER_NAME}"; then
|
|
||||||
openim::log::info "${SERVER_NAME} is running successfully."
|
|
||||||
else
|
|
||||||
openim::log::error "${SERVER_NAME} failed to start, maybe not installed properly"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
if [[ "$*" =~ openim::crontask:: ]];then
|
|
||||||
eval $*
|
|
||||||
fi
|
|
@ -1,96 +0,0 @@
|
|||||||
#!/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.
|
|
||||||
|
|
||||||
# openim-man.sh Script to manage man pages for openim
|
|
||||||
#
|
|
||||||
# Description:
|
|
||||||
# This script manages the man pages for the OpenIM software suite.
|
|
||||||
# It provides facilities to install, uninstall, and verify the
|
|
||||||
# installation status of the man pages related to OpenIM components.
|
|
||||||
#
|
|
||||||
# Usage:
|
|
||||||
# ./openim-man.sh openim::man::install - Install man pages
|
|
||||||
# ./openim-man.sh openim::man::uninstall - Uninstall man pages
|
|
||||||
# ./openim-man.sh openim::man::status - Check installation status
|
|
||||||
#
|
|
||||||
# Dependencies:
|
|
||||||
# - Assumes there's a common.sh in "${OPENIM_ROOT}/scripts/install/"
|
|
||||||
# containing shared functions and variables.
|
|
||||||
# - Relies on the script "${OPENIM_ROOT}/scripts/update-generated-docs.sh"
|
|
||||||
# to generate the man pages.
|
|
||||||
#
|
|
||||||
# Notes:
|
|
||||||
# - This script must be run with appropriate permissions to modify the
|
|
||||||
# system man directories.
|
|
||||||
# - Always ensure you're in the script's directory or provide the correct
|
|
||||||
# path when executing.
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
# Define the root of the build/dist directory
|
|
||||||
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)
|
|
||||||
|
|
||||||
# Ensure the common script is sourced
|
|
||||||
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}/scripts/install/common.sh"
|
|
||||||
|
|
||||||
# Print usage information after installation
|
|
||||||
function openim::man::info() {
|
|
||||||
cat <<- EOF
|
|
||||||
Usage:
|
|
||||||
man openim-server to see openim-server help # Display the man page for openim-server
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
|
|
||||||
# Install the man pages for openim
|
|
||||||
function openim::man::install() {
|
|
||||||
# Navigate to the openim root directory
|
|
||||||
pushd "${OPENIM_ROOT}" > /dev/null
|
|
||||||
|
|
||||||
# Generate man pages for each component
|
|
||||||
"${OPENIM_ROOT}/scripts/update-generated-docs.sh"
|
|
||||||
openim::common::sudo "cp docs/man/man1/* /usr/share/man/man1/"
|
|
||||||
|
|
||||||
# Verify installation status
|
|
||||||
if openim::man::status; then
|
|
||||||
openim::log::info "Installed openim-server man page successfully"
|
|
||||||
openim::man::info
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Return to the original directory
|
|
||||||
popd > /dev/null
|
|
||||||
}
|
|
||||||
|
|
||||||
# Uninstall the man pages for openim
|
|
||||||
function openim::man::uninstall() {
|
|
||||||
# Turn off exit-on-error temporarily to handle non-existing files gracefully
|
|
||||||
set +o errexit
|
|
||||||
openim::common::sudo "rm -f /usr/share/man/man1/openim-*"
|
|
||||||
|
|
||||||
|
|
||||||
openim::log::info "Uninstalled openim man pages successfully"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Check the installation status of the man pages
|
|
||||||
function openim::man::status() {
|
|
||||||
if ! ls /usr/share/man/man1/openim-* &> /dev/null; then
|
|
||||||
openim::log::error "OpenIM man files not found. Perhaps they were not installed correctly."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
# Execute the appropriate function based on the given arguments
|
|
||||||
if [[ "$*" =~ openim::man:: ]]; then
|
|
||||||
eval "$*"
|
|
||||||
fi
|
|
@ -1,141 +0,0 @@
|
|||||||
#!/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.
|
|
||||||
|
|
||||||
# Common utilities, variables and checks for all build scripts.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
|
|
||||||
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
|
|
||||||
|
|
||||||
|
|
||||||
SERVER_NAME="openim-msggateway"
|
|
||||||
|
|
||||||
function openim::msggateway::start() {
|
|
||||||
|
|
||||||
rm -rf "$TMP_LOG_FILE"
|
|
||||||
|
|
||||||
openim::log::info "Start OpenIM Msggateway, binary root: ${SERVER_NAME}"
|
|
||||||
openim::log::status "Start OpenIM Msggateway, path: ${OPENIM_MSGGATEWAY_BINARY}"
|
|
||||||
|
|
||||||
|
|
||||||
# OpenIM message gateway service port
|
|
||||||
OPENIM_MESSAGE_GATEWAY_PORTS=$(openim::util::list-to-string ${OPENIM_MESSAGE_GATEWAY_PORT} )
|
|
||||||
read -a OPENIM_MSGGATEWAY_PORTS_ARRAY <<< ${OPENIM_MESSAGE_GATEWAY_PORTS}
|
|
||||||
openim::util::stop_services_on_ports ${OPENIM_MSGGATEWAY_PORTS_ARRAY[*]}
|
|
||||||
# OpenIM WS port
|
|
||||||
OPENIM_WS_PORTS=$(openim::util::list-to-string ${OPENIM_WS_PORT} )
|
|
||||||
read -a OPENIM_WS_PORTS_ARRAY <<< ${OPENIM_WS_PORTS}
|
|
||||||
|
|
||||||
# Message Gateway Prometheus port of the service
|
|
||||||
MSG_GATEWAY_PROM_PORTS=$(openim::util::list-to-string ${MSG_GATEWAY_PROM_PORT} )
|
|
||||||
read -a MSG_GATEWAY_PROM_PORTS_ARRAY <<< ${MSG_GATEWAY_PROM_PORTS}
|
|
||||||
|
|
||||||
openim::log::status "OpenIM Mssage Getway ports: ${OPENIM_MESSAGE_GATEWAY_PORTS[*]}"
|
|
||||||
openim::log::status "OpenIM WS ports: ${OPENIM_WS_PORTS[*]}"
|
|
||||||
openim::log::status "OpenIM Prometheus ports: ${MSG_GATEWAY_PROM_PORTS[*]}"
|
|
||||||
|
|
||||||
openim::log::status "OpenIM Msggateway config path: ${OPENIM_MSGGATEWAY_CONFIG}"
|
|
||||||
|
|
||||||
if [ ${#OPENIM_MSGGATEWAY_PORTS_ARRAY[@]} -ne ${#OPENIM_WS_PORTS_ARRAY[@]} ]; then
|
|
||||||
openim::log::error_exit "ws_ports does not match push_rpc_ports or prome_ports in quantity!!!"
|
|
||||||
fi
|
|
||||||
|
|
||||||
for ((i = 0; i < ${#OPENIM_WS_PORTS_ARRAY[@]}; i++)); do
|
|
||||||
openim::log::info "start push process, port: ${OPENIM_MSGGATEWAY_PORTS_ARRAY[$i]}, prometheus port: ${MSG_GATEWAY_PROM_PORTS_ARRAY[$i]}"
|
|
||||||
|
|
||||||
PROMETHEUS_PORT_OPTION=""
|
|
||||||
if [[ -n "${MSG_GATEWAY_PROM_PORTS_ARRAY[$i]}" ]]; then
|
|
||||||
PROMETHEUS_PORT_OPTION="--prometheus_port ${MSG_GATEWAY_PROM_PORTS_ARRAY[$i]}"
|
|
||||||
fi
|
|
||||||
cmd="${OPENIM_MSGGATEWAY_BINARY} --port ${OPENIM_MSGGATEWAY_PORTS_ARRAY[$i]} --ws_port ${OPENIM_WS_PORTS_ARRAY[$i]} $PROMETHEUS_PORT_OPTION -c ${OPENIM_MSGGATEWAY_CONFIG}"
|
|
||||||
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >> "${LOG_FILE}" 2>&1 &
|
|
||||||
# nohup ${OPENIM_MSGGATEWAY_BINARY} --port ${OPENIM_MSGGATEWAY_PORTS_ARRAY[$i]} --ws_port ${OPENIM_WS_PORTS_ARRAY[$i]} $PROMETHEUS_PORT_OPTION -c ${OPENIM_MSGGATEWAY_CONFIG} >> ${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE" >&2) &
|
|
||||||
|
|
||||||
done
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
###################################### Linux Systemd ######################################
|
|
||||||
SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service"
|
|
||||||
|
|
||||||
# Print the necessary information after installation
|
|
||||||
function openim::msggateway::info() {
|
|
||||||
cat << EOF
|
|
||||||
openim-msggateway listen on: ${OPENIM_MSGGATEWAY_HOST}:${OPENIM_MESSAGE_GATEWAY_PORT}
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
|
|
||||||
# install openim-msggateway
|
|
||||||
function openim::msggateway::install() {
|
|
||||||
pushd "${OPENIM_ROOT}"
|
|
||||||
|
|
||||||
# 1. Build openim-msggateway
|
|
||||||
make build BINS=${SERVER_NAME}
|
|
||||||
openim::common::sudo "cp -r ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
|
|
||||||
openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
|
|
||||||
|
|
||||||
# 2. Generate and install the openim-msggateway configuration file (openim-msggateway.yaml)
|
|
||||||
# nono
|
|
||||||
|
|
||||||
# 3. Create and install the ${SERVER_NAME} systemd unit file
|
|
||||||
echo ${LINUX_PASSWORD} | sudo -S bash -c \
|
|
||||||
"SERVER_NAME=${SERVER_NAME} ./scripts/genconfig.sh ${ENV_FILE} deployments/templates/openim.service > ${SYSTEM_FILE_PATH}"
|
|
||||||
openim::log::status "${SERVER_NAME} systemd file: ${SYSTEM_FILE_PATH}"
|
|
||||||
|
|
||||||
# 4. Start the openim-msggateway service
|
|
||||||
openim::common::sudo "systemctl daemon-reload"
|
|
||||||
openim::common::sudo "systemctl restart ${SERVER_NAME}"
|
|
||||||
openim::common::sudo "systemctl enable ${SERVER_NAME}"
|
|
||||||
openim::msggateway::status || return 1
|
|
||||||
openim::msggateway::info
|
|
||||||
|
|
||||||
openim::log::info "install ${SERVER_NAME} successfully"
|
|
||||||
popd
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Unload
|
|
||||||
function openim::msggateway::uninstall() {
|
|
||||||
set +o errexit
|
|
||||||
openim::common::sudo "systemctl stop ${SERVER_NAME}"
|
|
||||||
openim::common::sudo "systemctl disable ${SERVER_NAME}"
|
|
||||||
openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
|
|
||||||
openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
|
|
||||||
openim::common::sudo "rm -f /etc/systemd/system/${SERVER_NAME}.service"
|
|
||||||
|
|
||||||
openim::log::info "uninstall ${SERVER_NAME} successfully"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Status Check
|
|
||||||
function openim::msggateway::status() {
|
|
||||||
# Check the running status of the ${SERVER_NAME}. If active (running) is displayed, the ${SERVER_NAME} is started successfully.
|
|
||||||
systemctl status ${SERVER_NAME}|grep -q 'active' || {
|
|
||||||
openim::log::error "${SERVER_NAME} failed to start, maybe not installed properly"
|
|
||||||
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# The listening port is hardcode in the configuration file
|
|
||||||
if echo | telnet ${OPENIM_MSGGATEWAY_HOST} ${OPENIM_MESSAGE_GATEWAY_PORT} 2>&1|grep refused &>/dev/null;then
|
|
||||||
openim::log::error "cannot access health check port, ${SERVER_NAME} maybe not startup"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
if [[ "$*" =~ openim::msggateway:: ]];then
|
|
||||||
eval $*
|
|
||||||
fi
|
|
@ -1,186 +0,0 @@
|
|||||||
#!/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.
|
|
||||||
# Use:
|
|
||||||
# ./scripts/install/openim-msgtransfer.sh openim::msgtransfer::start
|
|
||||||
|
|
||||||
# Common utilities, variables and checks for all build scripts.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
|
|
||||||
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
|
|
||||||
|
|
||||||
SERVER_NAME="openim-msgtransfer"
|
|
||||||
|
|
||||||
function openim::msgtransfer::start() {
|
|
||||||
|
|
||||||
rm -rf "$TMP_LOG_FILE"
|
|
||||||
|
|
||||||
openim::log::info "Start OpenIM Msggateway, binary root: ${SERVER_NAME}"
|
|
||||||
openim::log::status "Start OpenIM Msggateway, path: ${OPENIM_MSGTRANSFER_BINARY}"
|
|
||||||
|
|
||||||
# Message Transfer Prometheus port list
|
|
||||||
MSG_TRANSFER_PROM_PORTS=(openim::util::list-to-string ${MSG_TRANSFER_PROM_PORT} )
|
|
||||||
|
|
||||||
openim::log::status "OpenIM Prometheus ports: ${MSG_TRANSFER_PROM_PORTS[*]}"
|
|
||||||
|
|
||||||
openim::log::status "OpenIM Msggateway config path: ${OPENIM_MSGTRANSFER_CONFIG}"
|
|
||||||
|
|
||||||
openim::log::info "openim maggateway num: ${OPENIM_MSGGATEWAY_NUM}"
|
|
||||||
|
|
||||||
if [ "${OPENIM_MSGGATEWAY_NUM}" -lt 1 ]; then
|
|
||||||
opeim::log::error "OPENIM_MSGGATEWAY_NUM must be greater than 0"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ${OPENIM_MSGGATEWAY_NUM} -ne $((${#MSG_TRANSFER_PROM_PORTS[@]} - 1)) ]; then
|
|
||||||
openim::log::error "OPENIM_MSGGATEWAY_NUM must be equal to the number of MSG_TRANSFER_PROM_PORTS"
|
|
||||||
fi
|
|
||||||
|
|
||||||
for (( i=0; i<$OPENIM_MSGGATEWAY_NUM; i++ )) do
|
|
||||||
openim::log::info "prometheus port: ${MSG_TRANSFER_PROM_PORTS[$i]}"
|
|
||||||
PROMETHEUS_PORT_OPTION=""
|
|
||||||
if [[ -n "${MSG_TRANSFER_PROM_PORTS[$i+1]}" ]]; then
|
|
||||||
PROMETHEUS_MSG_TRANSFER_PORT="${MSG_TRANSFER_PROM_PORTS[$i+1]%,}"
|
|
||||||
openim::util::stop_services_on_ports ${PROMETHEUS_MSG_TRANSFER_PORT}
|
|
||||||
PROMETHEUS_PORT_OPTION="--prometheus_port ${PROMETHEUS_MSG_TRANSFER_PORT}"
|
|
||||||
fi
|
|
||||||
cmd="${OPENIM_MSGTRANSFER_BINARY} ${PROMETHEUS_PORT_OPTION} -c ${OPENIM_MSGTRANSFER_CONFIG} -n ${i}"
|
|
||||||
#nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >/dev/null &
|
|
||||||
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >> "${LOG_FILE}" 2>&1 &
|
|
||||||
#nohup ${OPENIM_MSGTRANSFER_BINARY} ${PROMETHEUS_PORT_OPTION} -c ${OPENIM_MSGTRANSFER_CONFIG} -n ${i} >> ${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE" >&2) &
|
|
||||||
done
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
function openim::msgtransfer::check() {
|
|
||||||
PIDS=$(pgrep -f "${OPENIM_OUTPUT_HOSTBIN}/openim-msgtransfer")
|
|
||||||
if [ -z "$PIDS" ]; then
|
|
||||||
NUM_PROCESSES=0
|
|
||||||
else
|
|
||||||
NUM_PROCESSES=$(echo "$PIDS" | wc -l)
|
|
||||||
fi
|
|
||||||
if [ "$NUM_PROCESSES" -eq "$OPENIM_MSGGATEWAY_NUM" ]; then
|
|
||||||
for PID in $PIDS; do
|
|
||||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
|
||||||
ps -p $PID -o pid,cmd
|
|
||||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
|
||||||
ps -p $PID -o pid,comm
|
|
||||||
else
|
|
||||||
openim::log::error "Unsupported OS type: $OSTYPE"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
else
|
|
||||||
openim::log::error "Expected $OPENIM_MSGGATEWAY_NUM OpenIM msgtransfer processes, but found $NUM_PROCESSES msgtransfer processes running"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
function openim::msgtransfer::check_for_stop() {
|
|
||||||
PIDS=$(pgrep -f "${OPENIM_OUTPUT_HOSTBIN}/openim-msgtransfer") || PIDS="0"
|
|
||||||
if [ "$PIDS" = "0" ]; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
NUM_PROCESSES=$(echo "$PIDS" | wc -l | xargs)
|
|
||||||
|
|
||||||
if [ "$NUM_PROCESSES" -gt 0 ]; then
|
|
||||||
openim::log::error "Found $NUM_PROCESSES processes for $OPENIM_OUTPUT_HOSTBIN/openim-msgtransfer"
|
|
||||||
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
|
|
||||||
openim::log::error "Processes have not been stopped properly."
|
|
||||||
else
|
|
||||||
openim::log::success "All openim-msgtransfer processes have been stopped properly."
|
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
###################################### Linux Systemd ######################################
|
|
||||||
SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service"
|
|
||||||
|
|
||||||
# Print the necessary information after installation
|
|
||||||
function openim::msgtransfer::info() {
|
|
||||||
cat << EOF
|
|
||||||
openim-msgtransfer listen on: ${OPENIM_MSGTRANSFER_HOST}
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
|
|
||||||
# install openim-msgtransfer
|
|
||||||
function openim::msgtransfer::install() {
|
|
||||||
pushd "${OPENIM_ROOT}"
|
|
||||||
|
|
||||||
# 1. Build openim-msgtransfer
|
|
||||||
make build BINS=${SERVER_NAME}
|
|
||||||
|
|
||||||
openim::common::sudo "cp -r ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
|
|
||||||
openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/${SERVER_NAME}/${SERVER_NAME}"
|
|
||||||
|
|
||||||
openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/bin/${SERVER_NAME}"
|
|
||||||
|
|
||||||
# 2. Generate and install the openim-msgtransfer configuration file (openim-msgtransfer.yaml)
|
|
||||||
# nono
|
|
||||||
|
|
||||||
# 3. Create and install the ${SERVER_NAME} systemd unit file
|
|
||||||
echo ${LINUX_PASSWORD} | sudo -S bash -c \
|
|
||||||
"SERVER_NAME=${SERVER_NAME} ./scripts/genconfig.sh ${ENV_FILE} deployments/templates/openim.service > ${SYSTEM_FILE_PATH}"
|
|
||||||
openim::log::status "${SERVER_NAME} systemd file: ${SYSTEM_FILE_PATH}"
|
|
||||||
|
|
||||||
# 4. Start the openim-msgtransfer service
|
|
||||||
openim::common::sudo "systemctl daemon-reload"
|
|
||||||
openim::common::sudo "systemctl restart ${SERVER_NAME}"
|
|
||||||
openim::common::sudo "systemctl enable ${SERVER_NAME}"
|
|
||||||
openim::msgtransfer::status || return 1
|
|
||||||
openim::msgtransfer::info
|
|
||||||
|
|
||||||
openim::log::info "install ${SERVER_NAME} successfully"
|
|
||||||
popd
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Unload
|
|
||||||
function openim::msgtransfer::uninstall() {
|
|
||||||
set +o errexit
|
|
||||||
openim::common::sudo "systemctl stop ${SERVER_NAME}"
|
|
||||||
openim::common::sudo "systemctl disable ${SERVER_NAME}"
|
|
||||||
openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
|
|
||||||
openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
|
|
||||||
openim::common::sudo "rm -f /etc/systemd/system/${SERVER_NAME}.service"
|
|
||||||
|
|
||||||
openim::log::info "uninstall ${SERVER_NAME} successfully"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Status Check
|
|
||||||
function openim::msgtransfer::status() {
|
|
||||||
# Check the running status of the ${SERVER_NAME}. If active (running) is displayed, the ${SERVER_NAME} is started successfully.
|
|
||||||
if systemctl is-active --quiet "${SERVER_NAME}"; then
|
|
||||||
openim::log::info "${SERVER_NAME} is running successfully."
|
|
||||||
else
|
|
||||||
openim::log::error "${SERVER_NAME} failed to start, maybe not installed properly"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
if [[ "$*" =~ openim::msgtransfer:: ]];then
|
|
||||||
eval $*
|
|
||||||
fi
|
|
@ -1,150 +0,0 @@
|
|||||||
#!/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.
|
|
||||||
#
|
|
||||||
# OpenIM Push Control Script
|
|
||||||
#
|
|
||||||
# Description:
|
|
||||||
# This script provides a control interface for the OpenIM Push service within a Linux environment. It supports two installation methods: installation via function calls to systemctl, and direct installation through background processes.
|
|
||||||
#
|
|
||||||
# Features:
|
|
||||||
# 1. Robust error handling leveraging Bash built-ins such as 'errexit', 'nounset', and 'pipefail'.
|
|
||||||
# 2. Capability to source common utility functions and configurations, ensuring environmental consistency.
|
|
||||||
# 3. Comprehensive logging tools, offering clear operational insights.
|
|
||||||
# 4. Support for creating, managing, and interacting with Linux systemd services.
|
|
||||||
# 5. Mechanisms to verify the successful running of the service.
|
|
||||||
#
|
|
||||||
# Usage:
|
|
||||||
# 1. Direct Script Execution:
|
|
||||||
# This will start the OpenIM push directly through a background process.
|
|
||||||
# Example: ./openim-push.sh
|
|
||||||
#
|
|
||||||
# 2. Controlling through Functions for systemctl operations:
|
|
||||||
# Specific operations like installation, uninstallation, and status check can be executed by passing the respective function name as an argument to the script.
|
|
||||||
# Example: ./openim-push.sh openim::push::install
|
|
||||||
#
|
|
||||||
# ENVIRONMENT VARIABLES:
|
|
||||||
# export OPENIM_PUSH_BINARY="8080 8081 8082"
|
|
||||||
# export OPENIM_PUSH_PORT="9090 9091 9092"
|
|
||||||
#
|
|
||||||
# Note: Ensure that the appropriate permissions and environmental variables are set prior to script execution.
|
|
||||||
#
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
|
|
||||||
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
|
|
||||||
|
|
||||||
SERVER_NAME="openim-push"
|
|
||||||
|
|
||||||
function openim::push::start() {
|
|
||||||
|
|
||||||
rm -rf "$TMP_LOG_FILE"
|
|
||||||
|
|
||||||
openim::log::status "Start OpenIM Push, binary root: ${SERVER_NAME}"
|
|
||||||
openim::log::info "Start OpenIM Push, path: ${OPENIM_PUSH_BINARY}"
|
|
||||||
|
|
||||||
openim::log::status "prepare start push process, path: ${OPENIM_PUSH_BINARY}"
|
|
||||||
openim::log::status "prepare start push process, port: ${OPENIM_PUSH_PORT}, prometheus port: ${PUSH_PROM_PORT}"
|
|
||||||
|
|
||||||
OPENIM_PUSH_PORTS_ARRAY=$(openim::util::list-to-string ${OPENIM_PUSH_PORT} )
|
|
||||||
PUSH_PROM_PORTS_ARRAY=$(openim::util::list-to-string ${PUSH_PROM_PORT} )
|
|
||||||
|
|
||||||
openim::log::status "push port list: ${OPENIM_PUSH_PORTS_ARRAY[@]}"
|
|
||||||
openim::log::status "prometheus port list: ${PUSH_PROM_PORTS_ARRAY[@]}"
|
|
||||||
|
|
||||||
if [ ${#OPENIM_PUSH_PORTS_ARRAY[@]} -ne ${#PUSH_PROM_PORTS_ARRAY[@]} ]; then
|
|
||||||
openim::log::error "The length of the two port lists is different!"
|
|
||||||
fi
|
|
||||||
|
|
||||||
for (( i=0; i<${#OPENIM_PUSH_PORTS_ARRAY[@]}; i++ )); do
|
|
||||||
openim::log::info "start push process, port: ${OPENIM_PUSH_PORTS_ARRAY[$i]}, prometheus port: ${PUSH_PROM_PORTS_ARRAY[$i]}"
|
|
||||||
cmd="${OPENIM_PUSH_BINARY} --port ${OPENIM_PUSH_PORTS_ARRAY[$i]} -c ${OPENIM_PUSH_CONFIG} --prometheus_port ${PUSH_PROM_PORTS_ARRAY[$i]}"
|
|
||||||
#nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >/dev/null &
|
|
||||||
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >> "${LOG_FILE}" 2>&1 &
|
|
||||||
#nohup ${OPENIM_PUSH_BINARY} --port ${OPENIM_PUSH_PORTS_ARRAY[$i]} -c ${OPENIM_PUSH_CONFIG} --prometheus_port ${PUSH_PROM_PORTS_ARRAY[$i]} >> ${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE" >&2) &
|
|
||||||
done
|
|
||||||
return 0
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
###################################### Linux Systemd ######################################
|
|
||||||
SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service"
|
|
||||||
|
|
||||||
# Print the necessary information after installation
|
|
||||||
function openim::push::info() {
|
|
||||||
cat << EOF
|
|
||||||
openim-push listen on: ${OPENIM_PUSH_HOST}:${OPENIM_PUSH_PORT}
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
|
|
||||||
# install openim-push
|
|
||||||
function openim::push::install() {
|
|
||||||
pushd "${OPENIM_ROOT}"
|
|
||||||
|
|
||||||
# 1. Build openim-push
|
|
||||||
make build BINS=${SERVER_NAME}
|
|
||||||
openim::common::sudo "cp -r ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
|
|
||||||
openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/${SERVER_NAME}/${SERVER_NAME}"
|
|
||||||
|
|
||||||
# 2. Generate and install the openim-push configuration file (config)
|
|
||||||
openim::log::status "${SERVER_NAME} config file: ${OPENIM_CONFIG_DIR}/config.yaml"
|
|
||||||
|
|
||||||
# 3. Create and install the ${SERVER_NAME} systemd unit file
|
|
||||||
echo ${LINUX_PASSWORD} | sudo -S bash -c \
|
|
||||||
"SERVER_NAME=${SERVER_NAME} ./scripts/genconfig.sh ${ENV_FILE} deployments/templates/openim.service > ${SYSTEM_FILE_PATH}"
|
|
||||||
openim::log::status "${SERVER_NAME} systemd file: ${SYSTEM_FILE_PATH}"
|
|
||||||
|
|
||||||
# 4. Start the openim-push service
|
|
||||||
openim::common::sudo "systemctl daemon-reload"
|
|
||||||
openim::common::sudo "systemctl restart ${SERVER_NAME}"
|
|
||||||
openim::common::sudo "systemctl enable ${SERVER_NAME}"
|
|
||||||
openim::push::status || return 1
|
|
||||||
openim::push::info
|
|
||||||
|
|
||||||
openim::log::info "install ${SERVER_NAME} successfully"
|
|
||||||
popd
|
|
||||||
}
|
|
||||||
|
|
||||||
# Unload
|
|
||||||
function openim::push::uninstall() {
|
|
||||||
set +o errexit
|
|
||||||
openim::common::sudo "systemctl stop ${SERVER_NAME}"
|
|
||||||
openim::common::sudo "systemctl disable ${SERVER_NAME}"
|
|
||||||
openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
|
|
||||||
openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
|
|
||||||
openim::common::sudo "rm -f /etc/systemd/system/${SERVER_NAME}.service"
|
|
||||||
|
|
||||||
openim::log::info "uninstall ${SERVER_NAME} successfully"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Status Check
|
|
||||||
function openim::push::status() {
|
|
||||||
# Check the running status of the ${SERVER_NAME}. If active (running) is displayed, the ${SERVER_NAME} is started successfully.
|
|
||||||
systemctl status ${SERVER_NAME}|grep -q 'active' || {
|
|
||||||
openim::log::error "${SERVER_NAME} failed to start, maybe not installed properly"
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# The listening port is hardcode in the configuration file
|
|
||||||
if echo | telnet ${OPENIM_MSGGATEWAY_HOST} ${OPENIM_PUSH_PORT} 2>&1|grep refused &>/dev/null;then # Assuming a different port for push
|
|
||||||
openim::log::error "cannot access health check port, ${SERVER_NAME} maybe not startup"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
if [[ "$*" =~ openim::push:: ]];then
|
|
||||||
eval $*
|
|
||||||
fi
|
|
@ -1,254 +0,0 @@
|
|||||||
#!/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.
|
|
||||||
#
|
|
||||||
# OpenIM RPC Service Control Script
|
|
||||||
#
|
|
||||||
# Description:
|
|
||||||
# This script provides a control interface for the OpenIM RPC service within a Linux environment. It offers functionalities to start multiple RPC services, each denoted by their respective names under openim::rpc::service_name.
|
|
||||||
#
|
|
||||||
# Features:
|
|
||||||
# 1. Robust error handling using Bash built-ins like 'errexit', 'nounset', and 'pipefail'.
|
|
||||||
# 2. The capability to source common utility functions and configurations to ensure uniform environmental settings.
|
|
||||||
# 3. Comprehensive logging functionalities, providing a detailed understanding of operational processes.
|
|
||||||
# 4. Provision for declaring and managing a set of RPC services, each associated with its unique name and corresponding ports.
|
|
||||||
# 5. The ability to define and associate Prometheus ports for service monitoring purposes.
|
|
||||||
# 6. Functionalities to start each RPC service, along with its designated ports, in a sequence.
|
|
||||||
#
|
|
||||||
# Usage:
|
|
||||||
# 1. Direct Script Execution:
|
|
||||||
# This initiates all the RPC services declared under the function openim::rpc::service_name.
|
|
||||||
# Example: ./openim-rpc-{rpc-name}.sh openim::rpc::start
|
|
||||||
# 2. Controlling through Functions for systemctl operations:
|
|
||||||
# Specific operations like installation, uninstallation, and status check can be executed by passing the respective function name as an argument to the script.
|
|
||||||
# Example: ./openim-rpc-{rpc-name}.sh openim::rpc::install
|
|
||||||
#
|
|
||||||
# Note: Before executing this script, ensure that the necessary permissions are granted and relevant environmental variables are set.
|
|
||||||
#
|
|
||||||
|
|
||||||
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
|
|
||||||
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
|
|
||||||
|
|
||||||
SERVER_NAME="openim-rpc"
|
|
||||||
readonly OPENIM_RPC_CONFIG="${OPENIM_ROOT}"/config
|
|
||||||
|
|
||||||
openim::rpc::service_name() {
|
|
||||||
local targets=(
|
|
||||||
openim-rpc-user
|
|
||||||
openim-rpc-friend
|
|
||||||
openim-rpc-msg
|
|
||||||
openim-rpc-group
|
|
||||||
openim-rpc-auth
|
|
||||||
openim-rpc-conversation
|
|
||||||
openim-rpc-third
|
|
||||||
)
|
|
||||||
echo "${targets[@]}"
|
|
||||||
}
|
|
||||||
IFS=" " read -ra OPENIM_RPC_SERVICE_TARGETS <<< "$(openim::rpc::service_name)"
|
|
||||||
readonly OPENIM_RPC_SERVICE_TARGETS
|
|
||||||
readonly OPENIM_RPC_SERVICE_LISTARIES=("${OPENIM_RPC_SERVICE_TARGETS[@]##*/}")
|
|
||||||
|
|
||||||
|
|
||||||
OPENIM_ALL_RPC_FULL_PATH=()
|
|
||||||
for target in openim::rpc::service_name; do
|
|
||||||
OPENIM_ALL_RPC_FULL_PATH+=("${OPENIM_OUTPUT_HOSTBIN}/${target}")
|
|
||||||
done
|
|
||||||
readonly OPENIM_ALL_RPC_FULL_PATH
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Make sure the environment is only called via common to avoid too much nesting
|
|
||||||
openim::rpc::service_port() {
|
|
||||||
local targets=(
|
|
||||||
${OPENIM_USER_PORT} # User service 10110
|
|
||||||
${OPENIM_FRIEND_PORT} # Friend service 10120
|
|
||||||
${OPENIM_MESSAGE_PORT} # Message service 10130
|
|
||||||
# ${OPENIM_MESSAGE_GATEWAY_PORT} # Message gateway 10140
|
|
||||||
${OPENIM_GROUP_PORT} # Group service 10150
|
|
||||||
${OPENIM_AUTH_PORT} # Authorization service 10160
|
|
||||||
# ${OPENIM_PUSH_PORT} # Push service 10170
|
|
||||||
${OPENIM_CONVERSATION_PORT} # Conversation service 10180
|
|
||||||
${OPENIM_THIRD_PORT} # Third-party service 10190
|
|
||||||
)
|
|
||||||
echo "${targets[@]}"
|
|
||||||
}
|
|
||||||
IFS=" " read -ra OPENIM_RPC_PORT_TARGETS <<< "$(openim::rpc::service_port)"
|
|
||||||
readonly OPENIM_RPC_PORT_TARGETS
|
|
||||||
readonly OPENIM_RPC_PORT_LISTARIES=("${OPENIM_RPC_PORT_TARGETS[@]##*/}")
|
|
||||||
|
|
||||||
openim::rpc::prometheus_port() {
|
|
||||||
# Declare an array to hold all the Prometheus ports for different services
|
|
||||||
local targets=(
|
|
||||||
${USER_PROM_PORT} # Prometheus port for user service
|
|
||||||
${FRIEND_PROM_PORT} # Prometheus port for friend service
|
|
||||||
${MESSAGE_PROM_PORT} # Prometheus port for message service
|
|
||||||
${GROUP_PROM_PORT} # Prometheus port for group service
|
|
||||||
${AUTH_PROM_PORT} # Prometheus port for authentication service
|
|
||||||
${CONVERSATION_PROM_PORT} # Prometheus port for conversation service
|
|
||||||
${THIRD_PROM_PORT} # Prometheus port for third-party integrations service
|
|
||||||
)
|
|
||||||
# Print the list of ports
|
|
||||||
echo "${targets[@]}"
|
|
||||||
}
|
|
||||||
IFS=" " read -ra OPENIM_RPC_PROM_PORT_TARGETS <<< "$(openim::rpc::prometheus_port)"
|
|
||||||
readonly OPENIM_RPC_PROM_PORT_TARGETS
|
|
||||||
readonly OPENIM_RPC_PROM_PORT_LISTARIES=("${OPENIM_RPC_PROM_PORT_TARGETS[@]##*/}")
|
|
||||||
|
|
||||||
function openim::rpc::start() {
|
|
||||||
rm -rf "$TMP_LOG_FILE"
|
|
||||||
|
|
||||||
echo "OPENIM_RPC_SERVICE_LISTARIES: ${OPENIM_RPC_SERVICE_LISTARIES[@]}"
|
|
||||||
echo "OPENIM_RPC_PROM_PORT_LISTARIES: ${OPENIM_RPC_PROM_PORT_LISTARIES[@]}"
|
|
||||||
echo "OPENIM_RPC_PORT_LISTARIES: ${OPENIM_RPC_PORT_LISTARIES[@]}"
|
|
||||||
|
|
||||||
openim::log::info "Starting ${SERVER_NAME} ..."
|
|
||||||
|
|
||||||
printf "+------------------------+-------+-----------------+\n"
|
|
||||||
printf "| Service Name | Port | Prometheus Port |\n"
|
|
||||||
printf "+------------------------+-------+-----------------+\n"
|
|
||||||
|
|
||||||
length=${#OPENIM_RPC_SERVICE_LISTARIES[@]}
|
|
||||||
|
|
||||||
for ((i=0; i<$length; i++)); do
|
|
||||||
printf "| %-22s | %-5s | %-15s |\n" "${OPENIM_RPC_SERVICE_LISTARIES[$i]}" "${OPENIM_RPC_PORT_LISTARIES[$i]}" "${OPENIM_RPC_PROM_PORT_LISTARIES[$i]}"
|
|
||||||
printf "+------------------------+-------+-----------------+\n"
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
# start all rpc services
|
|
||||||
for ((i = 0; i < ${#OPENIM_RPC_SERVICE_LISTARIES[*]}; i++)); do
|
|
||||||
|
|
||||||
openim::log::info "OpenIM ${OPENIM_RPC_SERVICE_LISTARIES[$i]} config path: ${OPENIM_RPC_CONFIG}"
|
|
||||||
# Get the service and Prometheus ports.
|
|
||||||
OPENIM_RPC_SERVICE_PORTS=( $(openim::util::list-to-string ${OPENIM_RPC_PORT_LISTARIES[$i]}) )
|
|
||||||
read -a OPENIM_RPC_SERVICE_PORTS_ARRAY <<< ${OPENIM_RPC_SERVICE_PORTS}
|
|
||||||
|
|
||||||
OPENIM_RPC_PROM_PORTS=( $(openim::util::list-to-string ${OPENIM_RPC_PROM_PORT_LISTARIES[$i]}) )
|
|
||||||
read -a OPENIM_RPC_PROM_PORTS_ARRAY <<< ${OPENIM_RPC_PROM_PORTS}
|
|
||||||
|
|
||||||
for ((j = 0; j < ${#OPENIM_RPC_SERVICE_PORTS_ARRAY[@]}; j++)); do
|
|
||||||
openim::log::info "Starting ${OPENIM_RPC_SERVICE_LISTARIES[$i]} service, port: ${OPENIM_RPC_SERVICE_PORTS[j]}, prometheus port: ${OPENIM_RPC_PROM_PORTS[j]}, binary root: ${OPENIM_OUTPUT_HOSTBIN}/${OPENIM_RPC_SERVICE_LISTARIES[$i]}"
|
|
||||||
result=$(openim::rpc::start_service "${OPENIM_RPC_SERVICE_LISTARIES[$i]}" "${OPENIM_RPC_SERVICE_PORTS[j]}" "${OPENIM_RPC_PROM_PORTS[j]}")
|
|
||||||
if [[ $? -ne 0 ]]; then
|
|
||||||
openim::log::error "start ${SERVER_NAME} failed"
|
|
||||||
else
|
|
||||||
openim::log::info "$result"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
function openim::rpc::start_service() {
|
|
||||||
local binary_name="$1"
|
|
||||||
local service_port="$2"
|
|
||||||
local prometheus_port="$3"
|
|
||||||
|
|
||||||
local cmd="${OPENIM_OUTPUT_HOSTBIN}/${binary_name} --port ${service_port} -c ${OPENIM_RPC_CONFIG}"
|
|
||||||
|
|
||||||
if [ -n "${prometheus_port}" ]; then
|
|
||||||
printf "Specifying prometheus port: %s\n" "${prometheus_port}"
|
|
||||||
cmd="${cmd} --prometheus_port ${prometheus_port}"
|
|
||||||
fi
|
|
||||||
#nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE" >&2) &
|
|
||||||
#nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >/dev/null &
|
|
||||||
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >> "${LOG_FILE}" 2>&1 &
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
###################################### Linux Systemd ######################################
|
|
||||||
declare -A SYSTEM_FILE_PATHS
|
|
||||||
for service in "${OPENIM_RPC_SERVICE_LISTARIES[@]}"; do
|
|
||||||
SYSTEM_FILE_PATHS["$service"]="/etc/systemd/system/${service}.service"
|
|
||||||
done
|
|
||||||
|
|
||||||
# Print the necessary information after installation
|
|
||||||
function openim::rpc::info() {
|
|
||||||
for service in "${OPENIM_RPC_SERVICE_LISTARIES[@]}"; do
|
|
||||||
echo "${service} listen on: ${OPENIM_RPC_PORT_LISTARIES[@]}"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# install openim-rpc
|
|
||||||
function openim::rpc::install() {
|
|
||||||
pushd "${OPENIM_ROOT}"
|
|
||||||
|
|
||||||
# 1. Build openim-rpc
|
|
||||||
for service in "${OPENIM_RPC_SERVICE_LISTARIES[@]}"; do
|
|
||||||
make build BINS=${service}
|
|
||||||
openim::common::sudo "cp -r ${OPENIM_OUTPUT_HOSTBIN}/${service} ${OPENIM_INSTALL_DIR}/${service}"
|
|
||||||
openim::log::status "${service} binary: ${OPENIM_INSTALL_DIR}/${service}/${service}"
|
|
||||||
done
|
|
||||||
|
|
||||||
# 2. Generate and install the openim-rpc configuration file (config)
|
|
||||||
openim::log::status "openim-rpc config file: ${OPENIM_CONFIG_DIR}/config.yaml"
|
|
||||||
|
|
||||||
# 3. Create and install the systemd unit files
|
|
||||||
for service in "${OPENIM_RPC_SERVICE_LISTARIES[@]}"; do
|
|
||||||
echo ${LINUX_PASSWORD} | sudo -S bash -c \
|
|
||||||
"SERVER_NAME=${service} ./scripts/genconfig.sh ${ENV_FILE} deployments/templates/openim.service > ${SYSTEM_FILE_PATHS[$service]}"
|
|
||||||
openim::log::status "${service} systemd file: ${SYSTEM_FILE_PATHS[$service]}"
|
|
||||||
done
|
|
||||||
|
|
||||||
# 4. Start the openim-rpc services
|
|
||||||
openim::common::sudo "systemctl daemon-reload"
|
|
||||||
for service in "${OPENIM_RPC_SERVICE_LISTARIES[@]}"; do
|
|
||||||
openim::common::sudo "systemctl restart ${service}"
|
|
||||||
openim::common::sudo "systemctl enable ${service}"
|
|
||||||
done
|
|
||||||
openim::rpc::status || return 1
|
|
||||||
openim::rpc::info
|
|
||||||
|
|
||||||
openim::log::info "install openim-rpc successfully"
|
|
||||||
popd
|
|
||||||
}
|
|
||||||
|
|
||||||
# Unload
|
|
||||||
function openim::rpc::uninstall() {
|
|
||||||
set +o errexit
|
|
||||||
for service in "${OPENIM_RPC_SERVICE_LISTARIES[@]}"; do
|
|
||||||
openim::common::sudo "systemctl stop ${service}"
|
|
||||||
openim::common::sudo "systemctl disable ${service}"
|
|
||||||
openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/${service}"
|
|
||||||
openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${service}.yaml"
|
|
||||||
openim::common::sudo "rm -f ${SYSTEM_FILE_PATHS[$service]}"
|
|
||||||
done
|
|
||||||
|
|
||||||
openim::log::info "uninstall openim-rpc successfully"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Status Check
|
|
||||||
function openim::rpc::status() {
|
|
||||||
for service in "${OPENIM_RPC_SERVICE_LISTARIES[@]}"; do
|
|
||||||
# Check the running status of the ${service}. If active (running) is displayed, the ${service} is started successfully.
|
|
||||||
systemctl status ${service}|grep -q 'active' || {
|
|
||||||
openim::log::error "${service} failed to start, maybe not installed properly"
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# The listening port is hardcoded in the configuration file
|
|
||||||
if echo | telnet ${OPENIM_MSGGATEWAY_HOST} ${OPENIM_RPC_PORT_LISTARIES[@]} 2>&1|grep refused &>/dev/null;then
|
|
||||||
openim::log::error "cannot access health check port, ${service} maybe not startup"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
if [[ "$*" =~ openim::rpc:: ]];then
|
|
||||||
eval $*
|
|
||||||
fi
|
|
@ -1,179 +0,0 @@
|
|||||||
#!/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.
|
|
||||||
#
|
|
||||||
# OpenIM Tools Control Script
|
|
||||||
#
|
|
||||||
# Description:
|
|
||||||
# This script is responsible for managing the lifecycle of OpenIM tools, which include starting, stopping,
|
|
||||||
# and handling pre and post operations. It's designed to be modular and extensible, ensuring that the
|
|
||||||
# individual operations can be managed separately, and integrated seamlessly with Linux systemd.
|
|
||||||
#
|
|
||||||
# Features:
|
|
||||||
# 1. Robust error handling using Bash built-ins like 'errexit', 'nounset', and 'pipefail'.
|
|
||||||
# 2. The capability to source common utility functions and configurations to ensure uniform environmental settings.
|
|
||||||
# 3. Comprehensive logging functionalities, providing a detailed understanding of operational processes.
|
|
||||||
# 4. Provision for declaring and managing a set of OpenIM tools, each associated with its unique name and corresponding ports.
|
|
||||||
# 5. The ability to define and associate Prometheus ports for service monitoring purposes.
|
|
||||||
# 6. Functionalities to start each OpenIM tool, along with its designated ports, in a sequence.
|
|
||||||
#
|
|
||||||
# Usage:
|
|
||||||
# 1. Direct Script Execution:
|
|
||||||
# This initiates all the OpenIM tools declared under the function openim::tools::service_name.
|
|
||||||
# Example: ./openim-tools.sh openim::tools::start
|
|
||||||
# 2. Controlling through Functions for systemctl operations:
|
|
||||||
# Specific operations like installation, uninstallation, and status check can be executed by passing the respective function name as an argument to the script.
|
|
||||||
# Example: ./openim-tools.sh openim::tools::install
|
|
||||||
#
|
|
||||||
|
|
||||||
|
|
||||||
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
|
|
||||||
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
|
|
||||||
|
|
||||||
SERVER_NAME="openim-tools"
|
|
||||||
|
|
||||||
openim::tools::start_name() {
|
|
||||||
local targets=(
|
|
||||||
imctl
|
|
||||||
)
|
|
||||||
echo "${targets[@]}"
|
|
||||||
}
|
|
||||||
IFS=" " read -ra OPENIM_TOOLS_NAME_TARGETS <<< "$(openim::tools::start_name)"
|
|
||||||
readonly OPENIM_TOOLS_NAME_TARGETS
|
|
||||||
readonly OPENIM_TOOLS_NAME_LISTARIES=("${OPENIM_TOOLS_NAME_TARGETS[@]##*/}")
|
|
||||||
|
|
||||||
openim::tools::pre_start_name() {
|
|
||||||
local targets=(
|
|
||||||
ncpu
|
|
||||||
component
|
|
||||||
)
|
|
||||||
echo "${targets[@]}"
|
|
||||||
}
|
|
||||||
IFS=" " read -ra OPENIM_TOOLS_PRE_START_NAME_TARGETS <<< "$(openim::tools::pre_start_name)"
|
|
||||||
readonly OPENIM_TOOLS_PRE_START_NAME_TARGETS
|
|
||||||
readonly OPENIM_TOOLS_PRE_START_NAME_LISTARIES=("${OPENIM_TOOLS_PRE_START_NAME_TARGETS[@]##*/}")
|
|
||||||
|
|
||||||
openim::tools::post_start_name() {
|
|
||||||
local targets=(
|
|
||||||
infra
|
|
||||||
versionchecker
|
|
||||||
)
|
|
||||||
echo "${targets[@]}"
|
|
||||||
}
|
|
||||||
IFS=" " read -ra OPENIM_TOOLS_POST_START_NAME_TARGETS <<< "$(openim::tools::post_start_name)"
|
|
||||||
readonly OPENIM_TOOLS_POST_START_NAME_TARGETS
|
|
||||||
readonly OPENIM_TOOLS_POST_START_NAME_LISTARIES=("${OPENIM_TOOLS_POST_START_NAME_TARGETS[@]##*/}")
|
|
||||||
|
|
||||||
function openim::tools::start_service() {
|
|
||||||
local binary_name="$1"
|
|
||||||
local config="$2"
|
|
||||||
local service_port="$3"
|
|
||||||
local prometheus_port="$4"
|
|
||||||
|
|
||||||
local cmd="${OPENIM_OUTPUT_HOSTBIN_TOOLS}/${binary_name}"
|
|
||||||
#openim::log::info "Starting PATH: ${OPENIM_OUTPUT_HOSTBIN_TOOLS}/${binary_name}..."
|
|
||||||
|
|
||||||
if [ -n "${config}" ]; then
|
|
||||||
# printf "Specifying config: %s\n" "${config}"
|
|
||||||
cmd="${cmd} -c ${config}/config.yaml"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "${service_port}" ]; then
|
|
||||||
#printf "Specifying service port: %s\n" "${service_port}"
|
|
||||||
cmd="${cmd} --port ${service_port}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "${prometheus_port}" ]; then
|
|
||||||
#printf "Specifying prometheus port: %s\n" "${prometheus_port}"
|
|
||||||
cmd="${cmd} --prometheus_port ${prometheus_port}"
|
|
||||||
fi
|
|
||||||
#openim::log::status "Starting binary ${binary_name}..."
|
|
||||||
|
|
||||||
|
|
||||||
# openim::log::info "cmd: $cmd"
|
|
||||||
${cmd}
|
|
||||||
|
|
||||||
|
|
||||||
local status=$?
|
|
||||||
if [ $status -eq 0 ]; then
|
|
||||||
openim::log::colorless "Service ${binary_name} started successfully."
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
openim::log::error "Failed to start service ${binary_name}."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function openim::tools::start() {
|
|
||||||
openim::log::info "Starting OpenIM Tools..."
|
|
||||||
for tool in "${OPENIM_TOOLS_NAME_LISTARIES[@]}"; do
|
|
||||||
openim::log::colorless "Starting tool ${tool}..."
|
|
||||||
# openim::tools::start_service ${tool}
|
|
||||||
#sleep 0.2
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function openim::tools::pre-start() {
|
|
||||||
#openim::log::info "Preparing to start OpenIM Tools..."
|
|
||||||
for tool in "${OPENIM_TOOLS_PRE_START_NAME_LISTARIES[@]}"; do
|
|
||||||
openim::log::colorless "Starting tool: ${tool}"
|
|
||||||
if ! openim::tools::start_service ${tool} ${OPNEIM_CONFIG}; then
|
|
||||||
openim::log::error "Failed to start ${tool}, aborting..."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
#openim::log::info "All tools started successfully."
|
|
||||||
}
|
|
||||||
|
|
||||||
function openim::tools::post-start() {
|
|
||||||
#openim::log::info "Post-start actions for OpenIM Tools..."
|
|
||||||
for tool in "${OPENIM_TOOLS_POST_START_NAME_LISTARIES[@]}"; do
|
|
||||||
openim::log::colorless "Starting tool: ${tool}"
|
|
||||||
openim::tools::start_service ${tool}
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
function openim::tools::stop() {
|
|
||||||
openim::log::info "Stopping OpenIM Tools..."
|
|
||||||
for tool in "${OPENIM_TOOLS_NAME_LISTARIES[@]}"; do
|
|
||||||
openim::log::info "Stopping ${tool}..."
|
|
||||||
# Similarly, place the actual command to stop the tool here.
|
|
||||||
echo "Stopping service for ${tool}"
|
|
||||||
sleep 0.2
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
function openim::tools::pre-stop() {
|
|
||||||
openim::log::info "Preparing to stop OpenIM Tools..."
|
|
||||||
for tool in "${OPENIM_TOOLS_PRE_START_NAME_LISTARIES[@]}"; do
|
|
||||||
openim::log::info "Setting up pre-stop for ${tool}..."
|
|
||||||
echo "Pre-stop actions for ${tool}"
|
|
||||||
sleep 0.2
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
function openim::tools::post-stop() {
|
|
||||||
openim::log::info "Post-stop actions for OpenIM Tools..."
|
|
||||||
for tool in "${OPENIM_TOOLS_POST_START_NAME_LISTARIES[@]}"; do
|
|
||||||
openim::log::info "Executing post-stop for ${tool}..."
|
|
||||||
echo "Post-stop cleanup for ${tool}"
|
|
||||||
sleep 0.2
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
if [[ "$*" =~ openim::tools:: ]];then
|
|
||||||
eval $*
|
|
||||||
fi
|
|
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue