mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-04-28 06:19:20 +08:00
✨Large refactoring projects: OpenIM automation, scripting, and openimctl refactoring (#825)
* fix: fix bin tools path Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: fix golang release file path Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: fix golang release file path Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: fix scripts and optimize Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: fix scripts path module Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: sync script code Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add lib and start scripts Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * ci: add copyright scripts Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * ci: add go-docs file and copyright scripts Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add scripts cross ower Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * style: Formatting code make lint path Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * style: Formatting code make lint path Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * style: Formatting code make lint path Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * style: Formatting code make lint path Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: chat scripts path bug Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: channge smail images Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add makefile feature Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add config and images log Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * style: Migrate directory to remove docker to images Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * style: formatting style Code Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: set opneim's bash logs Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: option scripts and docs Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add git cherry Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add git cherry Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: save all bash and docs labels Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: scripts feature extend Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add config path config Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add config path config Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add feat scripts Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add save scripts Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add save scripts Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add sctips help Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add start sctips help Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: save scripts file Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: save all file Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add openim server template file Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add alot of system design Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: save all file Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: save all file Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add env config options Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more robot details Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more module explain Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add scripts environment details design Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add openim msgtransfer scripts Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add openim msgtransfer scripts Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more design scripts Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add file save Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add file save Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add rpc build and start Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add rpc build and start Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add rpc build and start Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: save all images file Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add scripts set Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add test options Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: fix config path file Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: update config file Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: update config file Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: update config file Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: update config file Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add readme docs Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: save build scripts Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add all actions file Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add chat scripts name Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add all compose Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: commit tag Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: save server code Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add docker compose fix Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add docker compose fix Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add docker compose fix Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: save server code Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: optimize dockerfile option Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: optimize dockerfile option Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: optimize dockerfile option Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add all options Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add all options Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more scrips Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more options Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add more options Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add config path Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: Add some optimizations Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: Add some optimizations Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: delele go work sum Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: delele go work sum Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * Delete go.work.sum * feat: delele go work sum Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * Update .env * feat: delele go work sum Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: delele go work sum Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: delele go work sum Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: delele go work sum Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add docker compose fix Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add docker compose fix Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: delele go work sum Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> --------- Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
CHANGELOG
|
||||
go.mod
|
||||
go.sum
|
||||
third_party/
|
||||
translations/
|
||||
log
|
||||
+194
-15
@@ -1,5 +1,26 @@
|
||||
# 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)
|
||||
- [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
|
||||
@@ -9,19 +30,19 @@ scripts/
|
||||
│ └── LICENSE_TEMPLATES # Template for license file
|
||||
├── README.md # Readme file for scripts directory
|
||||
├── advertise.sh # Script for advertisement services
|
||||
├── batch_start_all.sh # Script to start all services in batch
|
||||
├── batch_start-all.sh # Script to start all services in batch
|
||||
├── build.cmd # Windows build command script
|
||||
├── build_all_service.sh # Script to build all services
|
||||
├── build-all-service.sh # Script to build all services
|
||||
├── build_push_k8s_images.sh # Script to build and push images for Kubernetes
|
||||
├── check_all.sh # Script to check status of all services
|
||||
├── check-all.sh # Script to check status of all services
|
||||
├── common.sh # Contains common functions used by other scripts
|
||||
├── coverage.awk # AWK script for coverage report generation
|
||||
├── coverage.sh # Script for generating coverage reports
|
||||
├── docker_check_service.sh # Docker specific service check script
|
||||
├── docker_start_all.sh # Script to start all services in a docker environment
|
||||
├── docker-check-service.sh # Docker specific service check script
|
||||
├── docker-start-all-all.sh # Script to start all services in a docker environment
|
||||
├── ensure_tag.sh # Script to ensure proper tagging of docker images
|
||||
├── enterprise # Scripts specific to enterprise version
|
||||
│ ├── check_all.sh # Check status of all enterprise services
|
||||
│ ├── check-all.sh # Check status of all enterprise services
|
||||
│ ├── function.sh # Functions specific to enterprise version
|
||||
│ └── path_info.cfg # Path information configuration for enterprise version
|
||||
├── env_check.sh # Script to check the environment
|
||||
@@ -32,7 +53,7 @@ scripts/
|
||||
│ └── pre-push # Script to run before each push
|
||||
├── init_pwd.sh # Script to initialize password
|
||||
├── install_im_compose.sh # Script to install IM with Docker Compose
|
||||
├── install_im_server.sh # Script to install IM server
|
||||
├── install-im-server.sh # Script to install IM server
|
||||
├── lib # Library scripts
|
||||
│ ├── color.sh # Script for console color manipulation
|
||||
│ ├── golang.sh # Script for golang related utility functions
|
||||
@@ -52,15 +73,15 @@ scripts/
|
||||
│ ├── swagger.mk # Make rules for swagger documentation
|
||||
│ └── tools.mk # Make rules for tools and utilities
|
||||
├── mongo-init.sh # Script to initialize MongoDB
|
||||
├── msg_gateway_start.sh # Script to start message gateway service
|
||||
├── msg_transfer_start.sh # Script to start message transfer service
|
||||
├── openim-msggateway.sh # Script to start message gateway service
|
||||
├── openim-msgtransfer.sh # Script to start message transfer service
|
||||
├── path_info.sh # Script containing path information
|
||||
├── push_start.sh # Script to start push service
|
||||
├── openim-push.sh # Script to start push service
|
||||
├── release.sh # Script to perform release process
|
||||
├── start_all.sh # Script to start all services
|
||||
├── start_cron.sh # Script to start cron jobs
|
||||
├── start_rpc_service.sh # Script to start RPC service
|
||||
├── stop_all.sh # Script to stop all services
|
||||
├── start-all.sh # Script to start all services
|
||||
├── openim-crontask.sh # Script to start cron jobs
|
||||
├── openim-rpc.sh # Script to start RPC service
|
||||
├── stop-all.sh # Script to stop all services
|
||||
└── style_info.sh # Script containing style related information
|
||||
```
|
||||
|
||||
@@ -68,6 +89,13 @@ The purpose of having a structured scripts directory like this is to make the op
|
||||
|
||||
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/conversions/bash_log.md)
|
||||
|
||||
## Supported platforms
|
||||
|
||||
- Linux x86_64 (linux_amd64) : 64-bit Linux for most desktop and server systems.
|
||||
@@ -84,11 +112,162 @@ Each directory and script in the structure should be understood as a part of a l
|
||||
|
||||
- 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/conversions/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
|
||||
```
|
||||
|
||||
|
||||
## 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:
|
||||
|
||||
+10
-34
@@ -13,61 +13,36 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
trap 'echo "Script interrupted."; exit 1' INT
|
||||
. $(dirname ${BASH_SOURCE})/lib/init.sh
|
||||
|
||||
# Function for colored echo
|
||||
function color_echo() {
|
||||
COLOR=$1
|
||||
shift
|
||||
echo -e "${COLOR}===> $* ${COLOR_SUFFIX}"
|
||||
}
|
||||
trap 'openim::util::onCtrlC' INT
|
||||
|
||||
# Color definitions
|
||||
function openim_color() {
|
||||
COLOR_SUFFIX="\033[0m" # End all colors and special effects
|
||||
|
||||
BLACK_PREFIX="\033[30m" # Black prefix
|
||||
RED_PREFIX="\033[31m" # Red prefix
|
||||
GREEN_PREFIX="\033[32m" # Green prefix
|
||||
YELLOW_PREFIX="\033[33m" # Yellow prefix
|
||||
BLUE_PREFIX="\033[34m" # Blue prefix
|
||||
SKY_BLUE_PREFIX="\033[36m" # Sky blue prefix
|
||||
WHITE_PREFIX="\033[37m" # White prefix
|
||||
BOLD_PREFIX="\033[1m" # Bold prefix
|
||||
UNDERLINE_PREFIX="\033[4m" # Underline prefix
|
||||
ITALIC_PREFIX="\033[3m" # Italic prefix
|
||||
|
||||
CYAN_PREFIX="\033[0;36m" # Cyan prefix
|
||||
}
|
||||
|
||||
function print_with_delay() {
|
||||
print_with_delay() {
|
||||
text="$1"
|
||||
delay="$2"
|
||||
color="$3"
|
||||
|
||||
for i in $(seq 0 $((${#text}-1))); do
|
||||
printf "${color}${text:$i:1}${COLOR_SUFFIX}"
|
||||
printf "${text:$i:1}"
|
||||
sleep $delay
|
||||
done
|
||||
printf "\n"
|
||||
}
|
||||
|
||||
function print_progress() {
|
||||
print_progress() {
|
||||
total="$1"
|
||||
delay="$2"
|
||||
color="$3"
|
||||
|
||||
printf "${color}["
|
||||
printf "["
|
||||
for i in $(seq 1 $total); do
|
||||
printf "#"
|
||||
sleep $delay
|
||||
done
|
||||
printf "]${COLOR_SUFFIX}\n"
|
||||
printf "]\n"
|
||||
}
|
||||
|
||||
function openim_logo() {
|
||||
# Set text color to cyan for header and URL
|
||||
echo -e "\033[0;36m"
|
||||
@@ -114,7 +89,8 @@ O:::::::OOO:::::::O p:::::ppppp:::::::pe::::::::e n::::n n::::nII:
|
||||
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, 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_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
|
||||
|
||||
|
||||
+11
-16
@@ -16,26 +16,21 @@
|
||||
#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
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
source $SCRIPTS_ROOT/style_info.sh
|
||||
source $SCRIPTS_ROOT/path_info.sh
|
||||
source $SCRIPTS_ROOT/function.sh
|
||||
|
||||
cd $SCRIPTS_ROOT
|
||||
|
||||
echo -e "${YELLOW_PREFIX}=======>SCRIPTS_ROOT=$SCRIPTS_ROOT${COLOR_SUFFIX}"
|
||||
echo -e "${YELLOW_PREFIX}=======>OPENIM_ROOT=$OPENIM_ROOT${COLOR_SUFFIX}"
|
||||
echo -e "${YELLOW_PREFIX}=======>pwd=$PWD${COLOR_SUFFIX}"
|
||||
trap 'openim::util::onCtrlC' INT
|
||||
|
||||
need_to_start_server_shell=(
|
||||
"start_rpc_service.sh"
|
||||
"msg_gateway_start.sh"
|
||||
"push_start.sh"
|
||||
"msg_transfer_start.sh"
|
||||
"oepnim-api.sh"
|
||||
"openim-rpc.sh"
|
||||
"openim-msggateway.sh"
|
||||
"openim-push.sh"
|
||||
"openim-msgtransfer.sh"
|
||||
)
|
||||
|
||||
time=$(date +"%Y-%m-%d %H:%M:%S")
|
||||
|
||||
Executable
+78
@@ -0,0 +1,78 @@
|
||||
#!/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: `hack/build-go.sh WHAT=cmd/kubelet`.
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
||||
|
||||
# CPU core number
|
||||
# Check the system type
|
||||
system_type=$(uname)
|
||||
|
||||
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,151 +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.
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
source $SCRIPTS_ROOT/style_info.sh
|
||||
source $SCRIPTS_ROOT/path_info.sh
|
||||
source $SCRIPTS_ROOT/function.sh
|
||||
|
||||
echo -e "${YELLOW_PREFIX}=======>SCRIPTS_ROOT=$SCRIPTS_ROOT${COLOR_SUFFIX}"
|
||||
echo -e "${YELLOW_PREFIX}=======>OPENIM_ROOT=$OPENIM_ROOT${COLOR_SUFFIX}"
|
||||
echo -e "${YELLOW_PREFIX}=======>pwd=$PWD${COLOR_SUFFIX}"
|
||||
|
||||
echo -e ""
|
||||
|
||||
echo -e "${BACKGROUND_BLUE}===============> Building all using make build binary files ${COLOR_SUFFIX}"
|
||||
|
||||
echo -e ""
|
||||
echo -e "${BOLD_PREFIX}____________________________________________________________ ${COLOR_SUFFIX}"
|
||||
|
||||
|
||||
bin_dir="$BIN_DIR"
|
||||
logs_dir="$OPENIM_ROOT/logs"
|
||||
sdk_db_dir="$OPENIM_ROOT/db/sdk/"
|
||||
|
||||
echo "==> bin_dir=$bin_dir"
|
||||
echo "==> logs_dir=$logs_dir"
|
||||
echo "==> sdk_db_dir=$sdk_db_dir"
|
||||
|
||||
# Automatically created when there is no bin, logs folder
|
||||
if [ ! -d $logs_dir ]; then
|
||||
mkdir -p $logs_dir
|
||||
fi
|
||||
if [ ! -d $sdk_db_dir ]; then
|
||||
mkdir -p $sdk_db_dir
|
||||
fi
|
||||
|
||||
cd $OPENIM_ROOT
|
||||
|
||||
# CPU core number
|
||||
# Check the system type
|
||||
system_type=$(uname)
|
||||
|
||||
if [[ "$system_type" == "Darwin" ]]; then
|
||||
# macOS (using sysctl)
|
||||
cpu_count=$(sysctl -n hw.ncpu)
|
||||
elif [[ "$system_type" == "Linux" ]]; then
|
||||
# Linux (using lscpu)
|
||||
cpu_count=$(lscpu --parse | grep -E '^([^#].*,){3}[^#]' | sort -u | wc -l)
|
||||
else
|
||||
echo "Unsupported operating system: $system_type"
|
||||
exit 1
|
||||
fi
|
||||
echo -e "${GREEN_PREFIX}======> cpu_count=$cpu_count${COLOR_SUFFIX}"
|
||||
|
||||
# Count the number of concurrent compilations (half the number of cpus)
|
||||
compile_count=$((cpu_count / 2))
|
||||
|
||||
# Execute 'make build' run the make command for concurrent compilation
|
||||
make -j$compile_count build
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "make build Error, script exits"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get the current operating system and architecture
|
||||
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
|
||||
ARCH=$(uname -m)
|
||||
|
||||
# Select the repository home directory based on the operating system and architecture
|
||||
if [[ "$OS" == "darwin" ]]; then
|
||||
if [[ "$ARCH" == "x86_64" ]]; then
|
||||
REPO_DIR="darwin/amd64"
|
||||
else
|
||||
REPO_DIR="darwin/386"
|
||||
fi
|
||||
elif [[ "$OS" == "linux" ]]; then
|
||||
if [[ "$ARCH" == "x86_64" ]]; then
|
||||
REPO_DIR="linux/amd64"
|
||||
elif [[ "$ARCH" == "arm64" ]]; then
|
||||
REPO_DIR="linux/arm64"
|
||||
elif [[ "$ARCH" == "mips64" ]]; then
|
||||
REPO_DIR="linux/mips64"
|
||||
elif [[ "$ARCH" == "mips64le" ]]; then
|
||||
REPO_DIR="linux/mips64le"
|
||||
elif [[ "$ARCH" == "ppc64le" ]]; then
|
||||
REPO_DIR="linux/ppc64le"
|
||||
elif [[ "$ARCH" == "s390x" ]]; then
|
||||
REPO_DIR="linux/s390x"
|
||||
else
|
||||
REPO_DIR="linux/386"
|
||||
fi
|
||||
elif [[ "$OS" == "windows" ]]; then
|
||||
if [[ "$ARCH" == "x86_64" ]]; then
|
||||
REPO_DIR="windows/amd64"
|
||||
else
|
||||
REPO_DIR="windows/386"
|
||||
fi
|
||||
else
|
||||
echo -e "${RED_PREFIX}Unsupported OS: $OS${COLOR_SUFFIX}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Determine if all scripts were successfully built
|
||||
BUILD_SUCCESS=true
|
||||
FAILED_SCRIPTS=()
|
||||
|
||||
for binary in $(find _output/bin/platforms/$REPO_DIR -type f); do
|
||||
if [[ ! -x $binary ]]; then
|
||||
FAILED_SCRIPTS+=("$binary")
|
||||
BUILD_SUCCESS=false
|
||||
fi
|
||||
done
|
||||
|
||||
echo -e " "
|
||||
|
||||
echo -e "${BOLD_PREFIX}=====================> Build Results <=====================${COLOR_SUFFIX}"
|
||||
|
||||
echo -e " "
|
||||
|
||||
if [[ "$BUILD_SUCCESS" == true ]]; then
|
||||
echo -e "${GREEN_PREFIX}All binaries built successfully.${COLOR_SUFFIX}"
|
||||
else
|
||||
echo -e "${RED_PREFIX}Some binary builds failed. Please check the following binary files:${COLOR_SUFFIX}"
|
||||
for script in "${FAILED_SCRIPTS[@]}"; do
|
||||
echo -e "${RED_PREFIX}$script${COLOR_SUFFIX}"
|
||||
done
|
||||
fi
|
||||
|
||||
echo -e " "
|
||||
|
||||
echo -e "${BOLD_PREFIX}============================================================${COLOR_SUFFIX}"
|
||||
|
||||
echo -e " "
|
||||
@@ -1,46 +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.
|
||||
|
||||
version=errcode
|
||||
repository=${1}
|
||||
if [[ -z ${repository} ]]
|
||||
then
|
||||
echo "repository is empty"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
set +e
|
||||
echo "repository: ${repository}"
|
||||
source ./path_info.sh
|
||||
echo "start to build docker images"
|
||||
currentPwd=`pwd`
|
||||
echo ${currentPwd}
|
||||
i=0
|
||||
for path in ${service_source_root[*]}
|
||||
do
|
||||
cd ${path}
|
||||
make build
|
||||
image="${repository}/${image_names[${i}]}:$version"
|
||||
echo ${image}
|
||||
docker build -t $image . -f ./deploy.Dockerfile
|
||||
echo "build ${image} success"
|
||||
docker push ${image}
|
||||
echo "push ${image} success"
|
||||
echo "=============================="
|
||||
i=$((i + 1))
|
||||
cd ${currentPwd}
|
||||
done
|
||||
|
||||
echo "build all images success"
|
||||
Executable
+83
@@ -0,0 +1,83 @@
|
||||
#!/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
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
source "${OPENIM_ROOT}/scripts/install/common.sh"
|
||||
|
||||
OPENIM_VERBOSE=4
|
||||
|
||||
# OpenIM status
|
||||
# Elegant printing function
|
||||
print_services_and_ports() {
|
||||
local -n service_names=$1
|
||||
local -n service_ports=$2
|
||||
|
||||
echo "+-------------------------+----------+"
|
||||
echo "| Service Name | Port |"
|
||||
echo "+-------------------------+----------+"
|
||||
|
||||
for index in "${!service_names[@]}"; do
|
||||
printf "| %-23s | %-8s |\n" "${service_names[$index]}" "${service_ports[$index]}"
|
||||
done
|
||||
|
||||
echo "+-------------------------+----------+"
|
||||
}
|
||||
|
||||
|
||||
# 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[@]}"
|
||||
echo "## Check all dependent service ports"
|
||||
echo "+++ The port being checked: ${OPENIM_DEPENDENCY_PORT_LISTARIES[@]}"
|
||||
|
||||
set +e
|
||||
openim::util::check_ports ${OPENIM_DEPENDENCY_PORT_LISTARIES[@]}
|
||||
|
||||
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
|
||||
echo "++++ Check all dependent service ports successfully !"
|
||||
fi
|
||||
set -e
|
||||
|
||||
echo -e "\n## Check OpenIM service name"
|
||||
. $(dirname ${BASH_SOURCE})/install/openim-msgtransfer.sh openim::msgtransfer::check
|
||||
|
||||
echo -e "\n## Check all OpenIM service ports"
|
||||
echo "+++ The port being checked: ${OPENIM_SERVER_PORT_LISTARIES[@]}"
|
||||
openim::util::check_ports ${OPENIM_SERVER_PORT_LISTARIES[@]}
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "+++ cat openim log file >>> ${LOG_FILE}"
|
||||
openim::log::error_exit "The service does not start properly, please check the port, query variable definition!"
|
||||
else
|
||||
echo "++++ Check all openim service ports successfully !"
|
||||
fi
|
||||
@@ -1,80 +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.
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
source $SCRIPTS_ROOT/style_info.sh
|
||||
source $SCRIPTS_ROOT/path_info.sh
|
||||
source $SCRIPTS_ROOT/function.sh
|
||||
|
||||
cd $SCRIPTS_ROOT
|
||||
|
||||
echo -e "${YELLOW_PREFIX}=======>SCRIPTS_ROOT=$SCRIPTS_ROOT${COLOR_SUFFIX}"
|
||||
echo -e "${YELLOW_PREFIX}=======>OPENIM_ROOT=$OPENIM_ROOT${COLOR_SUFFIX}"
|
||||
echo -e "${YELLOW_PREFIX}=======>pwd=$PWD${COLOR_SUFFIX}"
|
||||
|
||||
service_port_name=(
|
||||
openImWsPort
|
||||
openImApiPort
|
||||
openImUserPort
|
||||
openImFriendPort
|
||||
openImMessagePort
|
||||
openImMessageGatewayPort
|
||||
openImGroupPort
|
||||
openImAuthPort
|
||||
openImPushPort
|
||||
openImConversationPort
|
||||
openImThirdPort
|
||||
)
|
||||
for i in ${service_port_name[*]}; do
|
||||
list=$(cat $config_path | grep -w ${i} | awk -F '[:]' '{print $NF}')
|
||||
list_to_string $list
|
||||
for j in ${ports_array}; do
|
||||
port=$(ss -tunlp| grep openim | awk '{print $5}' | grep -w ${j} | awk -F '[:]' '{print $NF}')
|
||||
if [[ ${port} -ne ${j} ]]; then
|
||||
echo -e ${BACKGROUND_GREEN}${i}${COLOR_SUFFIX}${RED_PREFIX}" service does not start normally,not initiated port is "${COLOR_SUFFIX}${BACKGROUND_GREEN}${j}${COLOR_SUFFIX}
|
||||
echo -e ${RED_PREFIX}"please check $OPENIM_ROOT/logs/openIM.log "${COLOR_SUFFIX}
|
||||
exit -1
|
||||
else
|
||||
echo -e ${j}${GREEN_PREFIX}" port has been listening,belongs service is "${i}${COLOR_SUFFIX}
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
#Check launched service process
|
||||
check=$(ps aux | grep -w ./${openim_msgtransfer} | grep -v grep | wc -l)
|
||||
if [ $check -ge ${msg_transfer_service_num} ]; then
|
||||
echo -e ${GREEN_PREFIX}"none port has been listening,belongs service is openImMsgTransfer"${COLOR_SUFFIX}
|
||||
else
|
||||
echo $check ${msg_transfer_service_num}
|
||||
echo -e ${RED_PREFIX}"openImMsgTransfer service does not start normally, num err"${COLOR_SUFFIX}
|
||||
echo -e ${RED_PREFIX}"please check $OPENIM_ROOT/logs/openIM.log "${COLOR_SUFFIX}
|
||||
exit -1
|
||||
fi
|
||||
|
||||
|
||||
check=$(ps aux | grep -w ./${cron_task_name} | grep -v grep | wc -l)
|
||||
if [ $check -ge 1 ]; then
|
||||
echo -e ${GREEN_PREFIX}"none port has been listening,belongs service is openImCronTask"${COLOR_SUFFIX}
|
||||
else
|
||||
echo -e ${RED_PREFIX}"cron_task_name service does not start normally"${COLOR_SUFFIX}
|
||||
echo -e ${RED_PREFIX}"please check $OPENIM_ROOT/logs/openIM.log "${COLOR_SUFFIX}
|
||||
exit -1
|
||||
fi
|
||||
|
||||
echo -e ${BACKGROUND_GREEN}"all services launch success"${COLOR_SUFFIX}
|
||||
Executable
+256
@@ -0,0 +1,256 @@
|
||||
#!/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/git_cherry-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>
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
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(/http[s]:\/\/|git@/,"")}1' | awk -F'[@:./]' 'NR==1{print $3}')}
|
||||
MAIN_REPO_NAME=${MAIN_REPO_NAME:-$(git remote get-url "$UPSTREAM_REMOTE" | awk '{gsub(/http[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/git_cherry-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/git_cherry-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
|
||||
+2
-1
@@ -37,7 +37,8 @@ readonly DOCKER_MACHINE_DRIVER=${DOCKER_MACHINE_DRIVER:-"virtualbox --virtualbox
|
||||
# This will canonicalize the path
|
||||
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd -P)
|
||||
|
||||
source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
||||
# Please do not refer to lib after referring to common
|
||||
. $(dirname ${BASH_SOURCE})/lib/init.sh
|
||||
|
||||
# Constants
|
||||
readonly OPENIM_BUILD_IMAGE_REPO=openim-build
|
||||
|
||||
Executable
+92
@@ -0,0 +1,92 @@
|
||||
#!/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.
|
||||
|
||||
clear
|
||||
. $(dirname ${BASH_SOURCE})/lib/util.sh
|
||||
|
||||
trap 'openim::util::onCtrlC' INT
|
||||
|
||||
openim::util::desc "========> Welcome to the OpenIM Demo"
|
||||
openim::util::desc "========> We'll help you get started with OpenIM quickly"
|
||||
openim::util::desc "========> Press Enter to continue...."
|
||||
openim::util::run "make advertise"
|
||||
clear
|
||||
|
||||
openim::util::desc "========> Initialize the project and generate configuration files"
|
||||
openim::util::run "make init"
|
||||
|
||||
openim::util::desc "========> You can look git diff"
|
||||
openim::util::run "git diff"
|
||||
clear
|
||||
|
||||
openim::util::desc "You can learn a lot about automation using make help"
|
||||
openim::util::run "make help"
|
||||
clear
|
||||
|
||||
openim::util::desc "You can learn a lot about automation using make help-all"
|
||||
openim::util::run "make help-all"
|
||||
clear
|
||||
|
||||
openim::util::desc "How did we teach you how to build OpenIM"
|
||||
openim::util::desc "A full build startup check"
|
||||
openim::util::run "make all"
|
||||
|
||||
openim::util::desc "Build one OpenIM binary"
|
||||
openim::util::desc "BINS: openim-api openim-cmdutils openim-crontask openim-msggateway openim-msgtransfer openim-push openim-rpc changelog infra ncpu yamlfmt"
|
||||
openim::util::run "make build BINS=openim-api"
|
||||
|
||||
openim::util::desc "Build binaries for all platforms"
|
||||
openim::util::run "make multiarch -j BINS=openim-api PLATFORMS='linux_arm64 linux_amd64' "
|
||||
|
||||
openim::util::desc "If you wish to use dlv for debugging, either binary or process"
|
||||
openim::util::desc "You need to enable debug mode"
|
||||
openim::util::run "make build BINS=openim-api DEBUG=1"
|
||||
clear
|
||||
|
||||
openim::util::desc "Run tidy to format and fix imports"
|
||||
openim::util::run "make tidy"
|
||||
clear
|
||||
|
||||
openim::util::desc "Vendor go.mod dependencies"
|
||||
openim::util::run "make vendor"
|
||||
clear
|
||||
|
||||
openim::util::desc "Run unit tests"
|
||||
openim::util::run "make test"
|
||||
clear
|
||||
|
||||
openim::util::desc "Run unit tests and get test coverage"
|
||||
openim::util::run "make cover"
|
||||
clear
|
||||
|
||||
openim::util::desc "Check for updates to go.mod dependencies"
|
||||
openim::util::run "make updates"
|
||||
clear
|
||||
|
||||
openim::util::desc "Clean all generated files"
|
||||
openim::util::run "make clean"
|
||||
clear
|
||||
|
||||
openim::util::desc "Generate all necessary files"
|
||||
openim::util::run "make gen"
|
||||
clear
|
||||
|
||||
openim::util::desc "Verify the license headers for all files"
|
||||
openim::util::run "make verify-copyright"
|
||||
clear
|
||||
|
||||
openim::util::desc "Add copyright"
|
||||
openim::util::run "make add-copyright"
|
||||
clear
|
||||
@@ -14,23 +14,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Include shell font styles and some basic information
|
||||
SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
Chat_Script=$SCRIPTS_ROOT/../openim-chat/scripts
|
||||
|
||||
source "$SCRIPTS_ROOT/style_info.sh"
|
||||
|
||||
echo -e "${GREEN_PREFIX}=========> Check docker-compose status ${COLOR_SUFFIX} \n"
|
||||
|
||||
trap 'onCtrlC' INT
|
||||
|
||||
function onCtrlC() {
|
||||
kill -9 "${do_sth_pid}" "${progress_pid}" "${countdown_pid}"
|
||||
echo
|
||||
echo 'Ctrl+C is captured'
|
||||
exit 1
|
||||
}
|
||||
source "${OPENIM_ROOT}/scripts/install/common.sh"
|
||||
|
||||
cd "$OPENIM_ROOT"
|
||||
|
||||
@@ -94,9 +79,7 @@ do_sth() {
|
||||
|
||||
kill "$_progress_pid" "$_countdown_pid"
|
||||
|
||||
"${SCRIPTS_ROOT}/check_all.sh"
|
||||
echo -e "${GREEN_PREFIX}=========> Check chat-compose status ${COLOR_SUFFIX} \n"
|
||||
"${Chat_Script}/check_all.sh"
|
||||
"${SCRIPTS_ROOT}/check-all.sh"
|
||||
echo -e "${PURPLE_PREFIX}=========> Check docker-compose status ${COLOR_SUFFIX} \n"
|
||||
}
|
||||
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
#!/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
|
||||
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
source "${OPENIM_ROOT}/scripts/install/common.sh"
|
||||
|
||||
trap 'openim::util::onCtrlC' INT
|
||||
|
||||
nohup ${OPENIM_ROOT}/scripts/start-all.sh >> ${LOG_FILE} 2>&1 &
|
||||
|
||||
sleep 15
|
||||
|
||||
nohup ${OPENIM_ROOT}/scripts/check-all.sh >> ${LOG_FILE} 2>&1 &
|
||||
|
||||
tail -f ${LOG_FILE}
|
||||
@@ -1,60 +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
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
|
||||
#fixme Put the shell scripts name here
|
||||
need_to_start_server_shell=(
|
||||
${SCRIPTS_ROOT}/start_rpc_service.sh
|
||||
${SCRIPTS_ROOT}/msg_gateway_start.sh
|
||||
${SCRIPTS_ROOT}/push_start.sh
|
||||
${SCRIPTS_ROOT}/msg_transfer_start.sh
|
||||
${SCRIPTS_ROOT}/start_cron.sh
|
||||
)
|
||||
|
||||
component_check=start_component_check.sh
|
||||
chmod +x $SCRIPTS_ROOT/$component_check
|
||||
$SCRIPTS_ROOT/$component_check
|
||||
if [ $? -ne 0 ]; then
|
||||
# Print error message and exit
|
||||
echo "${BOLD_PREFIX}${RED_PREFIX}Error executing ${component_check}. Exiting...${COLOR_SUFFIX}"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
#fixme The 10 second delay to start the project is for the docker-compose one-click to start openIM when the infrastructure dependencies are not started
|
||||
|
||||
sleep 10
|
||||
time=`date +"%Y-%m-%d %H:%M:%S"`
|
||||
echo "==========================================================">>$OPENIM_ROOT/logs/openIM.log 2>&1 &
|
||||
echo "==========================================================">>$OPENIM_ROOT/logs/openIM.log 2>&1 &
|
||||
echo "==========================================================">>$OPENIM_ROOT/logs/openIM.log 2>&1 &
|
||||
echo "==========server start time:${time}===========">>$OPENIM_ROOT/logs/openIM.log 2>&1 &
|
||||
echo "==========================================================">>$OPENIM_ROOT/logs/openIM.log 2>&1 &
|
||||
echo "==========================================================">>$OPENIM_ROOT/logs/openIM.log 2>&1 &
|
||||
echo "==========================================================">>$OPENIM_ROOT/logs/openIM.log 2>&1 &
|
||||
for i in ${need_to_start_server_shell[*]}; do
|
||||
$i
|
||||
done
|
||||
|
||||
sleep 15
|
||||
|
||||
#fixme prevents the openIM service exit after execution in the docker container
|
||||
tail -f /dev/null
|
||||
@@ -1,52 +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.
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
source $SCRIPTS_ROOT/style_info.sh
|
||||
source $SCRIPTS_ROOT/path_info.sh
|
||||
source $SCRIPTS_ROOT/function.sh
|
||||
|
||||
cd $SCRIPTS_ROOT
|
||||
|
||||
echo -e "${YELLOW_PREFIX}=======>SCRIPTS_ROOT=$SCRIPTS_ROOT${COLOR_SUFFIX}"
|
||||
echo -e "${YELLOW_PREFIX}=======>OPENIM_ROOT=$OPENIM_ROOT${COLOR_SUFFIX}"
|
||||
echo -e "${YELLOW_PREFIX}=======>pwd=$PWD${COLOR_SUFFIX}"
|
||||
|
||||
service_port_name=(
|
||||
openImChatApiPort
|
||||
openImAdminApiPort
|
||||
#api port name
|
||||
openImAdminPort
|
||||
openImChatPort
|
||||
)
|
||||
|
||||
for i in ${service_port_name[*]}; do
|
||||
list=$(cat $config_path | grep -w ${i} | awk -F '[:]' '{print $NF}')
|
||||
list_to_string $list
|
||||
for j in ${ports_array}; do
|
||||
port=$(ss -tunlp| grep openim | awk '{print $5}' | grep -w ${j} | awk -F '[:]' '{print $NF}')
|
||||
if [[ ${port} -ne ${j} ]]; then
|
||||
echo -e ${BACKGROUND_GREEN}${i}${COLOR_SUFFIX}${RED_PREFIX}" service does not start normally,not initiated port is "${COLOR_SUFFIX}${BACKGROUND_GREEN}${j}${COLOR_SUFFIX}
|
||||
echo -e ${RED_PREFIX}"please check $OPENIM_ROOT/logs/openIM.log"${COLOR_SUFFIX}
|
||||
exit -1
|
||||
else
|
||||
echo -e ${j}${GREEN_PREFIX}" port has been listening,belongs service is "${i}${COLOR_SUFFIX}
|
||||
fi
|
||||
done
|
||||
done
|
||||
@@ -1,25 +0,0 @@
|
||||
#Don't put the space between "="
|
||||
|
||||
demo_server_name="chat-api"
|
||||
demo_server_binary_root="$BIN_DIR/"
|
||||
|
||||
#Global configuration file default dir
|
||||
config_path="../.docker-compose_cfg/config.yaml"
|
||||
|
||||
#servicefile dir path
|
||||
service_source_root=(
|
||||
#api service file
|
||||
../cmd/api/chat/
|
||||
../cmd/api/admin/
|
||||
#rpc service file
|
||||
../cmd/rpc/admin/
|
||||
../cmd/rpc/chat/
|
||||
)
|
||||
|
||||
#service filename
|
||||
service_names=(
|
||||
chat-api
|
||||
admin-api
|
||||
admin-rpc
|
||||
chat-rpc
|
||||
)
|
||||
@@ -19,9 +19,8 @@ SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
OPENIM_ROOT=$(dirname "${SCRIPTS_ROOT}")/..
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
source $SCRIPTS_ROOT/style_info.sh
|
||||
source $SCRIPTS_ROOT/path_info.sh
|
||||
source $SCRIPTS_ROOT/function.sh
|
||||
source $SCRIPTS_ROOT/lib/init.sh
|
||||
|
||||
cd $SCRIPTS_ROOT
|
||||
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright 2020 Lingfei Kong <colin404@foxmail.com>. All rights reserved.
|
||||
# Use of this source code is governed by a MIT style
|
||||
# license that can be found in the LICENSE file.
|
||||
|
||||
# OPENIM 项目源码根目录
|
||||
IAM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
|
||||
# 生成文件存放目录
|
||||
LOCAL_OUTPUT_ROOT="${IAM_ROOT}/${OUT_DIR:-_output}"
|
||||
|
||||
# 设置统一的密码,方便记忆
|
||||
readonly PASSWORD=${PASSWORD:-'iam59!z$'}
|
||||
|
||||
# Linux系统 going 用户
|
||||
readonly LINUX_USERNAME=${LINUX_USERNAME:-going}
|
||||
# Linux root & going 用户密码
|
||||
readonly LINUX_PASSWORD=${LINUX_PASSWORD:-${PASSWORD}}
|
||||
|
||||
# 设置安装目录
|
||||
readonly INSTALL_DIR=${INSTALL_DIR:-/tmp/installation}
|
||||
mkdir -p ${INSTALL_DIR}
|
||||
readonly ENV_FILE=${IAM_ROOT}/scripts/install/environment.sh
|
||||
|
||||
# MariaDB 配置信息
|
||||
readonly MARIADB_ADMIN_USERNAME=${MARIADB_ADMIN_USERNAME:-root} # MariaDB root 用户
|
||||
readonly MARIADB_ADMIN_PASSWORD=${MARIADB_ADMIN_PASSWORD:-${PASSWORD}} # MariaDB root 用户密码
|
||||
readonly MARIADB_HOST=${MARIADB_HOST:-127.0.0.1:3306} # MariaDB 主机地址
|
||||
readonly MARIADB_DATABASE=${MARIADB_DATABASE:-openim} # MariaDB openim 应用使用的数据库名
|
||||
readonly MARIADB_USERNAME=${MARIADB_USERNAME:-openim} # openim 数据库用户名
|
||||
readonly MARIADB_PASSWORD=${MARIADB_PASSWORD:-${PASSWORD}} # openim 数据库密码
|
||||
|
||||
# Redis 配置信息
|
||||
readonly REDIS_HOST=${REDIS_HOST:-127.0.0.1} # Redis 主机地址
|
||||
readonly REDIS_PORT=${REDIS_PORT:-6379} # Redis 监听端口
|
||||
readonly REDIS_USERNAME=${REDIS_USERNAME:-''} # Redis 用户名
|
||||
readonly REDIS_PASSWORD=${REDIS_PASSWORD:-${PASSWORD}} # Redis 密码
|
||||
|
||||
# MongoDB 配置
|
||||
readonly MONGO_ADMIN_USERNAME=${MONGO_ADMIN_USERNAME:-root} # MongoDB root 用户
|
||||
readonly MONGO_ADMIN_PASSWORD=${MONGO_ADMIN_PASSWORD:-${PASSWORD}} # MongoDB root 用户密码
|
||||
readonly MONGO_HOST=${MONGO_HOST:-127.0.0.1} # MongoDB 地址
|
||||
readonly MONGO_PORT=${MONGO_PORT:-27017} # MongoDB 端口
|
||||
readonly MONGO_USERNAME=${MONGO_USERNAME:-openim} # MongoDB 用户名
|
||||
readonly MONGO_PASSWORD=${MONGO_PASSWORD:-${PASSWORD}} # MongoDB 密码
|
||||
|
||||
# openim 配置
|
||||
readonly IAM_DATA_DIR=${IAM_DATA_DIR:-/data/openim} # openim 各组件数据目录
|
||||
readonly IAM_INSTALL_DIR=${IAM_INSTALL_DIR:-/opt/openim} # openim 安装文件存放目录
|
||||
readonly IAM_CONFIG_DIR=${IAM_CONFIG_DIR:-/etc/openim} # openim 配置文件存放目录
|
||||
readonly IAM_LOG_DIR=${IAM_LOG_DIR:-/var/log/openim} # openim 日志文件存放目录
|
||||
readonly CA_FILE=${CA_FILE:-${IAM_CONFIG_DIR}/cert/ca.pem} # CA
|
||||
|
||||
# openim-apiserver 配置
|
||||
readonly IAM_APISERVER_HOST=${IAM_APISERVER_HOST:-127.0.0.1} # openim-apiserver 部署机器 IP 地址
|
||||
readonly IAM_APISERVER_GRPC_BIND_ADDRESS=${IAM_APISERVER_GRPC_BIND_ADDRESS:-0.0.0.0}
|
||||
readonly IAM_APISERVER_GRPC_BIND_PORT=${IAM_APISERVER_GRPC_BIND_PORT:-8081}
|
||||
readonly IAM_APISERVER_INSECURE_BIND_ADDRESS=${IAM_APISERVER_INSECURE_BIND_ADDRESS:-127.0.0.1}
|
||||
readonly IAM_APISERVER_INSECURE_BIND_PORT=${IAM_APISERVER_INSECURE_BIND_PORT:-8080}
|
||||
readonly IAM_APISERVER_SECURE_BIND_ADDRESS=${IAM_APISERVER_SECURE_BIND_ADDRESS:-0.0.0.0}
|
||||
readonly IAM_APISERVER_SECURE_BIND_PORT=${IAM_APISERVER_SECURE_BIND_PORT:-8443}
|
||||
readonly IAM_APISERVER_SECURE_TLS_CERT_KEY_CERT_FILE=${IAM_APISERVER_SECURE_TLS_CERT_KEY_CERT_FILE:-${IAM_CONFIG_DIR}/cert/openim-apiserver.pem}
|
||||
readonly IAM_APISERVER_SECURE_TLS_CERT_KEY_PRIVATE_KEY_FILE=${IAM_APISERVER_SECURE_TLS_CERT_KEY_PRIVATE_KEY_FILE:-${IAM_CONFIG_DIR}/cert/openim-apiserver-key.pem}
|
||||
|
||||
# openim-authz-server 配置
|
||||
readonly IAM_AUTHZ_SERVER_HOST=${IAM_AUTHZ_SERVER_HOST:-127.0.0.1} # openim-authz-server 部署机器 IP 地址
|
||||
readonly IAM_AUTHZ_SERVER_INSECURE_BIND_ADDRESS=${IAM_AUTHZ_SERVER_INSECURE_BIND_ADDRESS:-127.0.0.1}
|
||||
readonly IAM_AUTHZ_SERVER_INSECURE_BIND_PORT=${IAM_AUTHZ_SERVER_INSECURE_BIND_PORT:-9090}
|
||||
readonly IAM_AUTHZ_SERVER_SECURE_BIND_ADDRESS=${IAM_AUTHZ_SERVER_SECURE_BIND_ADDRESS:-0.0.0.0}
|
||||
readonly IAM_AUTHZ_SERVER_SECURE_BIND_PORT=${IAM_AUTHZ_SERVER_SECURE_BIND_PORT:-9443}
|
||||
readonly IAM_AUTHZ_SERVER_SECURE_TLS_CERT_KEY_CERT_FILE=${IAM_AUTHZ_SERVER_SECURE_TLS_CERT_KEY_CERT_FILE:-${IAM_CONFIG_DIR}/cert/openim-authz-server.pem}
|
||||
readonly IAM_AUTHZ_SERVER_SECURE_TLS_CERT_KEY_PRIVATE_KEY_FILE=${IAM_AUTHZ_SERVER_SECURE_TLS_CERT_KEY_PRIVATE_KEY_FILE:-${IAM_CONFIG_DIR}/cert/openim-authz-server-key.pem}
|
||||
readonly IAM_AUTHZ_SERVER_CLIENT_CA_FILE=${IAM_AUTHZ_SERVER_CLIENT_CA_FILE:-${CA_FILE}}
|
||||
readonly IAM_AUTHZ_SERVER_RPCSERVER=${IAM_AUTHZ_SERVER_RPCSERVER:-${IAM_APISERVER_HOST}:${IAM_APISERVER_GRPC_BIND_PORT}}
|
||||
|
||||
# openim-pump 配置
|
||||
readonly IAM_PUMP_HOST=${IAM_PUMP_HOST:-127.0.0.1} # openim-pump 部署机器 IP 地址
|
||||
readonly IAM_PUMP_COLLECTION_NAME=${IAM_PUMP_COLLECTION_NAME:-iam_analytics}
|
||||
readonly IAM_PUMP_MONGO_URL=${IAM_PUMP_MONGO_URL:-mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@${MONGO_HOST}:${MONGO_PORT}/${IAM_PUMP_COLLECTION_NAME}?authSource=${IAM_PUMP_COLLECTION_NAME}}
|
||||
|
||||
# openim-watcher配置
|
||||
readonly IAM_WATCHER_HOST=${IAM_WATCHER_HOST:-127.0.0.1} # openim-watcher 部署机器 IP 地址
|
||||
|
||||
# iamctl 配置
|
||||
readonly CONFIG_USER_USERNAME=${CONFIG_USER_USERNAME:-admin}
|
||||
readonly CONFIG_USER_PASSWORD=${CONFIG_USER_PASSWORD:-Admin@2021}
|
||||
readonly CONFIG_USER_CLIENT_CERTIFICATE=${CONFIG_USER_CLIENT_CERTIFICATE:-${HOME}/.openim/cert/admin.pem}
|
||||
readonly CONFIG_USER_CLIENT_KEY=${CONFIG_USER_CLIENT_KEY:-${HOME}/.openim/cert/admin-key.pem}
|
||||
readonly CONFIG_SERVER_ADDRESS=${CONFIG_SERVER_ADDRESS:-${IAM_APISERVER_HOST}:${IAM_APISERVER_SECURE_BIND_PORT}}
|
||||
readonly CONFIG_SERVER_CERTIFICATE_AUTHORITY=${CONFIG_SERVER_CERTIFICATE_AUTHORITY:-${CA_FILE}}
|
||||
@@ -1,34 +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.
|
||||
|
||||
# input: [10023, 2323, 3434]
|
||||
# output: 10023 2323 3434
|
||||
|
||||
# 函数功能:将列表转换为字符串,去除空格和括号
|
||||
list_to_string() {
|
||||
ports_list=$* # 获取传入的参数列表
|
||||
sub_s1=$(echo $ports_list | sed 's/ //g') # 去除空格
|
||||
sub_s2=${sub_s1//,/ } # 将逗号替换为空格
|
||||
sub_s3=${sub_s2#*[} # 去除左括号及其之前的内容
|
||||
sub_s4=${sub_s3%]*} # 去除右括号及其之后的内容
|
||||
ports_array=$sub_s4 # 将处理后的字符串赋值给变量 ports_array
|
||||
}
|
||||
|
||||
# 函数功能:去除字符串中的空格
|
||||
remove_space() {
|
||||
value=$* # 获取传入的参数
|
||||
result=$(echo $value | sed 's/ //g') # 去除空格
|
||||
}
|
||||
Executable
+73
@@ -0,0 +1,73 @@
|
||||
#!/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.
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
# 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"
|
||||
+16
-6
@@ -1,11 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright 2020 Lingfei Kong <colin404@foxmail.com>. All rights reserved.
|
||||
# Use of this source code is governed by a MIT style
|
||||
# license that can be found in the LICENSE file.
|
||||
# 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.
|
||||
|
||||
# 本脚本功能:根据 scripts/environment.sh 配置,生成 OPENIM 组件 YAML 配置文件。
|
||||
# 示例:genconfig.sh scripts/environment.sh configs/openim-apiserver.yaml
|
||||
# 示例:./scripts/genconfig.sh scripts/install/environment.sh scripts/template/config.yaml
|
||||
# Read: https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/contrib/init_config.md
|
||||
|
||||
env_file="$1"
|
||||
template_file="$2"
|
||||
@@ -15,7 +25,7 @@ OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
||||
|
||||
if [ $# -ne 2 ];then
|
||||
openim::log::error "Usage: genconfig.sh scripts/environment.sh configs/openim-apiserver.yaml"
|
||||
openim::log::error "Usage: scripts/genconfig.sh scripts/environment.sh configs/openim-api.yaml"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
Executable
+78
@@ -0,0 +1,78 @@
|
||||
#!/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.
|
||||
|
||||
DEFAULT_DIRS=(
|
||||
"pkg"
|
||||
"internal/pkg"
|
||||
)
|
||||
BASE_URL="github.com/OpenIMSDK/Open-IM-Server"
|
||||
|
||||
usage() {
|
||||
echo "Usage: $0 [OPTIONS]"
|
||||
echo
|
||||
echo "This script iterates over directories and generates doc.go if necessary."
|
||||
echo "By default, it processes 'pkg' and 'internal/pkg' directories."
|
||||
echo
|
||||
echo "Options:"
|
||||
echo " -d DIRS, --dirs DIRS Specify the directories to be processed, 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 " -h, --help Show this help message."
|
||||
echo
|
||||
}
|
||||
|
||||
process_dir() {
|
||||
local dir=$1
|
||||
local base_url=$2
|
||||
|
||||
for d in $(find $dir -type d); do
|
||||
if [ ! -f $d/doc.go ]; then
|
||||
if ls $d/*.go > /dev/null 2>&1; then
|
||||
echo $d/doc.go
|
||||
echo "package $(basename $d) // import \"$base_url/$d\"" > $d/doc.go
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
key="$1"
|
||||
|
||||
case $key in
|
||||
-d|--dirs)
|
||||
IFS=',' read -ra DIRS <<< "$2"
|
||||
shift # shift past argument
|
||||
shift # shift past value
|
||||
;;
|
||||
-u|--url)
|
||||
BASE_URL="$2"
|
||||
shift # shift past argument
|
||||
shift # shift past value
|
||||
;;
|
||||
-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
DIRS=${DIRS:-${DEFAULT_DIRS[@]}}
|
||||
|
||||
for dir in "${DIRS[@]}"; do
|
||||
process_dir $dir $BASE_URL
|
||||
done
|
||||
@@ -26,7 +26,7 @@
|
||||
LC_ALL=C
|
||||
|
||||
local_branch="$(git rev-parse --abbrev-ref HEAD)"
|
||||
valid_branch_regex="^(main|master|develop|release(-[a-zA-Z0-9._-]+)?)$|(feature|feat|openim|hotfix|test|bug|bot|ci|cicd|style|)\/[a-z0-9._-]+$|^HEAD$"
|
||||
valid_branch_regex="^(main|master|develop|release(-[a-zA-Z0-9._-]+)?)$|(feature|feat|openim|hotfix|test|bug|bot|refactor|revert|ci|cicd|style|)\/[a-z0-9._-]+$|^HEAD$"
|
||||
|
||||
YELLOW="\e[93m"
|
||||
GREEN="\e[32m"
|
||||
|
||||
@@ -0,0 +1,935 @@
|
||||
# Copyright © 2023 OpenIMSDK open source community. 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 file contains all available configuration options
|
||||
# with their default values.
|
||||
|
||||
# options for analysis running
|
||||
run:
|
||||
# default concurrency is a available CPU number
|
||||
concurrency: 4
|
||||
|
||||
# timeout for analysis, e.g. 30s, 5m, default is 1m
|
||||
timeout: 5m
|
||||
|
||||
# exit code when at least one issue was found, default is 1
|
||||
issues-exit-code: 1
|
||||
|
||||
# include test files or not, default is true
|
||||
tests: true
|
||||
|
||||
# list of build tags, all linters use it. Default is empty list.
|
||||
build-tags:
|
||||
- mytag
|
||||
|
||||
# which dirs to skip: issues from them won't be reported;
|
||||
# can use regexp here: generated.*, regexp is applied on full path;
|
||||
# default value is empty list, but default dirs are skipped independently
|
||||
# from this option's value (see skip-dirs-use-default).
|
||||
# "/" will be replaced by current OS file path separator to properly work
|
||||
# on Windows.
|
||||
skip-dirs:
|
||||
- util
|
||||
- .*~
|
||||
- api/swagger/docs
|
||||
- server/docs
|
||||
|
||||
# default is true. Enables skipping of directories:
|
||||
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
|
||||
skip-dirs-use-default: true
|
||||
|
||||
# which files to skip: they will be analyzed, but issues from them
|
||||
# won't be reported. Default value is empty list, but there is
|
||||
# no need to include all autogenerated files, we confidently recognize
|
||||
# autogenerated files. If it's not please let us know.
|
||||
# "/" will be replaced by current OS file path separator to properly work
|
||||
# on Windows.
|
||||
skip-files:
|
||||
- ".*\\.my\\.go$"
|
||||
- _test.go
|
||||
- ".*\\.pb\\.go"
|
||||
|
||||
# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
|
||||
# If invoked with -mod=readonly, the go command is disallowed from the implicit
|
||||
# automatic updating of go.mod described above. Instead, it fails when any changes
|
||||
# to go.mod are needed. This setting is most useful to check that go.mod does
|
||||
# not need updates, such as in a continuous integration and testing system.
|
||||
# If invoked with -mod=vendor, the go command assumes that the vendor
|
||||
# directory holds the correct copies of dependencies and ignores
|
||||
# the dependency descriptions in go.mod.
|
||||
#modules-download-mode: release|readonly|vendor
|
||||
|
||||
# Allow multiple parallel golangci-lint instances running.
|
||||
# If false (default) - golangci-lint acquires file lock on start.
|
||||
allow-parallel-runners: true
|
||||
|
||||
|
||||
# output configuration options
|
||||
output:
|
||||
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
|
||||
format: colored-line-number
|
||||
|
||||
# print lines of code with issue, default is true
|
||||
print-issued-lines: true
|
||||
|
||||
# print linter name in the end of issue text, default is true
|
||||
print-linter-name: true
|
||||
|
||||
# make issues output unique by line, default is true
|
||||
uniq-by-line: true
|
||||
|
||||
# add a prefix to the output file references; default is no prefix
|
||||
path-prefix: ""
|
||||
|
||||
# sorts results by: filepath, line and column
|
||||
sort-results: true
|
||||
|
||||
# all available settings of specific linters
|
||||
linters-settings:
|
||||
bidichk:
|
||||
# The following configurations check for all mentioned invisible unicode
|
||||
# runes. It can be omitted because all runes are enabled by default.
|
||||
left-to-right-embedding: true
|
||||
right-to-left-embedding: true
|
||||
pop-directional-formatting: true
|
||||
left-to-right-override: true
|
||||
right-to-left-override: true
|
||||
left-to-right-isolate: true
|
||||
right-to-left-isolate: true
|
||||
first-strong-isolate: true
|
||||
pop-directional-isolate: true
|
||||
dogsled:
|
||||
# checks assignments with too many blank identifiers; default is 2
|
||||
max-blank-identifiers: 2
|
||||
dupl:
|
||||
# tokens count to trigger issue, 150 by default
|
||||
threshold: 200
|
||||
errcheck:
|
||||
# report about not checking of errors in type assertions: `a := b.(MyStruct)`;
|
||||
# default is false: such cases aren't reported by default.
|
||||
check-type-assertions: false
|
||||
|
||||
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
|
||||
# default is false: such cases aren't reported by default.
|
||||
check-blank: false
|
||||
|
||||
# [deprecated] comma-separated list of pairs of the form pkg:regex
|
||||
# the regex is used to ignore names within pkg. (default "fmt:.*").
|
||||
# see https://github.com/kisielk/errcheck#the-deprecated-method for details
|
||||
#ignore: GenMarkdownTree,os:.*,BindPFlags,WriteTo,Help
|
||||
#ignore: (os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv
|
||||
|
||||
# path to a file containing a list of functions to exclude from checking
|
||||
# see https://github.com/kisielk/errcheck#excluding-functions for details
|
||||
#exclude: errcheck.txt
|
||||
|
||||
errorlint:
|
||||
# Check whether fmt.Errorf uses the %w verb for formatting errors. See the readme for caveats
|
||||
errorf: true
|
||||
# Check for plain type assertions and type switches
|
||||
asserts: true
|
||||
# Check for plain error comparisons
|
||||
comparison: true
|
||||
|
||||
exhaustive:
|
||||
# check switch statements in generated files also
|
||||
check-generated: false
|
||||
# indicates that switch statements are to be considered exhaustive if a
|
||||
# 'default' case is present, even if all enum members aren't listed in the
|
||||
# switch
|
||||
default-signifies-exhaustive: false
|
||||
# enum members matching the supplied regex do not have to be listed in
|
||||
# switch statements to satisfy exhaustiveness
|
||||
ignore-enum-members: ""
|
||||
# consider enums only in package scopes, not in inner scopes
|
||||
package-scope-only: false
|
||||
exhaustivestruct:
|
||||
struct-patterns:
|
||||
- '*.Test'
|
||||
- '*.Test2'
|
||||
- '*.Embedded'
|
||||
- '*.External'
|
||||
|
||||
# forbidigo:
|
||||
# # Forbid the following identifiers (identifiers are written using regexp):
|
||||
# forbid:
|
||||
# - ^print.*$
|
||||
# - 'fmt\.Print.*'
|
||||
# - fmt.Println.* # too much log noise
|
||||
# - ginkgo\\.F.* # these are used just for local development
|
||||
# # Exclude godoc examples from forbidigo checks. Default is true.
|
||||
# exclude_godoc_examples: false
|
||||
funlen:
|
||||
lines: 150
|
||||
statements: 50
|
||||
gci:
|
||||
# put imports beginning with prefix after 3rd-party packages;
|
||||
# only support one prefix
|
||||
# if not set, use goimports.local-prefixes
|
||||
prefix: github.com/OpenIMSDK/OpenKF
|
||||
gocognit:
|
||||
# minimal code complexity to report, 30 by default (but we recommend 10-20)
|
||||
min-complexity: 30
|
||||
goconst:
|
||||
# minimal length of string constant, 3 by default
|
||||
min-len: 3
|
||||
# minimal occurrences count to trigger, 3 by default
|
||||
min-occurrences: 3
|
||||
# ignore test files, false by default
|
||||
ignore-tests: false
|
||||
# look for existing constants matching the values, true by default
|
||||
match-constant: true
|
||||
# search also for duplicated numbers, false by default
|
||||
numbers: false
|
||||
# minimum value, only works with goconst.numbers, 3 by default
|
||||
min: 3
|
||||
# maximum value, only works with goconst.numbers, 3 by default
|
||||
max: 3
|
||||
# ignore when constant is not used as function argument, true by default
|
||||
ignore-calls: true
|
||||
|
||||
gocritic:
|
||||
# Which checks should be enabled; can't be combined with 'disabled-checks';
|
||||
# See https://go-critic.github.io/overview#checks-overview
|
||||
# To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run`
|
||||
# By default list of stable checks is used.
|
||||
enabled-checks:
|
||||
#- rangeValCopy
|
||||
- nestingreduce
|
||||
- truncatecmp
|
||||
- unnamedresult
|
||||
- ruleguard
|
||||
|
||||
# Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty
|
||||
disabled-checks:
|
||||
- regexpMust
|
||||
- ifElseChain
|
||||
#- exitAfterDefer
|
||||
|
||||
# Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks.
|
||||
# Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags".
|
||||
enabled-tags:
|
||||
- performance
|
||||
disabled-tags:
|
||||
- experimental
|
||||
|
||||
# Settings passed to gocritic.
|
||||
# The settings key is the name of a supported gocritic checker.
|
||||
# The list of supported checkers can be find in https://go-critic.github.io/overview.
|
||||
settings:
|
||||
captLocal: # must be valid enabled check name
|
||||
# whether to restrict checker to params only (default true)
|
||||
paramsOnly: true
|
||||
elseif:
|
||||
# whether to skip balanced if-else pairs (default true)
|
||||
skipBalanced: true
|
||||
hugeParam:
|
||||
# size in bytes that makes the warning trigger (default 80)
|
||||
sizeThreshold: 80
|
||||
nestingReduce:
|
||||
# min number of statements inside a branch to trigger a warning (default 5)
|
||||
bodyWidth: 5
|
||||
rangeExprCopy:
|
||||
# size in bytes that makes the warning trigger (default 512)
|
||||
sizeThreshold: 512
|
||||
# whether to check test functions (default true)
|
||||
skipTestFuncs: true
|
||||
rangeValCopy:
|
||||
# size in bytes that makes the warning trigger (default 128)
|
||||
sizeThreshold: 32
|
||||
# whether to check test functions (default true)
|
||||
skipTestFuncs: true
|
||||
ruleguard:
|
||||
# path to a gorules file for the ruleguard checker
|
||||
rules: ''
|
||||
truncateCmp:
|
||||
# whether to skip int/uint/uintptr types (default true)
|
||||
skipArchDependent: true
|
||||
underef:
|
||||
# whether to skip (*x).method() calls where x is a pointer receiver (default true)
|
||||
skipRecvDeref: true
|
||||
unnamedResult:
|
||||
# whether to check exported functions
|
||||
checkExported: true
|
||||
gocyclo:
|
||||
# minimal code complexity to report, 30 by default (but we recommend 10-20)
|
||||
min-complexity: 30
|
||||
cyclop:
|
||||
# the maximal code complexity to report
|
||||
max-complexity: 50
|
||||
# the maximal average package complexity. If it's higher than 0.0 (float) the check is enabled (default 0.0)
|
||||
package-average: 0.0
|
||||
# should ignore tests (default false)
|
||||
skip-tests: false
|
||||
godot:
|
||||
# comments to be checked: `declarations`, `toplevel`, or `all`
|
||||
scope: declarations
|
||||
# list of regexps for excluding particular comment lines from check
|
||||
exclude:
|
||||
# example: exclude comments which contain numbers
|
||||
# - '[0-9]+'
|
||||
# check that each sentence starts with a capital letter
|
||||
capital: false
|
||||
godox:
|
||||
# report any comments starting with keywords, this is useful for TODO or FIXME comments that
|
||||
# might be left in the code accidentally and should be resolved before merging
|
||||
keywords: # default keywords are TODO, BUG, and FIXME, these can be overwritten by this setting
|
||||
#- TODO
|
||||
- BUG
|
||||
- FIXME
|
||||
#- NOTE
|
||||
- OPTIMIZE # marks code that should be optimized before merging
|
||||
- HACK # marks hack-arounds that should be removed before merging
|
||||
gofmt:
|
||||
# simplify code: gofmt with `-s` option, true by default
|
||||
simplify: true
|
||||
|
||||
gofumpt:
|
||||
# Select the Go version to target. The default is `1.18`.
|
||||
lang-version: "1.20"
|
||||
|
||||
# Choose whether or not to use the extra rules that are disabled
|
||||
# by default
|
||||
extra-rules: false
|
||||
|
||||
goheader:
|
||||
values:
|
||||
const:
|
||||
# define here const type values in format k:v, for example:
|
||||
# COMPANY: MY COMPANY
|
||||
regexp:
|
||||
# define here regexp type values, for example
|
||||
# AUTHOR: .*@mycompany\.com
|
||||
template: # |-
|
||||
# put here copyright header template for source code files, for example:
|
||||
# Note: {{ YEAR }} is a builtin value that returns the year relative to the current machine time.
|
||||
#
|
||||
# {{ AUTHOR }} {{ COMPANY }} {{ YEAR }}
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
# 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.
|
||||
template-path:
|
||||
# also as alternative of directive 'template' you may put the path to file with the template source
|
||||
goimports:
|
||||
# put imports beginning with prefix after 3rd-party packages;
|
||||
# it's a comma-separated list of prefixes
|
||||
local-prefixes: github.com/OpenIMSDK/OpenKF
|
||||
golint:
|
||||
# minimal confidence for issues, default is 0.8
|
||||
min-confidence: 0.9
|
||||
gomnd:
|
||||
settings:
|
||||
mnd:
|
||||
# the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
|
||||
checks: argument,case,condition,operation,return,assign
|
||||
# ignored-numbers: 1000
|
||||
# ignored-files: magic_.*.go
|
||||
# ignored-functions: math.*
|
||||
gomoddirectives:
|
||||
# Allow local `replace` directives. Default is false.
|
||||
replace-local: true
|
||||
# List of allowed `replace` directives. Default is empty.
|
||||
replace-allow-list:
|
||||
- google.golang.org/grpc
|
||||
|
||||
# Allow to not explain why the version has been retracted in the `retract` directives. Default is false.
|
||||
retract-allow-no-explanation: false
|
||||
# Forbid the use of the `exclude` directives. Default is false.
|
||||
exclude-forbidden: false
|
||||
gomodguard:
|
||||
allowed:
|
||||
modules:
|
||||
- gorm.io/gen # List of allowed modules
|
||||
- gorm.io/gorm
|
||||
- gorm.io/driver/mysql
|
||||
- k8s.io/klog
|
||||
# - gopkg.in/yaml.v2
|
||||
domains: # List of allowed module domains
|
||||
- google.golang.org
|
||||
- gopkg.in
|
||||
- golang.org
|
||||
- github.com
|
||||
- go.uber.org
|
||||
- go.etcd.io
|
||||
blocked:
|
||||
versions:
|
||||
- github.com/MakeNowJust/heredoc:
|
||||
version: "> 2.0.9"
|
||||
reason: "use the latest version"
|
||||
local_replace_directives: false # Set to true to raise lint issues for packages that are loaded from a local path via replace directive
|
||||
|
||||
gosec:
|
||||
# To select a subset of rules to run.
|
||||
# Available rules: https://github.com/securego/gosec#available-rules
|
||||
includes:
|
||||
- G401
|
||||
- G306
|
||||
- G101
|
||||
# To specify a set of rules to explicitly exclude.
|
||||
# Available rules: https://github.com/securego/gosec#available-rules
|
||||
excludes:
|
||||
- G204
|
||||
# Exclude generated files
|
||||
exclude-generated: true
|
||||
# Filter out the issues with a lower severity than the given value. Valid options are: low, medium, high.
|
||||
severity: "low"
|
||||
# Filter out the issues with a lower confidence than the given value. Valid options are: low, medium, high.
|
||||
confidence: "low"
|
||||
# To specify the configuration of rules.
|
||||
# The configuration of rules is not fully documented by gosec:
|
||||
# https://github.com/securego/gosec#configuration
|
||||
# https://github.com/securego/gosec/blob/569328eade2ccbad4ce2d0f21ee158ab5356a5cf/rules/rulelist.go#L60-L102
|
||||
config:
|
||||
G306: "0600"
|
||||
G101:
|
||||
pattern: "(?i)example"
|
||||
ignore_entropy: false
|
||||
entropy_threshold: "80.0"
|
||||
per_char_threshold: "3.0"
|
||||
truncate: "32"
|
||||
|
||||
gosimple:
|
||||
# Select the Go version to target. The default is '1.13'.
|
||||
go: "1.20"
|
||||
# https://staticcheck.io/docs/options#checks
|
||||
checks: [ "all" ]
|
||||
|
||||
govet:
|
||||
# report about shadowed variables
|
||||
check-shadowing: true
|
||||
|
||||
# settings per analyzer
|
||||
settings:
|
||||
printf: # analyzer name, run `go tool vet help` to see all analyzers
|
||||
funcs: # run `go tool vet help printf` to see available settings for `printf` analyzer
|
||||
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
|
||||
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
|
||||
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
|
||||
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
|
||||
|
||||
# enable or disable analyzers by name
|
||||
enable:
|
||||
- atomicalign
|
||||
enable-all: false
|
||||
disable:
|
||||
- shadow
|
||||
disable-all: false
|
||||
# depguard:
|
||||
# list-type: blacklist
|
||||
# include-go-root: false
|
||||
# packages:
|
||||
# - github.com/Sirupsen/logrus
|
||||
# packages-with-error-message:
|
||||
# # specify an error message to output when a blacklisted package is used
|
||||
# - github.com/Sirupsen/logrus: "logging is allowed only by logutils.Log"
|
||||
ifshort:
|
||||
# Maximum length of variable declaration measured in number of lines, after which linter won't suggest using short syntax.
|
||||
# Has higher priority than max-decl-chars.
|
||||
max-decl-lines: 1
|
||||
# Maximum length of variable declaration measured in number of characters, after which linter won't suggest using short syntax.
|
||||
max-decl-chars: 30
|
||||
|
||||
importas:
|
||||
# if set to `true`, force to use alias.
|
||||
no-unaliased: true
|
||||
# List of aliases
|
||||
alias:
|
||||
# using `servingv1` alias for `knative.dev/serving/pkg/apis/serving/v1` package
|
||||
- pkg: knative.dev/serving/pkg/apis/serving/v1
|
||||
alias: servingv1
|
||||
# using `autoscalingv1alpha1` alias for `knative.dev/serving/pkg/apis/autoscaling/v1alpha1` package
|
||||
- pkg: knative.dev/serving/pkg/apis/autoscaling/v1alpha1
|
||||
alias: autoscalingv1alpha1
|
||||
# You can specify the package path by regular expression,
|
||||
# and alias by regular expression expansion syntax like below.
|
||||
# see https://github.com/julz/importas#use-regular-expression for details
|
||||
- pkg: knative.dev/serving/pkg/apis/(\w+)/(v[\w\d]+)
|
||||
alias: $1$2
|
||||
# using `jwt` alias for `github.com/appleboy/gin-jwt/v2` package
|
||||
jwt: github.com/appleboy/gin-jwt/v2
|
||||
|
||||
ireturn:
|
||||
# ireturn allows using `allow` and `reject` settings at the same time.
|
||||
# Both settings are lists of the keywords and regular expressions matched to interface or package names.
|
||||
# keywords:
|
||||
# - `empty` for `interface{}`
|
||||
# - `error` for errors
|
||||
# - `stdlib` for standard library
|
||||
# - `anon` for anonymous interfaces
|
||||
|
||||
# By default, it allows using errors, empty interfaces, anonymous interfaces,
|
||||
# and interfaces provided by the standard library.
|
||||
allow:
|
||||
- anon
|
||||
- error
|
||||
- empty
|
||||
- stdlib
|
||||
# You can specify idiomatic endings for interface
|
||||
- (or|er)$
|
||||
|
||||
# Reject patterns
|
||||
reject:
|
||||
- github.com\/user\/package\/v4\.Type
|
||||
|
||||
lll:
|
||||
# max line length, lines longer will be reported. Default is 120.
|
||||
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
|
||||
line-length: 240
|
||||
# tab width in spaces. Default to 1.
|
||||
tab-width: 4
|
||||
maligned:
|
||||
# print struct with more effective memory layout or not, false by default
|
||||
suggest-new: true
|
||||
misspell:
|
||||
# Correct spellings using locale preferences for US or UK.
|
||||
# Default is to use a neutral variety of English.
|
||||
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
|
||||
locale: US
|
||||
ignore-words:
|
||||
- someword
|
||||
nakedret:
|
||||
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30
|
||||
max-func-lines: 30
|
||||
|
||||
nestif:
|
||||
# minimal complexity of if statements to report, 5 by default
|
||||
min-complexity: 4
|
||||
|
||||
nilnil:
|
||||
# By default, nilnil checks all returned types below.
|
||||
checked-types:
|
||||
- ptr
|
||||
- func
|
||||
- iface
|
||||
- map
|
||||
- chan
|
||||
|
||||
nlreturn:
|
||||
# size of the block (including return statement that is still "OK")
|
||||
# so no return split required.
|
||||
block-size: 1
|
||||
|
||||
nolintlint:
|
||||
# Disable to ensure that all nolint directives actually have an effect. Default is true.
|
||||
allow-unused: false
|
||||
# Disable to ensure that nolint directives don't have a leading space. Default is true.
|
||||
allow-leading-space: true
|
||||
# Exclude following linters from requiring an explanation. Default is [].
|
||||
allow-no-explanation: [ ]
|
||||
# Enable to require an explanation of nonzero length after each nolint directive. Default is false.
|
||||
require-explanation: false
|
||||
# Enable to require nolint directives to mention the specific linter being suppressed. Default is false.
|
||||
require-specific: true
|
||||
|
||||
prealloc:
|
||||
# XXX: we don't recommend using this linter before doing performance profiling.
|
||||
# For most programs usage of prealloc will be a premature optimization.
|
||||
|
||||
# Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them.
|
||||
# True by default.
|
||||
simple: true
|
||||
range-loops: true # Report preallocation suggestions on range loops, true by default
|
||||
for-loops: false # Report preallocation suggestions on for loops, false by default
|
||||
|
||||
promlinter:
|
||||
# Promlinter cannot infer all metrics name in static analysis.
|
||||
# Enable strict mode will also include the errors caused by failing to parse the args.
|
||||
strict: false
|
||||
# Please refer to https://github.com/yeya24/promlinter#usage for detailed usage.
|
||||
disabled-linters:
|
||||
# - "Help"
|
||||
# - "MetricUnits"
|
||||
# - "Counter"
|
||||
# - "HistogramSummaryReserved"
|
||||
# - "MetricTypeInName"
|
||||
# - "ReservedChars"
|
||||
# - "CamelCase"
|
||||
# - "lintUnitAbbreviations"
|
||||
|
||||
predeclared:
|
||||
# comma-separated list of predeclared identifiers to not report on
|
||||
ignore: ""
|
||||
# include method names and field names (i.e., qualified names) in checks
|
||||
q: false
|
||||
rowserrcheck:
|
||||
packages:
|
||||
- github.com/jmoiron/sqlx
|
||||
revive:
|
||||
# see https://github.com/mgechev/revive#available-rules for details.
|
||||
ignore-generated-header: true
|
||||
severity: warning
|
||||
rules:
|
||||
- name: indent-error-flow
|
||||
severity: warning
|
||||
staticcheck:
|
||||
# Select the Go version to target. The default is '1.13'.
|
||||
go: "1.16"
|
||||
# https://staticcheck.io/docs/options#checks
|
||||
checks: [ "all" ]
|
||||
|
||||
stylecheck:
|
||||
# Select the Go version to target. The default is '1.13'.
|
||||
go: "1.16"
|
||||
|
||||
# https://staticcheck.io/docs/options#checks
|
||||
checks: [ "all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022" ]
|
||||
# https://staticcheck.io/docs/options#dot_import_whitelist
|
||||
dot-import-whitelist:
|
||||
- fmt
|
||||
# https://staticcheck.io/docs/options#initialisms
|
||||
initialisms: [ "ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", "IP", "JSON", "QPS", "RAM", "RPC", "SLA", "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", "UDP", "UI", "GID", "UID", "UUID", "URI", "URL", "UTF8", "VM", "XML", "XMPP", "XSRF", "XSS" ]
|
||||
# https://staticcheck.io/docs/options#http_status_code_whitelist
|
||||
http-status-code-whitelist: [ "200", "400", "404", "500" ]
|
||||
|
||||
|
||||
tagliatelle:
|
||||
# check the struck tag name case
|
||||
case:
|
||||
# use the struct field name to check the name of the struct tag
|
||||
use-field-name: true
|
||||
rules:
|
||||
# any struct tag type can be used.
|
||||
# support string case: `camel`, `pascal`, `kebab`, `snake`, `goCamel`, `goPascal`, `goKebab`, `goSnake`, `upper`, `lower`
|
||||
json: camel
|
||||
yaml: camel
|
||||
xml: camel
|
||||
bson: camel
|
||||
avro: snake
|
||||
mapstructure: kebab
|
||||
|
||||
testpackage:
|
||||
# regexp pattern to skip files
|
||||
skip-regexp: (id|export|internal)_test\.go
|
||||
thelper:
|
||||
# The following configurations enable all checks. It can be omitted because all checks are enabled by default.
|
||||
# You can enable only required checks deleting unnecessary checks.
|
||||
test:
|
||||
first: true
|
||||
name: true
|
||||
begin: true
|
||||
benchmark:
|
||||
first: true
|
||||
name: true
|
||||
begin: true
|
||||
tb:
|
||||
first: true
|
||||
name: true
|
||||
begin: true
|
||||
|
||||
tenv:
|
||||
# The option `all` will run against whole test files (`_test.go`) regardless of method/function signatures.
|
||||
# By default, only methods that take `*testing.T`, `*testing.B`, and `testing.TB` as arguments are checked.
|
||||
all: false
|
||||
|
||||
unparam:
|
||||
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
|
||||
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
|
||||
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
|
||||
# with golangci-lint call it on a directory with the changed file.
|
||||
check-exported: false
|
||||
unused:
|
||||
# treat code as a program (not a library) and report unused exported identifiers; default is false.
|
||||
# XXX: if you enable this setting, unused will report a lot of false-positives in text editors:
|
||||
# if it's called for subdir of a project it can't find funcs usages. All text editor integrations
|
||||
# with golangci-lint call it on a directory with the changed file.
|
||||
check-exported: false
|
||||
whitespace:
|
||||
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
|
||||
multi-func: false # Enforces newlines (or comments) after every multi-line function signature
|
||||
|
||||
wrapcheck:
|
||||
# An array of strings that specify substrings of signatures to ignore.
|
||||
# If this set, it will override the default set of ignored signatures.
|
||||
# See https://github.com/tomarrell/wrapcheck#configuration for more information.
|
||||
ignoreSigs:
|
||||
- .Errorf(
|
||||
- errors.New(
|
||||
- errors.Unwrap(
|
||||
- .Wrap(
|
||||
- .Wrapf(
|
||||
- .WithMessage(
|
||||
- .WithMessagef(
|
||||
- .WithStack(
|
||||
ignorePackageGlobs:
|
||||
- encoding/*
|
||||
- github.com/pkg/*
|
||||
|
||||
wsl:
|
||||
# If true append is only allowed to be cuddled if appending value is
|
||||
# matching variables, fields or types on line above. Default is true.
|
||||
strict-append: true
|
||||
# Allow calls and assignments to be cuddled as long as the lines have any
|
||||
# matching variables, fields or types. Default is true.
|
||||
allow-assign-and-call: true
|
||||
# Allow assignments to be cuddled with anything. Default is false.
|
||||
allow-assign-and-anything: false
|
||||
# Allow multiline assignments to be cuddled. Default is true.
|
||||
allow-multiline-assign: true
|
||||
# Allow declarations (var) to be cuddled.
|
||||
allow-cuddle-declarations: false
|
||||
# Allow trailing comments in ending of blocks
|
||||
allow-trailing-comment: false
|
||||
# Force newlines in end of case at this limit (0 = never).
|
||||
force-case-trailing-whitespace: 0
|
||||
# Force cuddling of err checks with err var assignment
|
||||
force-err-cuddling: false
|
||||
# Allow leading comments to be separated with empty liens
|
||||
allow-separated-leading-comment: false
|
||||
makezero:
|
||||
# Allow only slices initialized with a length of zero. Default is false.
|
||||
always: false
|
||||
|
||||
|
||||
# The custom section can be used to define linter plugins to be loaded at runtime. See README doc
|
||||
# for more info.
|
||||
#custom:
|
||||
# Each custom linter should have a unique name.
|
||||
#example:
|
||||
# The path to the plugin *.so. Can be absolute or local. Required for each custom linter
|
||||
#path: /path/to/example.so
|
||||
# The description of the linter. Optional, just for documentation purposes.
|
||||
#description: This is an example usage of a plugin linter.
|
||||
# Intended to point to the repo location of the linter. Optional, just for documentation purposes.
|
||||
#original-url: github.com/golangci/example-linter
|
||||
|
||||
linters:
|
||||
# please, do not use `enable-all`: it's deprecated and will be removed soon.
|
||||
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
|
||||
# enable-all: true
|
||||
disable-all: true
|
||||
enable:
|
||||
- typecheck
|
||||
- asciicheck
|
||||
- bodyclose
|
||||
- cyclop
|
||||
- deadcode
|
||||
# - depguard
|
||||
- dogsled
|
||||
- dupl
|
||||
- durationcheck
|
||||
- errcheck
|
||||
- errorlint
|
||||
- exhaustive
|
||||
- exportloopref
|
||||
# - forbidigo
|
||||
- funlen
|
||||
# - gci
|
||||
# - gochecknoinits
|
||||
- gocognit
|
||||
- goconst
|
||||
- gocyclo
|
||||
- godot
|
||||
- godox
|
||||
- gofmt
|
||||
- gofumpt
|
||||
- goheader
|
||||
- goimports
|
||||
- gomoddirectives
|
||||
- gomodguard
|
||||
- goprintffuncname
|
||||
- gosec
|
||||
- gosimple
|
||||
- govet
|
||||
- ifshort
|
||||
- importas
|
||||
- ineffassign
|
||||
- lll
|
||||
- makezero
|
||||
- misspell
|
||||
- nakedret
|
||||
- nestif
|
||||
- nilerr
|
||||
- nlreturn
|
||||
- noctx
|
||||
- nolintlint
|
||||
- paralleltest
|
||||
- prealloc
|
||||
- predeclared
|
||||
- promlinter
|
||||
- revive
|
||||
- rowserrcheck
|
||||
- sqlclosecheck
|
||||
- staticcheck
|
||||
- structcheck
|
||||
- stylecheck
|
||||
- thelper
|
||||
- tparallel
|
||||
- unconvert
|
||||
- unparam
|
||||
- unused
|
||||
- varcheck
|
||||
- wastedassign
|
||||
- whitespace
|
||||
- bidichk
|
||||
- wastedassign
|
||||
- golint
|
||||
- execinquery
|
||||
- nosprintfhostport
|
||||
- grouper
|
||||
- decorder
|
||||
- errchkjson
|
||||
- maintidx
|
||||
#- containedctx
|
||||
#- tagliatelle
|
||||
#- nonamedreturns
|
||||
#- nilnil
|
||||
#- tenv
|
||||
#- varnamelen
|
||||
#- contextcheck
|
||||
#- errname
|
||||
#- ForceTypeAssert
|
||||
#- nilassign
|
||||
fast: false
|
||||
|
||||
issues:
|
||||
# List of regexps of issue texts to exclude, empty list by default.
|
||||
# But independently from this option we use default exclude patterns,
|
||||
# it can be disabled by `exclude-use-default: false`. To list all
|
||||
# excluded by default patterns execute `golangci-lint run --help`
|
||||
exclude:
|
||||
- tools/.*
|
||||
- test/.*
|
||||
- third_party/.*
|
||||
|
||||
# Excluding configuration per-path, per-linter, per-text and per-source
|
||||
exclude-rules:
|
||||
- linters:
|
||||
- golint
|
||||
path: (internal/api/.*)\.go # exclude golint for internal/api/... files
|
||||
|
||||
- linters:
|
||||
- revive
|
||||
path: (log/.*)\.go
|
||||
|
||||
- linters:
|
||||
- wrapcheck
|
||||
path: (cmd/.*|pkg/.*)\.go
|
||||
|
||||
- linters:
|
||||
- typecheck
|
||||
#path: (pkg/storage/.*)\.go
|
||||
path: (internal/.*|pkg/.*)\.go
|
||||
|
||||
- path: (cmd/.*|test/.*|tools/.*|internal/pump/pumps/.*)\.go
|
||||
linters:
|
||||
- forbidigo
|
||||
|
||||
- path: (cmd/[a-z]*/.*|store/.*)\.go
|
||||
linters:
|
||||
- dupl
|
||||
|
||||
- linters:
|
||||
- gocritic
|
||||
text: (hugeParam:|rangeValCopy:)
|
||||
|
||||
- path: (cmd/[a-z]*/.*)\.go
|
||||
linters:
|
||||
- lll
|
||||
|
||||
- path: (validator/.*|code/.*|validator/.*|watcher/watcher/.*)
|
||||
linters:
|
||||
- gochecknoinits
|
||||
|
||||
- path: (internal/.*/options|internal/pump|pkg/log/options.go|internal/authzserver|tools/)
|
||||
linters:
|
||||
- tagliatelle
|
||||
|
||||
- path: (pkg/app/.*)\.go
|
||||
linters:
|
||||
- deadcode
|
||||
- unused
|
||||
- varcheck
|
||||
- forbidigo
|
||||
|
||||
# Exclude some staticcheck messages
|
||||
- linters:
|
||||
- staticcheck
|
||||
text: "SA9003:"
|
||||
|
||||
# Exclude lll issues for long lines with go:generate
|
||||
- linters:
|
||||
- lll
|
||||
source: "^//go:generate "
|
||||
|
||||
# Independently from option `exclude` we use default exclude patterns,
|
||||
# it can be disabled by this option. To list all
|
||||
# excluded by default patterns execute `golangci-lint run --help`.
|
||||
# Default value for this option is true.
|
||||
exclude-use-default: true
|
||||
|
||||
# The default value is false. If set to true exclude and exclude-rules
|
||||
# regular expressions become case sensitive.
|
||||
exclude-case-sensitive: false
|
||||
|
||||
# The list of ids of default excludes to include or disable. By default it's empty.
|
||||
include:
|
||||
- EXC0002 # disable excluding of issues about comments from golint
|
||||
|
||||
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
|
||||
max-issues-per-linter: 0
|
||||
|
||||
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
|
||||
max-same-issues: 0
|
||||
|
||||
# Show only new issues: if there are unstaged changes or untracked files,
|
||||
# only those changes are analyzed, else only changes in HEAD~ are analyzed.
|
||||
# It's a super-useful option for integration of golangci-lint into existing
|
||||
# large codebase. It's not practical to fix all existing issues at the moment
|
||||
# of integration: much better don't allow issues in new code.
|
||||
# Default is false.
|
||||
new: false
|
||||
|
||||
# Show only new issues created after git revision `REV`
|
||||
# new-from-rev: REV
|
||||
|
||||
# Show only new issues created in git patch with set file path.
|
||||
#new-from-patch: path/to/patch/file
|
||||
|
||||
# Fix found issues (if it's supported by the linter)
|
||||
fix: true
|
||||
|
||||
severity:
|
||||
# Default value is empty string.
|
||||
# Set the default severity for issues. If severity rules are defined and the issues
|
||||
# do not match or no severity is provided to the rule this will be the default
|
||||
# severity applied. Severities should match the supported severity names of the
|
||||
# selected out format.
|
||||
# - Code climate: https://docs.codeclimate.com/docs/issues#issue-severity
|
||||
# - Checkstyle: https://checkstyle.sourceforge.io/property_types.html#severity
|
||||
# - Github: https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-error-message
|
||||
default-severity: error
|
||||
|
||||
# The default value is false.
|
||||
# If set to true severity-rules regular expressions become case sensitive.
|
||||
case-sensitive: false
|
||||
|
||||
# Default value is empty list.
|
||||
# When a list of severity rules are provided, severity information will be added to lint
|
||||
# issues. Severity rules have the same filtering capability as exclude rules except you
|
||||
# are allowed to specify one matcher per severity rule.
|
||||
# Only affects out formats that support setting severity information.
|
||||
rules:
|
||||
- linters:
|
||||
- dupl
|
||||
severity: info
|
||||
Executable
+50
@@ -0,0 +1,50 @@
|
||||
#!/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 the various configuration files
|
||||
# Read: https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/contrib/init_config.md
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
|
||||
source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
||||
|
||||
# 定义一个配置文件数组,其中包含需要生成的配置文件的名称路径 (en: Define a profile array that contains the name path of the profile to be generated.)
|
||||
readonly ENV_FILE=${ENV_FILE:-${OPENIM_ROOT}/scripts/install/environment.sh}
|
||||
|
||||
# 定义关联数组,其中键是模板文件,值是对应的输出文件 (en: Defines an associative array where the keys are the template files and the values are the corresponding output files.)
|
||||
declare -A TEMPLATES=(
|
||||
["${OPENIM_ROOT}/deployments/templates/env_template.yaml"]="${OPENIM_ROOT}/.env"
|
||||
["${OPENIM_ROOT}/deployments/templates/openim.yaml"]="${OPENIM_ROOT}/config/config.yaml"
|
||||
)
|
||||
|
||||
for template in "${!TEMPLATES[@]}"; do
|
||||
output_file=${TEMPLATES[$template]}
|
||||
|
||||
if [[ ! -f "${template}" ]]; then
|
||||
openim::log::error_exit "template file ${template} does not exist..."
|
||||
fi
|
||||
|
||||
openim::log::info "Working with template file: ${template} to ${output_file}..."
|
||||
"${OPENIM_ROOT}/scripts/genconfig.sh" "${ENV_FILE}" "${template}" > "${output_file}" || {
|
||||
openim::log::error "Error processing template file ${template}"
|
||||
exit 1
|
||||
}
|
||||
done
|
||||
|
||||
openim::log::success "All configuration files have been successfully generated!"
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
#!/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.
|
||||
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd -P)
|
||||
source "${OPENIM_ROOT}/scripts/install/common.sh"
|
||||
|
||||
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
-2
@@ -19,9 +19,8 @@ SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
OPENIM_ROOT=$(dirname "${SCRIPTS_ROOT}")/..
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
source $SCRIPTS_ROOT/style_info.sh
|
||||
source $SCRIPTS_ROOT/lib/init.sh
|
||||
source $SCRIPTS_ROOT/path_info.sh
|
||||
source $SCRIPTS_ROOT/function.sh
|
||||
|
||||
cd $SCRIPTS_ROOT
|
||||
|
||||
|
||||
Executable
+47
@@ -0,0 +1,47 @@
|
||||
#!/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.
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
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_ROOT}/scripts/init-config.sh
|
||||
|
||||
openim::util::ensure_docker_daemon_connectivity
|
||||
|
||||
DOCKER_COMPOSE_COMMAND=
|
||||
# Check if docker-compose command is available
|
||||
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
|
||||
|
||||
pushd "${OPENIM_ROOT}" >/dev/null
|
||||
${DOCKER_COMPOSE_COMMAND} up -d
|
||||
sleep 60
|
||||
${DOCKER_COMPOSE_COMMAND} ps
|
||||
${DOCKER_COMPOSE_COMMAND} logs
|
||||
popd >/dev/null
|
||||
@@ -0,0 +1,116 @@
|
||||
# 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.
|
||||
Executable
+142
@@ -0,0 +1,142 @@
|
||||
#!/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.
|
||||
set -o errexit
|
||||
set +o nounset
|
||||
set -o pipefail
|
||||
|
||||
# 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::common::dependency_name() {
|
||||
local targets=(
|
||||
mysql
|
||||
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
|
||||
# - mysql
|
||||
# - mongodb
|
||||
# - redis
|
||||
# - minio
|
||||
openim::common::dependency_port() {
|
||||
local targets=(
|
||||
${MYSQL_PORT} # MySQL port
|
||||
${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
|
||||
}
|
||||
Executable
+100
@@ -0,0 +1,100 @@
|
||||
#!/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
|
||||
|
||||
set -o errexit
|
||||
set +o nounset
|
||||
set -o pipefail
|
||||
|
||||
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
|
||||
[[ -z ${COMMON_SOURCED} ]] && source ${OPENIM_ROOT}/scripts/install/common.sh
|
||||
|
||||
# Start MySQL service
|
||||
docker run -d \
|
||||
--name mysql \
|
||||
-p 13306:3306 \
|
||||
-p 23306:33060 \
|
||||
-v "${DATA_DIR}/components/mysql/data:/var/lib/mysql" \
|
||||
-v "/etc/localtime:/etc/localtime" \
|
||||
-e MYSQL_ROOT_PASSWORD=${PASSWORD} \
|
||||
--restart always \
|
||||
mysql:5.7
|
||||
|
||||
# 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=${USER} \
|
||||
-e MONGO_INITDB_ROOT_PASSWORD=${PASSWORD} \
|
||||
-e MONGO_INITDB_DATABASE=openIM \
|
||||
-e MONGO_USERNAME=${USER} \
|
||||
-e MONGO_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=${USER} \
|
||||
-e MINIO_ROOT_PASSWORD=${PASSWORD} \
|
||||
--restart always \
|
||||
minio/minio server /data --console-address ':9090'
|
||||
Executable
+415
@@ -0,0 +1,415 @@
|
||||
#!/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 is a file that initializes variables for the automation script that initializes the config file
|
||||
# You need to supplement the script according to the specification.
|
||||
# Read: https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/contrib/init_config.md
|
||||
# 格式化 bash 注释:https://tool.lu/shell/
|
||||
|
||||
OPENIM_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
|
||||
|
||||
# 生成文件存放目录
|
||||
LOCAL_OUTPUT_ROOT="${OPENIM_ROOT}/${OUT_DIR:-_output}"
|
||||
source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
||||
|
||||
#TODO
|
||||
# IP=http://127.0.0.1
|
||||
if [ -z "${IP}" ]; then
|
||||
IP=$(openim::util::get_server_ip)
|
||||
fi
|
||||
|
||||
function def() {
|
||||
local var_name="$1"
|
||||
local default_value="${2:-}"
|
||||
eval "readonly $var_name=\"\${$var_name:-$(printf '%q' "$default_value")}\""
|
||||
}
|
||||
|
||||
# app要能访问到此ip和端口或域名
|
||||
def "API_URL" "http://${IP}:10002"
|
||||
def "DATA_DIR" "${OPENIM_ROOT}"
|
||||
|
||||
# 设置统一的用户名,方便记忆
|
||||
def "USER" "root"
|
||||
|
||||
# 设置统一的密码,方便记忆
|
||||
def "PASSWORD" "openIM123"
|
||||
|
||||
# 设置统一的数据库名称,方便管理
|
||||
def "DATABASE_NAME" "openIM_v3"
|
||||
|
||||
# Linux系统 openim 用户
|
||||
def "LINUX_USERNAME" "openim"
|
||||
def "LINUX_PASSWORD" "${PASSWORD}"
|
||||
|
||||
# 设置安装目录
|
||||
def "INSTALL_DIR" "${LOCAL_OUTPUT_ROOT}/installs"
|
||||
mkdir -p ${INSTALL_DIR}
|
||||
|
||||
def "ENV_FILE" "${OPENIM_ROOT}/scripts/install/environment.sh"
|
||||
|
||||
###################### openim 配置 ######################
|
||||
# read: https://github.com/OpenIMSDK/Open-IM-Server/blob/main/deployment/init/README.md
|
||||
def "OPENIM_DATA_DIR" "/data/openim"
|
||||
def "OPENIM_INSTALL_DIR" "/opt/openim"
|
||||
def "OPENIM_CONFIG_DIR" "/etc/openim"
|
||||
def "OPENIM_LOG_DIR" "/var/log/openim"
|
||||
def "CA_FILE" "${OPENIM_CONFIG_DIR}/cert/ca.pem"
|
||||
|
||||
def "OPNEIM_CONFIG" "${OPENIM_ROOT}/config"
|
||||
# TODO 注意: 一般的配置都可以使用 def 函数来定义,如果是包含特殊字符,比如说:
|
||||
# TODO readonly MSG_DESTRUCT_TIME=${MSG_DESTRUCT_TIME:-'0 2 * * *'}
|
||||
# TODO 使用 readonly 来定义合适,负责无法正常解析, 并且 yaml 模板需要加 "" 来包裹
|
||||
|
||||
###################### Zookeeper 配置信息 ######################
|
||||
def "ZOOKEEPER_SCHEMA" "openim" # Zookeeper的模式
|
||||
def "ZOOKEEPER_PORT" "2181" # Zookeeper的端口
|
||||
def "ZOOKEEPER_ADDRESS" "127.0.0.1" # Zookeeper的地址
|
||||
def "ZOOKEEPER_USERNAME" "" # Zookeeper的用户名
|
||||
def "ZOOKEEPER_PASSWORD" "" # Zookeeper的密码
|
||||
|
||||
###################### MySQL 配置信息 ######################
|
||||
def "MYSQL_PORT" "13306" # MySQL的端口
|
||||
def "MYSQL_ADDRESS" "127.0.0.1" # MySQL的地址
|
||||
def "MYSQL_USERNAME" "${USER}" # MySQL的用户名
|
||||
def "MYSQL_PASSWORD" "${PASSWORD}" # MySQL的密码
|
||||
def "MYSQL_DATABASE" "${DATABASE_NAME}" # MySQL的数据库名
|
||||
def "MYSQL_MAX_OPEN_CONN" "1000" # 最大打开的连接数
|
||||
def "MYSQL_MAX_IDLE_CONN" "100" # 最大空闲连接数
|
||||
def "MYSQL_MAX_LIFETIME" "60" # 连接可以重用的最大生命周期(秒)
|
||||
def "MYSQL_LOG_LEVEL" "4" # 日志级别
|
||||
def "MYSQL_SLOW_THRESHOLD" "500" # 慢查询阈值(毫秒)
|
||||
|
||||
###################### MongoDB 配置信息 ######################
|
||||
def "MONGO_URI" # MongoDB的URI
|
||||
def "MONGO_PORT" "37017" # MongoDB的端口
|
||||
def "MONGO_ADDRESS" "127.0.0.1" # MongoDB的地址
|
||||
def "MONGO_DATABASE" "${DATABASE_NAME}" # MongoDB的数据库名
|
||||
def "MONGO_USERNAME" "${USER}" # MongoDB的用户名
|
||||
def "MONGO_PASSWORD" "${PASSWORD}" # MongoDB的密码
|
||||
def "MONGO_MAX_POOL_SIZE" "100" # 最大连接池大小
|
||||
|
||||
###################### Object 配置信息 ######################
|
||||
def "OBJECT_ENABLE" "minio" # 对象是否启用
|
||||
def "OBJECT_APIURL" "http://${IP}:10002" # 对象的API地址
|
||||
def "MINIO_BUCKET" "openim" # MinIO的存储桶名称
|
||||
def "MINIO_PORT" "10005" # MinIO的端口
|
||||
# MinIO的端点URL
|
||||
readonly MINIO_ENDPOINT=${MINIO_ENDPOINT:-"http://127.0.0.1:${MINIO_PORT}"}
|
||||
def "MINIO_ACCESS_KEY" "${USER}" # MinIO的访问密钥ID
|
||||
def "MINIO_SECRET_KEY" "${PASSWORD}" # MinIO的密钥
|
||||
def "MINIO_SESSION_TOKEN" # MinIO的会话令牌
|
||||
readonly MINIO_SIGN_ENDPOINT=${MINIO_SIGN_ENDPOINT:-"http://${IP}:${MINIO_PORT}"} # signEndpoint为minio公网地址 # MinIO的会话令牌
|
||||
def "COS_BUCKET_URL" "https://temp-1252357374.cos.ap-chengdu.myqcloud.com" # 腾讯云COS的存储桶URL
|
||||
def "COS_SECRET_ID" # 腾讯云COS的密钥ID
|
||||
def "COS_SECRET_KEY" # 腾讯云COS的密钥
|
||||
def "COS_SESSION_TOKEN" # 腾讯云COS的会话令牌
|
||||
def "OSS_ENDPOINT" "https://oss-cn-chengdu.aliyuncs.com" # 阿里云OSS的端点URL
|
||||
def "OSS_BUCKET" "demo-9999999" # 阿里云OSS的存储桶名称
|
||||
def "OSS_BUCKET_URL" "https://demo-9999999.oss-cn-chengdu.aliyuncs.com" # 阿里云OSS的存储桶URL
|
||||
def "OSS_ACCESS_KEY_ID" # 阿里云OSS的访问密钥ID
|
||||
def "OSS_ACCESS_KEY_SECRET" # 阿里云OSS的密钥
|
||||
def "OSS_SESSION_TOKEN" # 阿里云OSS的会话令牌
|
||||
|
||||
###################### Redis 配置信息 ######################
|
||||
def "REDIS_PORT" "16379" # Redis的端口
|
||||
def "REDIS_ADDRESS" "127.0.0.1" # Redis的地址
|
||||
def "REDIS_USERNAME" # Redis的用户名
|
||||
def "REDIS_PASSWORD" "${PASSWORD}" # Redis的密码
|
||||
|
||||
###################### Kafka 配置信息 ######################
|
||||
def "KAFKA_USERNAME" # Kafka的用户名
|
||||
def "KAFKA_PASSWORD" # Kafka的密码
|
||||
def "KAFKA_PORT" "9092" # Kafka的端口
|
||||
def "KAFKA_ADDR" "127.0.0.1" # Kafka的地址
|
||||
def "KAFKA_LATESTMSG_REDIS_TOPIC" "latestMsgToRedis" # Kafka的最新消息到Redis的主题
|
||||
def "KAFKA_OFFLINEMSG_MONGO_TOPIC" "offlineMsgToMongoMysql" # Kafka的离线消息到Mongo的主题
|
||||
def "KAFKA_MSG_PUSH_TOPIC" "msgToPush" # Kafka的消息到推送的主题
|
||||
def "KAFKA_CONSUMERGROUPID_REDIS" "redis" # Kafka的消费组ID到Redis
|
||||
def "KAFKA_CONSUMERGROUPID_MONGO" "mongo" # Kafka的消费组ID到Mongo
|
||||
def "KAFKA_CONSUMERGROUPID_MYSQL" "mysql" # Kafka的消费组ID到MySql
|
||||
def "KAFKA_CONSUMERGROUPID_PUSH" "push" # Kafka的消费组ID到推送
|
||||
|
||||
###################### RPC 配置信息 ######################
|
||||
def "RPC_REGISTER_IP" # RPC的注册IP
|
||||
def "RPC_LISTEN_IP" "0.0.0.0" # RPC的监听IP
|
||||
|
||||
###################### API 配置信息 ######################
|
||||
# API的开放端口, 只能设置一个端口
|
||||
def "API_OPENIM_PORT" "10002"
|
||||
def "API_LISTEN_IP" "0.0.0.0" # API的监听IP
|
||||
|
||||
###################### RPC Port Configuration Variables ######################
|
||||
# For launching multiple programs, just fill in multiple ports separated by commas
|
||||
# For example:
|
||||
# readonly OPENIM_USER_PORT=${OPENIM_USER_PORT:-'10110, 10111, 10112'} #Try not to have Spaces
|
||||
|
||||
# OpenIM用户服务端口
|
||||
readonly OPENIM_USER_PORT=${OPENIM_USER_PORT:-'10110'}
|
||||
# OpenIM朋友服务端口
|
||||
readonly OPENIM_FRIEND_PORT=${OPENIM_FRIEND_PORT:-'10120'}
|
||||
# OpenIM消息服务端口
|
||||
readonly OPENIM_MESSAGE_PORT=${OPENIM_MESSAGE_PORT:-'10130'}
|
||||
# OpenIM消息网关服务端口
|
||||
readonly OPENIM_MESSAGE_GATEWAY_PORT=${OPENIM_MESSAGE_GATEWAY_PORT:-'10140'}
|
||||
# OpenIM组服务端口
|
||||
readonly OPENIM_GROUP_PORT=${OPENIM_GROUP_PORT:-'10150'}
|
||||
# OpenIM授权服务端口
|
||||
readonly OPENIM_AUTH_PORT=${OPENIM_AUTH_PORT:-'10160'}
|
||||
# OpenIM推送服务端口
|
||||
readonly OPENIM_PUSH_PORT=${OPENIM_PUSH_PORT:-'10170'}
|
||||
# OpenIM对话服务端口
|
||||
readonly OPENIM_CONVERSATION_PORT=${OPENIM_CONVERSATION_PORT:-'10180'}
|
||||
# OpenIM第三方服务端口
|
||||
readonly OPENIM_THIRD_PORT=${OPENIM_THIRD_PORT:-'10190'}
|
||||
|
||||
###################### RPC Register Name Variables ######################
|
||||
def "OPENIM_USER_NAME" "User" # OpenIM用户服务名称
|
||||
def "OPENIM_FRIEND_NAME" "Friend" # OpenIM朋友服务名称
|
||||
def "OPENIM_MSG_NAME" "Msg" # OpenIM消息服务名称
|
||||
def "OPENIM_PUSH_NAME" "Push" # OpenIM推送服务名称
|
||||
def "OPENIM_MESSAGE_GATEWAY_NAME" "MessageGateway" # OpenIM消息网关服务名称
|
||||
def "OPENIM_GROUP_NAME" "Group" # OpenIM组服务名称
|
||||
def "OPENIM_AUTH_NAME" "Auth" # OpenIM授权服务名称
|
||||
def "OPENIM_CONVERSATION_NAME" "Conversation" # OpenIM对话服务名称
|
||||
def "OPENIM_THIRD_NAME" "Third" # OpenIM第三方服务名称
|
||||
|
||||
###################### Log Configuration Variables ######################
|
||||
def "LOG_STORAGE_LOCATION" "${OPENIM_ROOT}/logs/" # 日志存储位置
|
||||
def "LOG_ROTATION_TIME" "24" # 日志轮替时间
|
||||
def "LOG_REMAIN_ROTATION_COUNT" "2" # 保留的日志轮替数量
|
||||
def "LOG_REMAIN_LOG_LEVEL" "6" # 保留的日志级别
|
||||
def "LOG_IS_STDOUT" "false" # 是否将日志输出到标准输出
|
||||
def "LOG_IS_JSON" "false" # 日志是否为JSON格式
|
||||
def "LOG_WITH_STACK" "false" # 日志是否带有堆栈信息
|
||||
|
||||
###################### Variables definition ######################
|
||||
def "OPENIM_WS_PORT" "10001" # OpenIM WS端口
|
||||
def "WEBSOCKET_MAX_CONN_NUM" "100000" # Websocket最大连接数
|
||||
def "WEBSOCKET_MAX_MSG_LEN" "4096" # Websocket最大消息长度
|
||||
def "WEBSOCKET_TIMEOUT" "10" # Websocket超时
|
||||
def "PUSH_ENABLE" "getui" # 推送是否启用
|
||||
# GeTui推送URL
|
||||
readonly GETUI_PUSH_URL=${GETUI_PUSH_URL:-'https://restapi.getui.com/v2/$appId'}
|
||||
def "FCM_SERVICE_ACCOUNT" "x.json" # FCM服务账户
|
||||
def "JPNS_APP_KEY" # JPNS应用密钥
|
||||
def "JPNS_MASTER_SECRET" # JPNS主密钥
|
||||
def "JPNS_PUSH_URL" # JPNS推送URL
|
||||
def "JPNS_PUSH_INTENT" # JPNS推送意图
|
||||
def "MANAGER_USERID_1" "openIM123456" # 管理员ID 1
|
||||
def "MANAGER_USERID_2" "openIM654321" # 管理员ID 2
|
||||
def "MANAGER_USERID_3" "openIMAdmin" # 管理员ID 3
|
||||
def "NICKNAME_1" "system1" # 昵称1
|
||||
def "NICKNAME_2" "system2" # 昵称2
|
||||
def "NICKNAME_3" "system3" # 昵称3
|
||||
def "MULTILOGIN_POLICY" "1" # 多登录策略
|
||||
def "CHAT_PERSISTENCE_MYSQL" "true" # 聊天持久化MySQL
|
||||
def "MSG_CACHE_TIMEOUT" "86400" # 消息缓存超时
|
||||
def "GROUP_MSG_READ_RECEIPT" "true" # 群消息已读回执启用
|
||||
def "SINGLE_MSG_READ_RECEIPT" "true" # 单一消息已读回执启用
|
||||
def "RETAIN_CHAT_RECORDS" "365" # 保留聊天记录
|
||||
# 聊天记录清理时间
|
||||
readonly CHAT_RECORDS_CLEAR_TIME=${CHAT_RECORDS_CLEAR_TIME:-'0 2 * * 3'}
|
||||
# 消息销毁时间
|
||||
readonly MSG_DESTRUCT_TIME=${MSG_DESTRUCT_TIME:-'0 2 * * *'}
|
||||
def "SECRET" "${PASSWORD}" # 密钥
|
||||
def "TOKEN_EXPIRE" "90" # Token到期时间
|
||||
def "FRIEND_VERIFY" "false" # 朋友验证
|
||||
def "IOS_PUSH_SOUND" "xxx" # IOS推送声音
|
||||
def "IOS_BADGE_COUNT" "true" # IOS徽章计数
|
||||
def "IOS_PRODUCTION" "false" # IOS生产
|
||||
|
||||
###################### Prometheus 配置信息 ######################
|
||||
def "PROMETHEUS_ENABLE" "false" # 是否启用 Prometheus
|
||||
def "USER_PROM_PORT" "20110" # User 服务的 Prometheus 端口
|
||||
def "FRIEND_PROM_PORT" "20120" # Friend 服务的 Prometheus 端口
|
||||
def "MESSAGE_PROM_PORT" "20130" # Message 服务的 Prometheus 端口
|
||||
def "MSG_GATEWAY_PROM_PORT" "20140" # Message Gateway 服务的 Prometheus 端口
|
||||
def "GROUP_PROM_PORT" "20150" # Group 服务的 Prometheus 端口
|
||||
def "AUTH_PROM_PORT" "20160" # Auth 服务的 Prometheus 端口
|
||||
def "PUSH_PROM_PORT" "20170" # Push 服务的 Prometheus 端口
|
||||
def "CONVERSATION_PROM_PORT" "20230" # Conversation 服务的 Prometheus 端口
|
||||
def "RTC_PROM_PORT" "21300" # RTC 服务的 Prometheus 端口
|
||||
def "THIRD_PROM_PORT" "21301" # Third 服务的 Prometheus 端口
|
||||
# Message Transfer 服务的 Prometheus 端口列表
|
||||
readonly MSG_TRANSFER_PROM_PORT=${MSG_TRANSFER_PROM_PORT:-'21400, 21401, 21402, 21403'}
|
||||
|
||||
###################### OpenIM openim-api ######################
|
||||
def "OPENIM_API_HOST" "127.0.0.1"
|
||||
def "OPENIM_API_BINARY" "${OPENIM_OUTPUT_HOSTBIN}/openim-api" # OpenIM openim-api 二进制文件路径
|
||||
def "OPENIM_API_CONFIG" "${OPENIM_ROOT}/config/" # OpenIM openim-api 配置文件路径
|
||||
def "OPENIM_API_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-api" # OpenIM openim-api 日志存储路径
|
||||
def "OPENIM_API_LOG_LEVEL" "info" # OpenIM openim-api 日志级别
|
||||
def "OPENIM_API_LOG_MAX_SIZE" "100" # OpenIM openim-api 日志最大大小(MB)
|
||||
def "OPENIM_API_LOG_MAX_BACKUPS" "7" # OpenIM openim-api 日志最大备份数
|
||||
def "OPENIM_API_LOG_MAX_AGE" "7" # OpenIM openim-api 日志最大保存时间(天)
|
||||
def "OPENIM_API_LOG_COMPRESS" "false" # OpenIM openim-api 日志是否压缩
|
||||
def "OPENIM_API_LOG_WITH_STACK" "${LOG_WITH_STACK}" # OpenIM openim-api 日志是否带有堆栈信息
|
||||
|
||||
###################### OpenIM openim-cmdutils ######################
|
||||
def "OPENIM_CMDUTILS_HOST" "127.0.0.1"
|
||||
def "OPENIM_CMDUTILS_BINARY" "${OPENIM_OUTPUT_HOSTBIN}/openim-cmdutils" # OpenIM openim-cmdutils 二进制文件路径
|
||||
def "OPENIM_CMDUTILS_CONFIG" "${OPENIM_ROOT}/config/" # OpenIM openim-cmdutils 配置文件路径
|
||||
def "OPENIM_CMDUTILS_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-cmdutils" # OpenIM openim-cmdutils 日志存储路径
|
||||
def "OPENIM_CMDUTILS_LOG_LEVEL" "info" # OpenIM openim-cmdutils 日志级别
|
||||
def "OPENIM_CMDUTILS_LOG_MAX_SIZE" "100" # OpenIM openim-cmdutils 日志最大大小(MB)
|
||||
def "OPENIM_CMDUTILS_LOG_MAX_BACKUPS" "7" # OpenIM openim-cmdutils 日志最大备份数
|
||||
def "OPENIM_CMDUTILS_LOG_MAX_AGE" "7" # OpenIM openim-cmdutils 日志最大保存时间(天)
|
||||
def "OPENIM_CMDUTILS_LOG_COMPRESS" "false" # OpenIM openim-cmdutils 日志是否压缩
|
||||
def "OPENIM_CMDUTILS_LOG_WITH_STACK" "${LOG_WITH_STACK}" # OpenIM openim-cmdutils 日志是否带有堆栈信息
|
||||
|
||||
###################### OpenIM openim-crontask ######################
|
||||
def "OPENIM_CRONTASK_HOST" "127.0.0.1"
|
||||
def "OPENIM_CRONTASK_BINARY" "${OPENIM_OUTPUT_HOSTBIN}/openim-crontask" # OpenIM openim-crontask 二进制文件路径
|
||||
def "OPENIM_CRONTASK_CONFIG" "${OPENIM_ROOT}/config/" # OpenIM openim-crontask 配置文件路径
|
||||
def "OPENIM_CRONTASK_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-crontask" # OpenIM openim-crontask 日志存储路径
|
||||
def "OPENIM_CRONTASK_LOG_LEVEL" "info" # OpenIM openim-crontask 日志级别
|
||||
def "OPENIM_CRONTASK_LOG_MAX_SIZE" "100" # OpenIM openim-crontask 日志最大大小(MB)
|
||||
def "OPENIM_CRONTASK_LOG_MAX_BACKUPS" "7" # OpenIM openim-crontask 日志最大备份数
|
||||
def "OPENIM_CRONTASK_LOG_MAX_AGE" "7" # OpenIM openim-crontask 日志最大保存时间(天)
|
||||
def "OPENIM_CRONTASK_LOG_COMPRESS" "false" # OpenIM openim-crontask 日志是否压缩
|
||||
def "OPENIM_CRONTASK_LOG_WITH_STACK" "${LOG_WITH_STACK}" # OpenIM openim-crontask 日志是否带有堆栈信息
|
||||
|
||||
###################### OpenIM openim-msggateway ######################
|
||||
def "OPENIM_MSGGATEWAY_HOST" "127.0.0.1"
|
||||
def "OPENIM_MSGGATEWAY_BINARY" "${OPENIM_OUTPUT_HOSTBIN}/openim-msggateway"
|
||||
def "OPENIM_MSGGATEWAY_CONFIG" "${OPENIM_ROOT}/config/"
|
||||
def "OPENIM_MSGGATEWAY_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-msggateway"
|
||||
def "OPENIM_MSGGATEWAY_LOG_LEVEL" "info"
|
||||
def "OPENIM_MSGGATEWAY_LOG_MAX_SIZE" "100"
|
||||
def "OPENIM_MSGGATEWAY_LOG_MAX_BACKUPS" "7"
|
||||
def "OPENIM_MSGGATEWAY_LOG_MAX_AGE" "7"
|
||||
def "OPENIM_MSGGATEWAY_LOG_COMPRESS" "false"
|
||||
def "OPENIM_MSGGATEWAY_LOG_WITH_STACK" "${LOG_WITH_STACK}"
|
||||
|
||||
# 定义 openim-msggateway 的数量, 默认为 4
|
||||
readonly OPENIM_MSGGATEWAY_NUM=${OPENIM_MSGGATEWAY_NUM:-'4'}
|
||||
|
||||
###################### OpenIM openim-msgtransfer ######################
|
||||
def "OPENIM_MSGTRANSFER_HOST" "127.0.0.1"
|
||||
def "OPENIM_MSGTRANSFER_BINARY" "${OPENIM_OUTPUT_HOSTBIN}/openim-msgtransfer" # OpenIM openim-msgtransfer 二进制文件路径
|
||||
def "OPENIM_MSGTRANSFER_CONFIG" "${OPENIM_ROOT}/config/" # OpenIM openim-msgtransfer 配置文件路径
|
||||
def "OPENIM_MSGTRANSFER_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-msgtransfer" # OpenIM openim-msgtransfer 日志存储路径
|
||||
def "OPENIM_MSGTRANSFER_LOG_LEVEL" "info" # OpenIM openim-msgtransfer 日志级别
|
||||
def "OPENIM_MSGTRANSFER_LOG_MAX_SIZE" "100" # OpenIM openim-msgtransfer 日志最大大小(MB)
|
||||
def "OPENIM_MSGTRANSFER_LOG_MAX_BACKUPS" "7" # OpenIM openim-msgtransfer 日志最大备份数
|
||||
def "OPENIM_MSGTRANSFER_LOG_MAX_AGE" "7" # OpenIM openim-msgtransfer 日志最大保存时间(天)
|
||||
def "OPENIM_MSGTRANSFER_LOG_COMPRESS" "false" # OpenIM openim-msgtransfer 日志是否压缩
|
||||
def "OPENIM_MSGTRANSFER_LOG_WITH_STACK" "${LOG_WITH_STACK}" # OpenIM openim-msgtransfer 日志是否带有堆栈信息
|
||||
|
||||
###################### OpenIM openim-push ######################
|
||||
def "OPENIM_PUSH_HOST" "127.0.0.1"
|
||||
def "OPENIM_PUSH_BINARY" "${OPENIM_OUTPUT_HOSTBIN}/openim-push" # OpenIM openim-push 二进制文件路径
|
||||
def "OPENIM_PUSH_CONFIG" "${OPENIM_ROOT}/config/" # OpenIM openim-push 配置文件路径
|
||||
def "OPENIM_PUSH_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-push" # OpenIM openim-push 日志存储路径
|
||||
def "OPENIM_PUSH_LOG_LEVEL" "info" # OpenIM openim-push 日志级别
|
||||
def "OPENIM_PUSH_LOG_MAX_SIZE" "100" # OpenIM openim-push 日志最大大小(MB)
|
||||
def "OPENIM_PUSH_LOG_MAX_BACKUPS" "7" # OpenIM openim-push 日志最大备份数
|
||||
def "OPENIM_PUSH_LOG_MAX_AGE" "7" # OpenIM openim-push 日志最大保存时间(天)
|
||||
def "OPENIM_PUSH_LOG_COMPRESS" "false" # OpenIM openim-push 日志是否压缩
|
||||
def "OPENIM_PUSH_LOG_WITH_STACK" "${LOG_WITH_STACK}" # OpenIM openim-push 日志是否带有堆栈信息
|
||||
|
||||
###################### OpenIM openim-rpc-auth ######################
|
||||
def "OPENIM_RPC_AUTH_HOST" "127.0.0.1"
|
||||
def "OPENIM_RPC_AUTH_BINARY" "${OPENIM_OUTPUT_HOSTBIN}/openim-rpc-auth" # OpenIM openim-rpc-auth 二进制文件路径
|
||||
def "OPENIM_RPC_AUTH_CONFIG" "${OPENIM_ROOT}/config/" # OpenIM openim-rpc-auth 配置文件路径
|
||||
def "OPENIM_RPC_AUTH_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-rpc-auth" # OpenIM openim-rpc-auth 日志存储路径
|
||||
def "OPENIM_RPC_AUTH_LOG_LEVEL" "info" # OpenIM openim-rpc-auth 日志级别
|
||||
def "OPENIM_RPC_AUTH_LOG_MAX_SIZE" "100" # OpenIM openim-rpc-auth 日志最大大小(MB)
|
||||
def "OPENIM_RPC_AUTH_LOG_MAX_BACKUPS" "7" # OpenIM openim-rpc-auth 日志最大备份数
|
||||
def "OPENIM_RPC_AUTH_LOG_MAX_AGE" "7" # OpenIM openim-rpc-auth 日志最大保存时间(天)
|
||||
def "OPENIM_RPC_AUTH_LOG_COMPRESS" "false" # OpenIM openim-rpc-auth 日志是否压缩
|
||||
def "OPENIM_RPC_AUTH_LOG_WITH_STACK" "${LOG_WITH_STACK}" # OpenIM openim-rpc-auth 日志是否带有堆栈信息
|
||||
|
||||
###################### OpenIM openim-rpc-conversation ######################
|
||||
def "OPENIM_RPC_CONVERSATION_HOST" "127.0.0.1"
|
||||
def "OPENIM_RPC_CONVERSATION_BINARY" "${OPENIM_OUTPUT_HOSTBIN}/openim-rpc-conversation" # OpenIM openim-rpc-conversation 二进制文件路径
|
||||
def "OPENIM_RPC_CONVERSATION_CONFIG" "${OPENIM_ROOT}/config/" # OpenIM openim-rpc-conversation 配置文件路径
|
||||
def "OPENIM_RPC_CONVERSATION_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-rpc-conversation" # OpenIM openim-rpc-conversation 日志存储路径
|
||||
def "OPENIM_RPC_CONVERSATION_LOG_LEVEL" "info" # OpenIM openim-rpc-conversation 日志级别
|
||||
def "OPENIM_RPC_CONVERSATION_LOG_MAX_SIZE" "100" # OpenIM openim-rpc-conversation 日志最大大小(MB)
|
||||
def "OPENIM_RPC_CONVERSATION_LOG_MAX_BACKUPS" "7" # OpenIM openim-rpc-conversation 日志最大备份数
|
||||
def "OPENIM_RPC_CONVERSATION_LOG_MAX_AGE" "7" # OpenIM openim-rpc-conversation 日志最大保存时间(天)
|
||||
def "OPENIM_RPC_CONVERSATION_LOG_COMPRESS" "false" # OpenIM openim-rpc-conversation 日志是否压缩
|
||||
def "OPENIM_RPC_CONVERSATION_LOG_WITH_STACK" "${LOG_WITH_STACK}" # OpenIM openim-rpc-conversation 日志是否带有堆栈信息
|
||||
|
||||
###################### OpenIM openim-rpc-friend ######################
|
||||
def "OPENIM_RPC_FRIEND_HOST" "127.0.0.1"
|
||||
def "OPENIM_RPC_FRIEND_BINARY" "${OPENIM_OUTPUT_HOSTBIN}/openim-rpc-friend" # OpenIM openim-rpc-friend 二进制文件路径
|
||||
def "OPENIM_RPC_FRIEND_CONFIG" "${OPENIM_ROOT}/config/" # OpenIM openim-rpc-friend 配置文件路径
|
||||
def "OPENIM_RPC_FRIEND_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-rpc-friend" # OpenIM openim-rpc-friend 日志存储路径
|
||||
def "OPENIM_RPC_FRIEND_LOG_LEVEL" "info" # OpenIM openim-rpc-friend 日志级别
|
||||
def "OPENIM_RPC_FRIEND_LOG_MAX_SIZE" "100" # OpenIM openim-rpc-friend 日志最大大小(MB)
|
||||
def "OPENIM_RPC_FRIEND_LOG_MAX_BACKUPS" "7" # OpenIM openim-rpc-friend 日志最大备份数
|
||||
def "OPENIM_RPC_FRIEND_LOG_MAX_AGE" "7" # OpenIM openim-rpc-friend 日志最大保存时间(天)
|
||||
def "OPENIM_RPC_FRIEND_LOG_COMPRESS" "false" # OpenIM openim-rpc-friend 日志是否压缩
|
||||
def "OPENIM_RPC_FRIEND_LOG_WITH_STACK" "${LOG_WITH_STACK}" # OpenIM openim-rpc-friend 日志是否带有堆栈信息
|
||||
|
||||
###################### OpenIM openim-rpc-group ######################
|
||||
def "OPENIM_RPC_GROUP_HOST" "127.0.0.1"
|
||||
def "OPENIM_RPC_GROUP_BINARY" "${OPENIM_OUTPUT_HOSTBIN}/openim-rpc-group" # OpenIM openim-rpc-group 二进制文件路径
|
||||
def "OPENIM_RPC_GROUP_CONFIG" "${OPENIM_ROOT}/config/" # OpenIM openim-rpc-group 配置文件路径
|
||||
def "OPENIM_RPC_GROUP_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-rpc-group" # OpenIM openim-rpc-group 日志存储路径
|
||||
def "OPENIM_RPC_GROUP_LOG_LEVEL" "info" # OpenIM openim-rpc-group 日志级别
|
||||
def "OPENIM_RPC_GROUP_LOG_MAX_SIZE" "100" # OpenIM openim-rpc-group 日志最大大小(MB)
|
||||
def "OPENIM_RPC_GROUP_LOG_MAX_BACKUPS" "7" # OpenIM openim-rpc-group 日志最大备份数
|
||||
def "OPENIM_RPC_GROUP_LOG_MAX_AGE" "7" # OpenIM openim-rpc-group 日志最大保存时间(天)
|
||||
def "OPENIM_RPC_GROUP_LOG_COMPRESS" "false" # OpenIM openim-rpc-group 日志是否压缩
|
||||
def "OPENIM_RPC_GROUP_LOG_WITH_STACK" "${LOG_WITH_STACK}" # OpenIM openim-rpc-group 日志是否带有堆栈信息
|
||||
|
||||
###################### OpenIM openim-rpc-msg ######################
|
||||
def "OPENIM_RPC_MSG_HOST" "127.0.0.1"
|
||||
def "OPENIM_RPC_MSG_BINARY" "${OPENIM_OUTPUT_HOSTBIN}/openim-rpc-msg" # OpenIM openim-rpc-msg 二进制文件路径
|
||||
def "OPENIM_RPC_MSG_CONFIG" "${OPENIM_ROOT}/config/" # OpenIM openim-rpc-msg 配置文件路径
|
||||
def "OPENIM_RPC_MSG_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-rpc-msg" # OpenIM openim-rpc-msg 日志存储路径
|
||||
def "OPENIM_RPC_MSG_LOG_LEVEL" "info" # OpenIM openim-rpc-msg 日志级别
|
||||
def "OPENIM_RPC_MSG_LOG_MAX_SIZE" "100" # OpenIM openim-rpc-msg 日志最大大小(MB)
|
||||
def "OPENIM_RPC_MSG_LOG_MAX_BACKUPS" "7" # OpenIM openim-rpc-msg 日志最大备份数
|
||||
def "OPENIM_RPC_MSG_LOG_MAX_AGE" "7" # OpenIM openim-rpc-msg 日志最大保存时间(天)
|
||||
def "OPENIM_RPC_MSG_LOG_COMPRESS" "false" # OpenIM openim-rpc-msg 日志是否压缩
|
||||
def "OPENIM_RPC_MSG_LOG_WITH_STACK" "${LOG_WITH_STACK}" # OpenIM openim-rpc-msg 日志是否带有堆栈信息
|
||||
|
||||
###################### OpenIM openim-rpc-third ######################
|
||||
def "OPENIM_RPC_THIRD_HOST" "127.0.0.1"
|
||||
def "OPENIM_RPC_THIRD_BINARY" "${OPENIM_OUTPUT_HOSTBIN}/openim-rpc-third" # OpenIM openim-rpc-third 二进制文件路径
|
||||
def "OPENIM_RPC_THIRD_CONFIG" "${OPENIM_ROOT}/config/" # OpenIM openim-rpc-third 配置文件路径
|
||||
def "OPENIM_RPC_THIRD_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-rpc-third" # OpenIM openim-rpc-third 日志存储路径
|
||||
def "OPENIM_RPC_THIRD_LOG_LEVEL" "info" # OpenIM openim-rpc-third 日志级别
|
||||
def "OPENIM_RPC_THIRD_LOG_MAX_SIZE" "100" # OpenIM openim-rpc-third 日志最大大小(MB)
|
||||
def "OPENIM_RPC_THIRD_LOG_MAX_BACKUPS" "7" # OpenIM openim-rpc-third 日志最大备份数
|
||||
def "OPENIM_RPC_THIRD_LOG_MAX_AGE" "7" # OpenIM openim-rpc-third 日志最大保存时间(天)
|
||||
def "OPENIM_RPC_THIRD_LOG_COMPRESS" "false" # OpenIM openim-rpc-third 日志是否压缩
|
||||
def "OPENIM_RPC_THIRD_LOG_WITH_STACK" "${LOG_WITH_STACK}" # OpenIM openim-rpc-third 日志是否带有堆栈信息
|
||||
|
||||
###################### OpenIM openim-rpc-user ######################
|
||||
def "OPENIM_RPC_USER_HOST" "127.0.0.1"
|
||||
def "OPENIM_RPC_USER_BINARY" "${OPENIM_OUTPUT_HOSTBIN}/openim-rpc-user" # OpenIM openim-rpc-user 二进制文件路径
|
||||
def "OPENIM_RPC_USER_CONFIG" "${OPENIM_ROOT}/config/" # OpenIM openim-rpc-user 配置文件路径
|
||||
def "OPENIM_RPC_USER_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-rpc-user" # OpenIM openim-rpc-user 日志存储路径
|
||||
def "OPENIM_RPC_USER_LOG_LEVEL" "info" # OpenIM openim-rpc-user 日志级别
|
||||
def "OPENIM_RPC_USER_LOG_MAX_SIZE" "100" # OpenIM openim-rpc-user 日志最大大小(MB)
|
||||
def "OPENIM_RPC_USER_LOG_MAX_BACKUPS" "7" # OpenIM openim-rpc-user 日志最大备份数
|
||||
def "OPENIM_RPC_USER_LOG_MAX_AGE" "7" # OpenIM openim-rpc-user 日志最大保存时间(天)
|
||||
def "OPENIM_RPC_USER_LOG_COMPRESS" "false" # OpenIM openim-rpc-user 日志是否压缩
|
||||
def "OPENIM_RPC_USER_LOG_WITH_STACK" "${LOG_WITH_STACK}" # OpenIM openim-rpc-user 日志是否带有堆栈信息
|
||||
|
||||
###################### 设计中...暂时不需要######################
|
||||
|
||||
# openimctl 配置
|
||||
def "CONFIG_USER_USERNAME" "admin"
|
||||
def "CONFIG_USER_PASSWORD" "Admin@2021"
|
||||
def "CONFIG_USER_CLIENT_CERTIFICATE" "${HOME}/.openim/cert/admin.pem"
|
||||
def "CONFIG_USER_CLIENT_KEY" "${HOME}/.openim/cert/admin-key.pem"
|
||||
def "CONFIG_SERVER_ADDRESS" "${OPENIM_APISERVER_HOST}:${OPENIM_APISERVER_SECURE_BIND_PORT}"
|
||||
def "CONFIG_SERVER_CERTIFICATE_AUTHORITY" "${CA_FILE}"
|
||||
Executable
+116
@@ -0,0 +1,116 @@
|
||||
#!/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
|
||||
#
|
||||
# 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
|
||||
Executable
+149
@@ -0,0 +1,149 @@
|
||||
#!/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
|
||||
|
||||
source ${OPENIM_ROOT}/scripts/install/openim-msggateway.sh
|
||||
source ${OPENIM_ROOT}/scripts/install/openim-msgtransfer.sh
|
||||
source ${OPENIM_ROOT}/scripts/install/openim-push.sh
|
||||
source ${OPENIM_ROOT}/scripts/install/openim-rpc.sh
|
||||
source ${OPENIM_ROOT}/scripts/install/openim-crontask.sh
|
||||
source ${OPENIM_ROOT}/scripts/install/openim-api.sh
|
||||
source ${OPENIM_ROOT}/scripts/install/openim-man.sh
|
||||
source ${OPENIM_ROOT}/scripts/install/openim-tools.sh
|
||||
source ${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::log::info "check openim dependency"
|
||||
openim::util::check_ports ${OPENIM_DEPENDENCY_PORT_LISTARIES[@]}
|
||||
|
||||
openim::msggateway::install || return 1
|
||||
openim::msgtransfer::install || return 1
|
||||
openim::push::install || return 1
|
||||
openim::rpc::install || return 1
|
||||
openim::crontask::install || return 1
|
||||
openim::api::install || return 1
|
||||
|
||||
openim::log::success "openim install success"
|
||||
}
|
||||
|
||||
function openim::uninstall::uninstall_openim()
|
||||
{
|
||||
openim::log::info "uninstall openim"
|
||||
|
||||
openim::msggateway::uninstall || return 1
|
||||
openim::msgtransfer::uninstall || return 1
|
||||
openim::push::uninstall || return 1
|
||||
openim::rpc::uninstall || return 1
|
||||
openim::crontask::uninstall || return 1
|
||||
openim::api::uninstall || return 1
|
||||
|
||||
openim::log::success "openim uninstall success"
|
||||
}
|
||||
|
||||
function openim::install::status()
|
||||
{
|
||||
openim::log::info "check openim status"
|
||||
|
||||
openim::msggateway::status || return 1
|
||||
openim::msgtransfer::status || return 1
|
||||
openim::push::status || return 1
|
||||
openim::rpc::status || return 1
|
||||
openim::crontask::status || return 1
|
||||
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
|
||||
Executable
+112
@@ -0,0 +1,112 @@
|
||||
#!/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 -o errexit
|
||||
set +o nounset
|
||||
set -o pipefail
|
||||
|
||||
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[@]##*/}")
|
||||
|
||||
function openim::api::start()
|
||||
{
|
||||
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} ..."
|
||||
|
||||
printf "+------------------------+--------------+\n"
|
||||
printf "| Service Name | Port |\n"
|
||||
printf "+------------------------+--------------+\n"
|
||||
|
||||
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"
|
||||
done
|
||||
# start all api services
|
||||
for ((i = 0; i < ${#OPENIM_API_SERVICE_LISTARIES[*]}; i++)); do
|
||||
openim::util::stop_services_with_name ${OPENIM_API_SERVICE_LISTARIES[$i]}
|
||||
openim::log::info "OpenIM ${OPENIM_API_SERVICE_LISTARIES[$i]} config path: ${OPENIM_API_CONFIG}"
|
||||
|
||||
# Get the service and Prometheus ports.
|
||||
OPENIM_API_SERVICE_PORTS=( $(openim::util::list-to-string ${OPENIM_API_PORT_LISTARIES[$i]}) )
|
||||
|
||||
# TODO Only one port is supported. An error occurs on multiple ports
|
||||
if [ ${#OPENIM_API_SERVICE_PORTS[@]} -ne 1 ]; then
|
||||
openim::log::error_exit "Set only one port for ${OPENIM_API_SERVICE_LISTARIES[$i]} service."
|
||||
fi
|
||||
|
||||
for ((j = 0; j < ${#OPENIM_API_SERVICE_PORTS[@]}; j++)); do
|
||||
openim::log::info "Starting ${OPENIM_API_SERVICE_LISTARIES[$i]} service, port: ${OPENIM_API_SERVICE_PORTS[j]}, binary root: ${OPENIM_OUTPUT_HOSTBIN}/${OPENIM_API_SERVICE_LISTARIES[$i]}"
|
||||
openim::api::start_service "${OPENIM_API_SERVICE_LISTARIES[$i]}" "${OPENIM_API_PORT_LISTARIES[j]}"
|
||||
sleep 1
|
||||
done
|
||||
done
|
||||
|
||||
OPENIM_API_PORT_STRINGARIES=( $(openim::util::list-to-string ${OPENIM_API_PORT_LISTARIES[@]}) )
|
||||
openim::util::check_ports ${OPENIM_API_PORT_STRINGARIES[@]}
|
||||
}
|
||||
|
||||
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}"
|
||||
|
||||
nohup ${cmd} >> "${LOG_FILE}" 2>&1 &
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
openim::log::error_exit "Failed to start ${binary_name} on port ${service_port}."
|
||||
fi
|
||||
}
|
||||
|
||||
###################################### Linux Systemd ######################################
|
||||
SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service"
|
||||
|
||||
function openim::api::install() {
|
||||
openim::log::info "Installing ${SERVER_NAME} ..."
|
||||
}
|
||||
|
||||
function openim::api::uninstall() {
|
||||
openim::log::info "Uninstalling ${SERVER_NAME} ..."
|
||||
|
||||
}
|
||||
|
||||
function openim::api::status() {
|
||||
openim::log::info "Checking ${SERVER_NAME} status ..."
|
||||
|
||||
openim::util::check_ports ${OPENIM_API_PORT_LISTARIES[@]}
|
||||
}
|
||||
|
||||
if [[ "$*" =~ openim::api:: ]];then
|
||||
eval $*
|
||||
fi
|
||||
Executable
+132
@@ -0,0 +1,132 @@
|
||||
#!/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()
|
||||
{
|
||||
openim::log::info "Start OpenIM Cron, binary root: ${SERVER_NAME}"
|
||||
openim::log::status "Start OpenIM Cron, path: ${OPENIM_CRONTASK_BINARY}"
|
||||
|
||||
openim::util::stop_services_with_name ${SERVER_NAME}
|
||||
|
||||
openim::log::status "start cron_task process, path: ${OPENIM_CRONTASK_BINARY}"
|
||||
nohup ${OPENIM_CRONTASK_BINARY} >> ${LOG_FILE} 2>&1 &
|
||||
openim::util::check_process_names ${SERVER_NAME}
|
||||
}
|
||||
|
||||
###################################### 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 ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/bin"
|
||||
|
||||
openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/bin/${SERVER_NAME}"
|
||||
|
||||
# 2. Generate and install the openim-crontask configuration file (openim-crontask.yaml)
|
||||
echo ${LINUX_PASSWORD} | sudo -S bash -c \
|
||||
"./scripts/genconfig.sh ${ENV_FILE} deployments/templates/${SERVER_NAME}.yaml > ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
|
||||
openim::log::status "${SERVER_NAME} config file: ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
|
||||
|
||||
# 3. Create and install the ${SERVER_NAME} systemd unit file
|
||||
echo ${LINUX_PASSWORD} | sudo -S bash -c \
|
||||
"./scripts/genconfig.sh ${ENV_FILE} deployments/templates/init/${SERVER_NAME}.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}/bin/${SERVER_NAME}"
|
||||
openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
|
||||
openim::common::sudo "rm -f /etc/systemd/system/${SERVER_NAME}.service"
|
||||
set -o errexit
|
||||
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.
|
||||
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 127.0.0.1 7070 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::crontask:: ]];then
|
||||
eval $*
|
||||
fi
|
||||
Executable
+96
@@ -0,0 +1,96 @@
|
||||
#!/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 # 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-*"
|
||||
set -o errexit
|
||||
|
||||
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
|
||||
Executable
+141
@@ -0,0 +1,141 @@
|
||||
#!/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.
|
||||
set -o errexit
|
||||
set +o nounset
|
||||
set -o pipefail
|
||||
|
||||
ulimit -n 200000
|
||||
|
||||
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()
|
||||
{
|
||||
openim::log::info "Start OpenIM Msggateway, binary root: ${SERVER_NAME}"
|
||||
openim::log::status "Start OpenIM Msggateway, path: ${OPENIM_MSGGATEWAY_BINARY}"
|
||||
|
||||
openim::util::stop_services_with_name ${SERVER_NAME}
|
||||
|
||||
# OpenIM message gateway service port
|
||||
OPENIM_RPC_PORTS=$(openim::util::list-to-string ${OPENIM_MESSAGE_GATEWAY_PORT} )
|
||||
# OpenIM WS port
|
||||
OPENIM_WS_PORTS=$(openim::util::list-to-string ${OPENIM_WS_PORT} )
|
||||
# Message Gateway Prometheus port of the service
|
||||
MSG_GATEWAY_PROM_PORTS=$(openim::util::list-to-string ${MSG_GATEWAY_PROM_PORT} )
|
||||
|
||||
openim::log::status "OpenIM RPC ports: ${OPENIM_RPC_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_RPC_PORTS[@]} -ne ${#OPENIM_WS_PORTS[@]} ]; then
|
||||
openim::log::error "ws_ports does not match push_rpc_ports or prome_ports in quantity!!!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for ((i = 0; i < ${#OPENIM_WS_PORTS[@]}; i++)); do
|
||||
openim::log::info "start push process, port: ${OPENIM_MSGGATEWAY_PORTS_ARRAY[$i]}, prometheus port: ${PUSH_MSGGATEWAY_PORTS_ARRAY[$i]}"
|
||||
|
||||
PROMETHEUS_PORT_OPTION=""
|
||||
if [[ -n "${MSG_GATEWAY_PROM_PORTS[$i]}" ]]; then
|
||||
PROMETHEUS_PORT_OPTION="--prometheus_port ${MSG_GATEWAY_PROM_PORTS[$i]}"
|
||||
fi
|
||||
|
||||
nohup ${OPENIM_MSGGATEWAY_BINARY} --port ${OPENIM_RPC_PORTS[$i]} --ws_port ${OPENIM_WS_PORTS[$i]} $PROMETHEUS_PORT_OPTION -c ${OPENIM_MSGGATEWAY_CONFIG} >> ${LOG_FILE} 2>&1 &
|
||||
done
|
||||
|
||||
openim::util::check_process_names ${SERVER_NAME}
|
||||
}
|
||||
|
||||
###################################### 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}
|
||||
EOF
|
||||
}
|
||||
|
||||
# install openim-msggateway
|
||||
function openim::msggateway::install()
|
||||
{
|
||||
pushd ${OPENIM_ROOT}
|
||||
|
||||
# 1. Build openim-msggateway
|
||||
make build BINS=${SERVER_NAME}
|
||||
openim::common::sudo "cp ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/bin"
|
||||
|
||||
openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/bin/${SERVER_NAME}"
|
||||
|
||||
# 2. Generate and install the openim-msggateway configuration file (openim-msggateway.yaml)
|
||||
echo ${LINUX_PASSWORD} | sudo -S bash -c \
|
||||
"./scripts/genconfig.sh ${ENV_FILE} deployments/templates/${SERVER_NAME}.yaml > ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
|
||||
openim::log::status "${SERVER_NAME} config file: ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
|
||||
|
||||
# 3. Create and install the ${SERVER_NAME} systemd unit file
|
||||
echo ${LINUX_PASSWORD} | sudo -S bash -c \
|
||||
"./scripts/genconfig.sh ${ENV_FILE} deployments/templates/init/${SERVER_NAME}.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}/bin/${SERVER_NAME}"
|
||||
openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
|
||||
openim::common::sudo "rm -f /etc/systemd/system/${SERVER_NAME}.service"
|
||||
set -o errexit
|
||||
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 127.0.0.1 7070 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
|
||||
Executable
+155
@@ -0,0 +1,155 @@
|
||||
#!/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.
|
||||
set -o errexit
|
||||
set +o nounset
|
||||
set -o pipefail
|
||||
|
||||
ulimit -n 200000
|
||||
|
||||
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()
|
||||
{
|
||||
openim::log::info "Start OpenIM Msggateway, binary root: ${SERVER_NAME}"
|
||||
openim::log::status "Start OpenIM Msggateway, path: ${OPENIM_MSGTRANSFER_BINARY}"
|
||||
|
||||
openim::util::stop_services_with_name ${SERVER_NAME}
|
||||
|
||||
# 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_exit "OPENIM_MSGGATEWAY_NUM must be greater than 0"
|
||||
fi
|
||||
|
||||
if [ ${OPENIM_MSGGATEWAY_NUM} -ne $((${#MSG_TRANSFER_PROM_PORTS[@]} - 1)) ]; then
|
||||
openim::log::error_exit "OPENIM_MSGGATEWAY_NUM must be equal to the number of MSG_TRANSFER_PROM_PORTS"
|
||||
fi
|
||||
|
||||
for (( i=1; i<=$OPENIM_MSGGATEWAY_NUM; i++ )) do
|
||||
openim::log::info "prometheus port: ${MSG_TRANSFER_PROM_PORTS[$i]}"
|
||||
PROMETHEUS_PORT_OPTION=""
|
||||
if [[ -n "${OPENIM_PROMETHEUS_PORTS[$i]}" ]]; then
|
||||
PROMETHEUS_PORT_OPTION="--prometheus_port ${OPENIM_PROMETHEUS_PORTS[$i]}"
|
||||
fi
|
||||
nohup ${OPENIM_MSGTRANSFER_BINARY} ${PROMETHEUS_PORT_OPTION} -c ${OPENIM_MSGTRANSFER_CONFIG} >> ${LOG_FILE} 2>&1 &
|
||||
done
|
||||
|
||||
openim::util::check_process_names "${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME}"
|
||||
}
|
||||
|
||||
function openim::msgtransfer::check()
|
||||
{
|
||||
PIDS=$(pgrep -f "${OPENIM_OUTPUT_HOSTBIN}/openim-msgtransfer")
|
||||
|
||||
NUM_PROCESSES=$(echo "$PIDS" | wc -l)
|
||||
# NUM_PROCESSES=$(($NUM_PROCESSES - 1))
|
||||
|
||||
if [ "$NUM_PROCESSES" -eq "$OPENIM_MSGGATEWAY_NUM" ]; then
|
||||
openim::log::info "Found $OPENIM_MSGGATEWAY_NUM processes named $OPENIM_OUTPUT_HOSTBIN"
|
||||
for PID in $PIDS; do
|
||||
ps -p $PID -o pid,cmd
|
||||
done
|
||||
else
|
||||
openim::log::error_exit "Expected $OPENIM_MSGGATEWAY_NUM openim msgtransfer processes, but found $NUM_PROCESSES msgtransfer processes."
|
||||
fi
|
||||
}
|
||||
|
||||
###################################### 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 ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/bin"
|
||||
|
||||
openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/bin/${SERVER_NAME}"
|
||||
|
||||
# 2. Generate and install the openim-msgtransfer configuration file (openim-msgtransfer.yaml)
|
||||
echo ${LINUX_PASSWORD} | sudo -S bash -c \
|
||||
"./scripts/genconfig.sh ${ENV_FILE} deployments/templates/${SERVER_NAME}.yaml > ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
|
||||
openim::log::status "${SERVER_NAME} config file: ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
|
||||
|
||||
# 3. Create and install the ${SERVER_NAME} systemd unit file
|
||||
echo ${LINUX_PASSWORD} | sudo -S bash -c \
|
||||
"./scripts/genconfig.sh ${ENV_FILE} deployments/templates/init/${SERVER_NAME}.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}/bin/${SERVER_NAME}"
|
||||
openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
|
||||
openim::common::sudo "rm -f /etc/systemd/system/${SERVER_NAME}.service"
|
||||
set -o errexit
|
||||
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.
|
||||
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 127.0.0.1 7070 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::msgtransfer:: ]];then
|
||||
eval $*
|
||||
fi
|
||||
Executable
+153
@@ -0,0 +1,153 @@
|
||||
#!/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.
|
||||
#
|
||||
set -o errexit
|
||||
set +o nounset
|
||||
set -o pipefail
|
||||
|
||||
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()
|
||||
{
|
||||
openim::log::status "Start OpenIM Push, binary root: ${SERVER_NAME}"
|
||||
openim::log::info "Start OpenIM Push, path: ${OPENIM_PUSH_BINARY}"
|
||||
|
||||
openim::util::stop_services_with_name ${SERVER_NAME}
|
||||
|
||||
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_exit "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]}"
|
||||
nohup ${OPENIM_PUSH_BINARY} --port ${OPENIM_PUSH_PORTS_ARRAY[$i]} --prometheus_port ${PUSH_PROM_PORTS_ARRAY[$i]} >> ${LOG_FILE} 2>&1 &
|
||||
done
|
||||
|
||||
openim::util::check_process_names ${SERVER_NAME}
|
||||
}
|
||||
|
||||
###################################### 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}
|
||||
EOF
|
||||
}
|
||||
|
||||
# install openim-push
|
||||
function openim::push::install()
|
||||
{
|
||||
pushd ${OPENIM_ROOT}
|
||||
|
||||
# 1. Build openim-push
|
||||
make build BINS=${SERVER_NAME}
|
||||
openim::common::sudo "cp ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/bin"
|
||||
|
||||
openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/bin/${SERVER_NAME}"
|
||||
|
||||
# 2. Generate and install the openim-push configuration file (openim-push.yaml)
|
||||
echo ${LINUX_PASSWORD} | sudo -S bash -c \
|
||||
"./scripts/genconfig.sh ${ENV_FILE} deployments/templates/${SERVER_NAME}.yaml > ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
|
||||
openim::log::status "${SERVER_NAME} config file: ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
|
||||
|
||||
# 3. Create and install the ${SERVER_NAME} systemd unit file
|
||||
echo ${LINUX_PASSWORD} | sudo -S bash -c \
|
||||
"./scripts/genconfig.sh ${ENV_FILE} deployments/templates/init/${SERVER_NAME}.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}/bin/${SERVER_NAME}"
|
||||
openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
|
||||
openim::common::sudo "rm -f /etc/systemd/system/${SERVER_NAME}.service"
|
||||
set -o errexit
|
||||
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 127.0.0.1 7071 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
|
||||
Executable
+181
@@ -0,0 +1,181 @@
|
||||
#!/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.
|
||||
#
|
||||
|
||||
|
||||
set -o errexit
|
||||
set +o nounset
|
||||
set -o pipefail
|
||||
|
||||
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[@]##*/}")
|
||||
|
||||
# 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() {
|
||||
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::util::stop_services_with_name ${OPENIM_RPC_SERVICE_LISTARIES[$i]}
|
||||
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]}) )
|
||||
OPENIM_RPC_PROM_PORTS=( $(openim::util::list-to-string ${OPENIM_RPC_PROM_PORT_LISTARIES[$i]}) )
|
||||
|
||||
for ((j = 0; j < ${#OPENIM_RPC_SERVICE_PORTS[@]}; 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]}"
|
||||
openim::rpc::start_service "${OPENIM_RPC_SERVICE_LISTARIES[$i]}" "${OPENIM_RPC_SERVICE_PORTS[j]}" "${OPENIM_RPC_PROM_PORTS[j]}"
|
||||
sleep 0.5
|
||||
done
|
||||
done
|
||||
|
||||
openim::util::check_ports ${OPENIM_RPC_PORT_TARGETS[@]}
|
||||
# openim::util::check_ports ${OPENIM_RPC_PROM_PORT_TARGETS[@]}
|
||||
|
||||
}
|
||||
|
||||
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>&1 &
|
||||
}
|
||||
|
||||
###################################### Linux Systemd ######################################
|
||||
SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service"
|
||||
|
||||
function openim::rpc::install() {
|
||||
openim::log::info "Installing ${SERVER_NAME} ..."
|
||||
}
|
||||
|
||||
function openim::rpc::uninstall() {
|
||||
openim::log::info "Uninstalling ${SERVER_NAME} ..."
|
||||
|
||||
}
|
||||
|
||||
function openim::rpc::status() {
|
||||
openim::log::info "Checking ${SERVER_NAME} status ..."
|
||||
|
||||
openim::util::check_ports ${OPENIM_RPC_PORT_TARGETS[@]}
|
||||
# openim::util::check_ports ${OPENIM_RPC_PROM_PORT_TARGETS[@]}
|
||||
|
||||
openim::util::check_process_names ${SERVER_NAME}
|
||||
}
|
||||
|
||||
if [[ "$*" =~ openim::rpc:: ]];then
|
||||
eval $*
|
||||
fi
|
||||
Executable
+166
@@ -0,0 +1,166 @@
|
||||
#!/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
|
||||
#
|
||||
|
||||
set -o errexit
|
||||
set +o nounset
|
||||
set -o pipefail
|
||||
|
||||
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
|
||||
)
|
||||
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::info "Starting ${binary_name}..."
|
||||
${cmd}
|
||||
}
|
||||
|
||||
function openim::tools::start() {
|
||||
openim::log::info "Starting OpenIM Tools..."
|
||||
for tool in "${OPENIM_TOOLS_NAME_LISTARIES[@]}"; do
|
||||
openim::log::info "Starting ${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::info "Starting ${tool}..."
|
||||
openim::tools::start_service ${tool} ${OPNEIM_CONFIG}
|
||||
sleep 0.2
|
||||
done
|
||||
}
|
||||
|
||||
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::info "Starting ${tool}..."
|
||||
# openim::tools::start_service ${tool}
|
||||
sleep 0.2
|
||||
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
|
||||
Executable
+561
@@ -0,0 +1,561 @@
|
||||
#!/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.
|
||||
|
||||
# A set of helpers for tests
|
||||
|
||||
openim::test::clear_all() {
|
||||
if openim::test::if_supports_resource "rc" ; then
|
||||
# shellcheck disable=SC2154
|
||||
# Disabling because "kube_flags" is set in a parent script
|
||||
kubectl delete "${kube_flags[@]}" rc --all --grace-period=0 --force
|
||||
fi
|
||||
if openim::test::if_supports_resource "pods" ; then
|
||||
kubectl delete "${kube_flags[@]}" pods --all --grace-period=0 --force
|
||||
fi
|
||||
}
|
||||
|
||||
# Prints the calling file and line number $1 levels deep
|
||||
# Defaults to 2 levels so you can call this to find your own caller
|
||||
openim::test::get_caller() {
|
||||
local levels=${1:-2}
|
||||
local caller_file="${BASH_SOURCE[${levels}]}"
|
||||
local caller_line="${BASH_LINENO[${levels}-1]}"
|
||||
echo "$(basename "${caller_file}"):${caller_line}"
|
||||
}
|
||||
|
||||
# Force exact match of a returned result for a object query. Wrap this with || to support multiple
|
||||
# valid return types.
|
||||
# This runs `kubectl get` once and asserts that the result is as expected.
|
||||
# $1: Object on which get should be run
|
||||
# $2: The go-template to run on the result
|
||||
# $3: The expected output
|
||||
# $4: Additional args to be passed to kubectl
|
||||
openim::test::get_object_assert() {
|
||||
openim::test::object_assert 1 "$@"
|
||||
}
|
||||
|
||||
# Asserts that the output of a given get query is as expected.
|
||||
# Runs the query multiple times before failing it.
|
||||
# $1: Object on which get should be run
|
||||
# $2: The go-template to run on the result
|
||||
# $3: The expected output
|
||||
# $4: Additional args to be passed to kubectl
|
||||
openim::test::wait_object_assert() {
|
||||
openim::test::object_assert 10 "$@"
|
||||
}
|
||||
|
||||
# Asserts that the output of a given get query is as expected.
|
||||
# Can run the query multiple times before failing it.
|
||||
# $1: Number of times the query should be run before failing it.
|
||||
# $2: Object on which get should be run
|
||||
# $3: The go-template to run on the result
|
||||
# $4: The expected output
|
||||
# $5: Additional args to be passed to kubectl
|
||||
openim::test::object_assert() {
|
||||
local tries=$1
|
||||
local object=$2
|
||||
local request=$3
|
||||
local expected=$4
|
||||
local args=${5:-}
|
||||
|
||||
for j in $(seq 1 "${tries}"); do
|
||||
# shellcheck disable=SC2086
|
||||
# Disabling because to allow for expansion here
|
||||
res=$(kubectl get "${kube_flags[@]}" ${args} ${object} -o go-template="${request}")
|
||||
if [[ "${res}" =~ ^$expected$ ]]; then
|
||||
echo -n "${green}"
|
||||
echo "$(openim::test::get_caller 3): Successful get ${object} ${request}: ${res}"
|
||||
echo -n "${reset}"
|
||||
return 0
|
||||
fi
|
||||
echo "Waiting for Get ${object} ${request} ${args}: expected: ${expected}, got: ${res}"
|
||||
sleep $((j-1))
|
||||
done
|
||||
|
||||
echo "${bold}${red}"
|
||||
echo "$(openim::test::get_caller 3): FAIL!"
|
||||
echo "Get ${object} ${request}"
|
||||
echo " Expected: ${expected}"
|
||||
echo " Got: ${res}"
|
||||
echo "${reset}${red}"
|
||||
caller
|
||||
echo "${reset}"
|
||||
return 1
|
||||
}
|
||||
|
||||
openim::test::get_object_jsonpath_assert() {
|
||||
local object=$1
|
||||
local request=$2
|
||||
local expected=$3
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
# Disabling to allow for expansion here
|
||||
res=$(kubectl get "${kube_flags[@]}" ${object} -o jsonpath=${request})
|
||||
|
||||
if [[ "${res}" =~ ^$expected$ ]]; then
|
||||
echo -n "${green}"
|
||||
echo "$(openim::test::get_caller): Successful get ${object} ${request}: ${res}"
|
||||
echo -n "${reset}"
|
||||
return 0
|
||||
else
|
||||
echo "${bold}${red}"
|
||||
echo "$(openim::test::get_caller): FAIL!"
|
||||
echo "Get ${object} ${request}"
|
||||
echo " Expected: ${expected}"
|
||||
echo " Got: ${res}"
|
||||
echo "${reset}${red}"
|
||||
caller
|
||||
echo "${reset}"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
openim::test::describe_object_assert() {
|
||||
local resource=$1
|
||||
local object=$2
|
||||
local matches=( "${@:3}" )
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
# Disabling to allow for expansion here
|
||||
result=$(kubectl describe "${kube_flags[@]}" ${resource} ${object})
|
||||
|
||||
for match in "${matches[@]}"; do
|
||||
if grep -q "${match}" <<< "${result}"; then
|
||||
echo "matched ${match}"
|
||||
else
|
||||
echo "${bold}${red}"
|
||||
echo "$(openim::test::get_caller): FAIL!"
|
||||
echo "Describe ${resource} ${object}"
|
||||
echo " Expected Match: ${match}"
|
||||
echo " Not found in:"
|
||||
echo "${result}"
|
||||
echo "${reset}${red}"
|
||||
caller
|
||||
echo "${reset}"
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
|
||||
echo -n "${green}"
|
||||
echo "$(openim::test::get_caller): Successful describe ${resource} ${object}:"
|
||||
echo "${result}"
|
||||
echo -n "${reset}"
|
||||
return 0
|
||||
}
|
||||
|
||||
openim::test::describe_object_events_assert() {
|
||||
local resource=$1
|
||||
local object=$2
|
||||
local showevents=${3:-"true"}
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
# Disabling to allow for expansion here
|
||||
if [[ -z "${3:-}" ]]; then
|
||||
result=$(kubectl describe "${kube_flags[@]}" ${resource} ${object})
|
||||
else
|
||||
result=$(kubectl describe "${kube_flags[@]}" "--show-events=${showevents}" ${resource} ${object})
|
||||
fi
|
||||
|
||||
if grep -q "No events.\|Events:" <<< "${result}"; then
|
||||
local has_events="true"
|
||||
else
|
||||
local has_events="false"
|
||||
fi
|
||||
if [[ "${showevents}" == "${has_events}" ]]; then
|
||||
echo -n "${green}"
|
||||
echo "$(openim::test::get_caller): Successful describe"
|
||||
echo "${result}"
|
||||
echo "${reset}"
|
||||
return 0
|
||||
else
|
||||
echo "${bold}${red}"
|
||||
echo "$(openim::test::get_caller): FAIL"
|
||||
if [[ "${showevents}" == "false" ]]; then
|
||||
echo " Events information should not be described in:"
|
||||
else
|
||||
echo " Events information not found in:"
|
||||
fi
|
||||
echo "${result}"
|
||||
echo "${reset}${red}"
|
||||
caller
|
||||
echo "${reset}"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
openim::test::describe_resource_assert() {
|
||||
local resource=$1
|
||||
local matches=( "${@:2}" )
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
# Disabling to allow for expansion here
|
||||
result=$(kubectl describe "${kube_flags[@]}" ${resource})
|
||||
|
||||
for match in "${matches[@]}"; do
|
||||
if grep -q "${match}" <<< "${result}"; then
|
||||
echo "matched ${match}"
|
||||
else
|
||||
echo "${bold}${red}"
|
||||
echo "FAIL!"
|
||||
echo "Describe ${resource}"
|
||||
echo " Expected Match: ${match}"
|
||||
echo " Not found in:"
|
||||
echo "${result}"
|
||||
echo "${reset}${red}"
|
||||
caller
|
||||
echo "${reset}"
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
|
||||
echo -n "${green}"
|
||||
echo "Successful describe ${resource}:"
|
||||
echo "${result}"
|
||||
echo -n "${reset}"
|
||||
return 0
|
||||
}
|
||||
|
||||
openim::test::describe_resource_events_assert() {
|
||||
local resource=$1
|
||||
local showevents=${2:-"true"}
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
# Disabling to allow for expansion here
|
||||
result=$(kubectl describe "${kube_flags[@]}" "--show-events=${showevents}" ${resource})
|
||||
|
||||
if grep -q "No events.\|Events:" <<< "${result}"; then
|
||||
local has_events="true"
|
||||
else
|
||||
local has_events="false"
|
||||
fi
|
||||
if [[ "${showevents}" == "${has_events}" ]]; then
|
||||
echo -n "${green}"
|
||||
echo "Successful describe"
|
||||
echo "${result}"
|
||||
echo -n "${reset}"
|
||||
return 0
|
||||
else
|
||||
echo "${bold}${red}"
|
||||
echo "FAIL"
|
||||
if [[ "${showevents}" == "false" ]]; then
|
||||
echo " Events information should not be described in:"
|
||||
else
|
||||
echo " Events information not found in:"
|
||||
fi
|
||||
echo "${result}"
|
||||
caller
|
||||
echo "${reset}"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
openim::test::describe_resource_chunk_size_assert() {
|
||||
# $1: the target resource
|
||||
local resource=$1
|
||||
# $2: comma-separated list of additional resources that will be listed
|
||||
local additionalResources=${2:-}
|
||||
# Remaining args are flags to pass to kubectl
|
||||
local args=${3:-}
|
||||
|
||||
# Expect list requests for the target resource and the additional resources
|
||||
local expectLists
|
||||
IFS="," read -r -a expectLists <<< "${resource},${additionalResources}"
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
# Disabling to allow for expansion here
|
||||
defaultResult=$(kubectl describe ${resource} --show-events=true -v=6 ${args} "${kube_flags[@]}" 2>&1 >/dev/null)
|
||||
for r in "${expectLists[@]}"; do
|
||||
if grep -q "${r}?.*limit=500" <<< "${defaultResult}"; then
|
||||
echo "query for ${r} had limit param"
|
||||
else
|
||||
echo "${bold}${red}"
|
||||
echo "FAIL!"
|
||||
echo "Describe ${resource}"
|
||||
echo " Expected limit param on request for: ${r}"
|
||||
echo " Not found in:"
|
||||
echo "${defaultResult}"
|
||||
echo "${reset}${red}"
|
||||
caller
|
||||
echo "${reset}"
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
# Disabling to allow for expansion here
|
||||
# Try a non-default chunk size
|
||||
customResult=$(kubectl describe ${resource} --show-events=false --chunk-size=10 -v=6 ${args} "${kube_flags[@]}" 2>&1 >/dev/null)
|
||||
if grep -q "${resource}?limit=10" <<< "${customResult}"; then
|
||||
echo "query for ${resource} had user-specified limit param"
|
||||
else
|
||||
echo "${bold}${red}"
|
||||
echo "FAIL!"
|
||||
echo "Describe ${resource}"
|
||||
echo " Expected limit param on request for: ${r}"
|
||||
echo " Not found in:"
|
||||
echo "${customResult}"
|
||||
echo "${reset}${red}"
|
||||
caller
|
||||
echo "${reset}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo -n "${green}"
|
||||
echo "Successful describe ${resource} verbose logs:"
|
||||
echo "${defaultResult}"
|
||||
echo -n "${reset}"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# Compare sort-by resource name output (first column, skipping first line) with expected order specify in the last parameter
|
||||
openim::test::if_sort_by_has_correct_order() {
|
||||
local var
|
||||
var="$(echo "$1" | awk '{if(NR!=1) print $1}' | tr '\n' ':')"
|
||||
openim::test::if_has_string "${var}" "${@:$#}"
|
||||
}
|
||||
|
||||
openim::test::if_has_string() {
|
||||
local message=$1
|
||||
local match=$2
|
||||
|
||||
if grep -q "${match}" <<< "${message}"; then
|
||||
echo -n "${green}"
|
||||
echo "Successful"
|
||||
echo -n "${reset}"
|
||||
echo "message:${message}"
|
||||
echo "has:${match}"
|
||||
return 0
|
||||
else
|
||||
echo -n "${bold}${red}"
|
||||
echo "FAIL!"
|
||||
echo -n "${reset}"
|
||||
echo "message:${message}"
|
||||
echo "has not:${match}"
|
||||
caller
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
openim::test::if_has_not_string() {
|
||||
local message=$1
|
||||
local match=$2
|
||||
|
||||
if grep -q "${match}" <<< "${message}"; then
|
||||
echo -n "${bold}${red}"
|
||||
echo "FAIL!"
|
||||
echo -n "${reset}"
|
||||
echo "message:${message}"
|
||||
echo "has:${match}"
|
||||
caller
|
||||
return 1
|
||||
else
|
||||
echo -n "${green}"
|
||||
echo "Successful"
|
||||
echo -n "${reset}"
|
||||
echo "message:${message}"
|
||||
echo "has not:${match}"
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
openim::test::if_empty_string() {
|
||||
local match=$1
|
||||
if [ -n "${match}" ]; then
|
||||
echo -n "${bold}${red}"
|
||||
echo "FAIL!"
|
||||
echo "${match} is not empty"
|
||||
echo -n "${reset}"
|
||||
caller
|
||||
return 1
|
||||
else
|
||||
echo -n "${green}"
|
||||
echo "Successful"
|
||||
echo -n "${reset}"
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
# Returns true if the required resource is part of supported resources.
|
||||
# Expects env vars:
|
||||
# SUPPORTED_RESOURCES: Array of all resources supported by the apiserver. "*"
|
||||
# means it supports all resources. For ex: ("*") or ("rc" "*") both mean that
|
||||
# all resources are supported.
|
||||
# $1: Name of the resource to be tested.
|
||||
openim::test::if_supports_resource() {
|
||||
SUPPORTED_RESOURCES=${SUPPORTED_RESOURCES:-""}
|
||||
REQUIRED_RESOURCE=${1:-""}
|
||||
|
||||
for r in "${SUPPORTED_RESOURCES[@]}"; do
|
||||
if [[ "${r}" == "*" || "${r}" == "${REQUIRED_RESOURCE}" ]]; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
openim::test::version::object_to_file() {
|
||||
name=$1
|
||||
flags=${2:-""}
|
||||
file=$3
|
||||
# shellcheck disable=SC2086
|
||||
# Disabling because "flags" needs to allow for expansion here
|
||||
kubectl version ${flags} | grep "${name} Version:" | sed -e s/"${name} Version: "/""/g > "${file}"
|
||||
}
|
||||
|
||||
openim::test::version::json_object_to_file() {
|
||||
flags=$1
|
||||
file=$2
|
||||
# shellcheck disable=SC2086
|
||||
# Disabling because "flags" needs to allow for expansion here
|
||||
kubectl version ${flags} --output json | sed -e s/' '/''/g -e s/'\"'/''/g -e s/'}'/''/g -e s/'{'/''/g -e s/'clientVersion:'/'clientVersion:,'/ -e s/'serverVersion:'/'serverVersion:,'/ | tr , '\n' > "${file}"
|
||||
}
|
||||
|
||||
openim::test::version::json_client_server_object_to_file() {
|
||||
flags=$1
|
||||
name=$2
|
||||
file=$3
|
||||
# shellcheck disable=SC2086
|
||||
# Disabling because "flags" needs to allow for expansion here
|
||||
kubectl version ${flags} --output json | jq -r ".${name}" | sed -e s/'\"'/''/g -e s/'}'/''/g -e s/'{'/''/g -e /^$/d -e s/','/''/g -e s/':'/'='/g > "${file}"
|
||||
}
|
||||
|
||||
openim::test::version::yaml_object_to_file() {
|
||||
flags=$1
|
||||
file=$2
|
||||
# shellcheck disable=SC2086
|
||||
# Disabling because "flags" needs to allow for expansion here
|
||||
kubectl version ${flags} --output yaml | sed -e s/' '/''/g -e s/'\"'/''/g -e /^$/d > "${file}"
|
||||
}
|
||||
|
||||
openim::test::version::diff_assert() {
|
||||
local original=$1
|
||||
local comparator=${2:-"eq"}
|
||||
local latest=$3
|
||||
local diff_msg=${4:-""}
|
||||
local res=""
|
||||
|
||||
if [ ! -f "${original}" ]; then
|
||||
echo "${bold}${red}"
|
||||
echo "FAIL! ${diff_msg}"
|
||||
echo "the file '${original}' does not exit"
|
||||
echo "${reset}${red}"
|
||||
caller
|
||||
echo "${reset}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ ! -f "${latest}" ]; then
|
||||
echo "${bold}${red}"
|
||||
echo "FAIL! ${diff_msg}"
|
||||
echo "the file '${latest}' does not exit"
|
||||
echo "${reset}${red}"
|
||||
caller
|
||||
echo "${reset}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ "${comparator}" == "exact" ]; then
|
||||
# Skip sorting of file content for exact comparison.
|
||||
cp "${original}" "${original}.sorted"
|
||||
cp "${latest}" "${latest}.sorted"
|
||||
else
|
||||
sort "${original}" > "${original}.sorted"
|
||||
sort "${latest}" > "${latest}.sorted"
|
||||
fi
|
||||
|
||||
if [ "${comparator}" == "eq" ] || [ "${comparator}" == "exact" ]; then
|
||||
if [ "$(diff -iwB "${original}".sorted "${latest}".sorted)" == "" ] ; then
|
||||
echo -n "${green}"
|
||||
echo "Successful: ${diff_msg}"
|
||||
echo -n "${reset}"
|
||||
return 0
|
||||
else
|
||||
echo "${bold}${red}"
|
||||
echo "FAIL! ${diff_msg}"
|
||||
echo " Expected: "
|
||||
cat "${original}"
|
||||
echo " Got: "
|
||||
cat "${latest}"
|
||||
echo "${reset}${red}"
|
||||
caller
|
||||
echo "${reset}"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
if [ -n "$(diff -iwB "${original}".sorted "${latest}".sorted)" ] ; then
|
||||
echo -n "${green}"
|
||||
echo "Successful: ${diff_msg}"
|
||||
echo -n "${reset}"
|
||||
return 0
|
||||
else
|
||||
echo "${bold}${red}"
|
||||
echo "FAIL! ${diff_msg}"
|
||||
echo " Expected: "
|
||||
cat "${original}"
|
||||
echo " Got: "
|
||||
cat "${latest}"
|
||||
echo "${reset}${red}"
|
||||
caller
|
||||
echo "${reset}"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Force exact match of kubectl stdout, stderr, and return code.
|
||||
# $1: file with actual stdout
|
||||
# $2: file with actual stderr
|
||||
# $3: the actual return code
|
||||
# $4: file with expected stdout
|
||||
# $5: file with expected stderr
|
||||
# $6: expected return code
|
||||
# $7: additional message describing the invocation
|
||||
openim::test::results::diff() {
|
||||
local actualstdout=$1
|
||||
local actualstderr=$2
|
||||
local actualcode=$3
|
||||
local expectedstdout=$4
|
||||
local expectedstderr=$5
|
||||
local expectedcode=$6
|
||||
local message=$7
|
||||
local result=0
|
||||
|
||||
if ! openim::test::version::diff_assert "${expectedstdout}" "exact" "${actualstdout}" "stdout for ${message}"; then
|
||||
result=1
|
||||
fi
|
||||
if ! openim::test::version::diff_assert "${expectedstderr}" "exact" "${actualstderr}" "stderr for ${message}"; then
|
||||
result=1
|
||||
fi
|
||||
if [ "${actualcode}" -ne "${expectedcode}" ]; then
|
||||
echo "${bold}${red}"
|
||||
echo "$(openim::test::get_caller): FAIL!"
|
||||
echo "Return code for ${message}"
|
||||
echo " Expected: ${expectedcode}"
|
||||
echo " Got: ${actualcode}"
|
||||
echo "${reset}${red}"
|
||||
caller
|
||||
echo "${reset}"
|
||||
result=1
|
||||
fi
|
||||
|
||||
if [ "${result}" -eq 0 ]; then
|
||||
echo -n "${green}"
|
||||
echo "$(openim::test::get_caller): Successful: ${message}"
|
||||
echo -n "${reset}"
|
||||
fi
|
||||
|
||||
return "$result"
|
||||
}
|
||||
@@ -0,0 +1,300 @@
|
||||
" learn: https://github.com/cubxxw/awesome-cs-course/tree/master/linux
|
||||
" Read: https://github.com/cubxxw/awesome-cs-course/blob/master/linux/markdown/my_vim.md
|
||||
|
||||
"vim的配置关于鼠标滚动滑动"""
|
||||
if has("autocmd")
|
||||
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
|
||||
set mouse=a
|
||||
endif
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
"C,C++ 按F5编译运行
|
||||
map <F5> :call CompileRunGcc()<CR>
|
||||
func! CompileRunGcc()
|
||||
exec "w"
|
||||
if &filetype == 'c'
|
||||
exec "!g++ % -o %<"
|
||||
exec "! ./%<"
|
||||
elseif &filetype == 'cpp'
|
||||
exec "!g++ % -o %<"
|
||||
exec "! ./%<"
|
||||
elseif &filetype == 'java'
|
||||
exec "!javac %"
|
||||
exec "!java %<"
|
||||
elseif &filetype == 'sh'
|
||||
:!./%
|
||||
endif
|
||||
endfunc
|
||||
"配置命令"
|
||||
"C,C++的调试
|
||||
"''''''''''''''''""""""""""""""""""""""""""""""""""'''''''''''''''''''''
|
||||
map <F8> :call Rungdb()<CR>
|
||||
func! Rungdb()
|
||||
exec "w"
|
||||
exec "!g++ % -g -o %<"
|
||||
exec "!gdb ./%<"
|
||||
endfunc
|
||||
|
||||
""实用设置
|
||||
" 设置当文件被改动时自动载入
|
||||
set autoread
|
||||
" quickfix模式
|
||||
autocmd FileType c,cpp map <buffer> <leader><space> :w<cr>:make<cr>
|
||||
"代码补全
|
||||
set completeopt=preview,menu
|
||||
|
||||
" common configure
|
||||
"set noswapfile
|
||||
set mouse=a " 激活鼠标使用
|
||||
set wrap " 自动换行
|
||||
set sw=4 " 设置软宽度
|
||||
set gdefault " 行内替换
|
||||
set nu
|
||||
set showmatch " 高亮显示括号匹配
|
||||
set expandtab " 使用空格来替换 Tab
|
||||
set tabstop=4 " 设置 Tab 长度为 4 空格
|
||||
set shiftwidth=4 " 设置自动缩进长度为 4 空格
|
||||
set autoindent " 继承前一行的缩进方式,适用于多行注释"
|
||||
set autowrite " 自动保存
|
||||
set nocompatible " 关闭 vi 兼容模式
|
||||
set history=1000 " 设置历史记录步数
|
||||
set confirm " 在处理未保存或只读文件时,弹出确认
|
||||
|
||||
" 搜索逐字符高亮
|
||||
set hlsearch
|
||||
set incsearch
|
||||
|
||||
" 从不备份
|
||||
set nobackup
|
||||
set noswapfile
|
||||
|
||||
let g:indentLine_enabled=0
|
||||
|
||||
" golang configure ====> start
|
||||
let g:go_highlight_methods = 1
|
||||
let g:go_highlight_operators = 1
|
||||
let g:go_highlight_build_constraints = 1
|
||||
let g:go_fmt_autosave = 1
|
||||
let g:go_version_warning = 1
|
||||
let g:go_autodetect_gopath = 1
|
||||
let g:go_highlight_types = 1
|
||||
let g:go_highlight_fields = 1
|
||||
let g:go_highlight_functions = 1
|
||||
let g:go_highlight_function_calls = 1
|
||||
let g:go_highlight_extra_types = 1
|
||||
let g:go_highlight_generate_tags = 1
|
||||
let g:go_def_mode = 'gopls'
|
||||
let g:go_gopls_enabled = 1
|
||||
let g:go_guru_enabled = 1
|
||||
let g:go_fmt_experimental = 1
|
||||
let g:go_def_mapping_enabled = 1
|
||||
let g:go_build_tags = '-v'
|
||||
let g:go_fmt_command = "goimports"
|
||||
let g:go_list_type = "quickfix"
|
||||
let g:go_def_mapping_enable = 1
|
||||
|
||||
map <2-LeftMouse> :GoDef <CR>
|
||||
map <RightMouse> :GoDefPop <CR>
|
||||
map <C-N> :GoCallers <CR>
|
||||
map <C-M> :GoCallees <CR>
|
||||
map <ScrollWheelUp> <C-Y>
|
||||
map <ScrollWheelDown> <C-E>
|
||||
unmap <CR>
|
||||
map <CR> :GoDef <CR>
|
||||
map <C-I> :GoDefPop <CR>
|
||||
map <S-K> :GoDoc<cr>
|
||||
map <S-M> :GoInfo<cr>
|
||||
map <S-T> :GoDefType<cr>
|
||||
map <S-L> :GoAddTag<cr>
|
||||
map <S-P> :GoImplements<cr>
|
||||
map <S-R> :GoRename<cr>
|
||||
map <S-F> :GoFillStruct<cr>
|
||||
map <S-C> :GoCallers<cr>
|
||||
map <S-H> :GoSameIdsToggle<cr>
|
||||
|
||||
augroup go
|
||||
autocmd!
|
||||
|
||||
" Show by default 4 spaces for a tab
|
||||
autocmd BufNewFile,BufRead *.go setlocal noexpandtab tabstop=4 shiftwidth=4
|
||||
|
||||
" :GoDef but opens in a vertical split
|
||||
autocmd FileType go nmap <Leader>v <Plug>(go-def-vertical)
|
||||
" :GoDef but opens in a horizontal split
|
||||
autocmd FileType go nmap <Leader>s <Plug>(go-def-split)
|
||||
|
||||
" :GoAlternate commands :A, :AV, :AS and :AT
|
||||
autocmd Filetype go command! -bang A call go#alternate#Switch(<bang>0, 'edit')
|
||||
autocmd Filetype go command! -bang AV call go#alternate#Switch(<bang>0, 'vsplit')
|
||||
autocmd Filetype go command! -bang AS call go#alternate#Switch(<bang>0, 'split')
|
||||
autocmd Filetype go command! -bang AT call go#alternate#Switch(<bang>0, 'tabe')
|
||||
augroup END
|
||||
|
||||
" build_go_files is a custom function that builds or compiles the test file.
|
||||
" It calls :GoBuild if its a Go file, or :GoTestCompile if it's a test file
|
||||
function! s:build_go_files()
|
||||
let l:file = expand('%')
|
||||
if l:file =~# '^\f\+_test\.go$'
|
||||
call go#test#Test(0, 1)
|
||||
elseif l:file =~# '^\f\+\.go$'
|
||||
call go#cmd#Build(0)
|
||||
endif
|
||||
endfunction
|
||||
" golang configure ====> end
|
||||
|
||||
:inoremap ( ()<ESC>i
|
||||
:inoremap ) <c-r>=ClosePair(')')<CR>
|
||||
:inoremap { {<CR>}<ESC>O
|
||||
:inoremap } <c-r>=ClosePair('}')<CR>
|
||||
:inoremap [ []<ESC>i
|
||||
:inoremap ] <c-r>=ClosePair(']')<CR>
|
||||
:inoremap " ""<ESC>i
|
||||
:inoremap ' ''<ESC>i
|
||||
function! ClosePair(char)
|
||||
if getline('.')[col('.') - 1] == a:char
|
||||
return "\<Right>"
|
||||
else
|
||||
return a:char
|
||||
endif
|
||||
endfunction
|
||||
filetype plugin indent on
|
||||
"打开文件类型检测, 加了这句才可以用智能补全
|
||||
|
||||
set completeopt=longest,menu
|
||||
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""
|
||||
noremap <F6> :set nu
|
||||
noremap <F4> :!python3 a
|
||||
noremap <F7> :set ai
|
||||
noremap <F8> :syntax on
|
||||
set cursorline " 突出显示当前行
|
||||
set magic " 设置魔术
|
||||
"" noremap <F5> :! g++ -o a
|
||||
nnoremap <C-J> <C-W><C-J>
|
||||
nnoremap <C-K> <C-W><C-K>
|
||||
nnoremap <C-L> <C-W><C-L>
|
||||
nnoremap <C-H> <C-W><C-H>
|
||||
nmap wj :resize -3<CR>
|
||||
nmap wk :resize +3<CR>
|
||||
nmap wh :vertical resize -3<CR>
|
||||
nmap wl :vertical resize +3<CR>
|
||||
set guifont=Droid\ Sans\ Mono\ Nerd\ Font\ Complete:h18 " 设置字体
|
||||
set guicursor=n-v-c:ver5 " 设置光标为竖线
|
||||
set number ""# 显示行号
|
||||
set autowrite "" # 自动保存
|
||||
set ruler ""# 显示打开状态栏标尺
|
||||
set cursorline "" # 突出显示当前行
|
||||
|
||||
set showmatch "" # 匹配光标所经过的括号等.
|
||||
set showcmd ""# 命令行显示输入的命令
|
||||
set showmode ""命令行显示vim当前模式
|
||||
set showtabline=0 " 隐藏Tab栏
|
||||
set laststatus=2 """"'vim 窗口底部显示永久状态栏,显示文件名,行号,列号等.
|
||||
let mapleader = "," " 定义<leader>键
|
||||
set nocompatible " 设置不兼容原始vi模式
|
||||
filetype on " 设置开启文件类型侦测
|
||||
filetype plugin on " 设置加载对应文件类型的插件
|
||||
set noeb " 关闭错误的提示
|
||||
syntax enable " 开启语法高亮功能
|
||||
syntax on " 自动语法高亮
|
||||
set cmdheight=2 " 设置命令行的高度
|
||||
set showcmd " select模式下显示选中的行数
|
||||
set ruler " 总是显示光标位置
|
||||
set laststatus=2 " 总是显示状态栏
|
||||
set number " 开启行号显示
|
||||
set cursorline " 高亮显示当前行
|
||||
set whichwrap+=<,>,h,l " 设置光标键跨行
|
||||
set ttimeoutlen=0 " 设置<ESC>键响应时间
|
||||
set virtualedit=block,onemore " 允许光标出现在最后一个字符的后面
|
||||
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
" 代码缩进和排版
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
set autoindent " 设置自动缩进
|
||||
set cindent " 设置使用C/C++语言的自动缩进方式
|
||||
set cinoptions=g0,:0,N-s,(0 " 设置C/C++语言的具体缩进方式
|
||||
set smartindent " 智能的选择对其方式
|
||||
filetype indent on " 自适应不同语言的智能缩进
|
||||
set expandtab " 将制表符扩展为空格
|
||||
set tabstop=4 " 设置编辑时制表符占用空格数
|
||||
set shiftwidth=4 " 设置格式化时制表符占用空格数
|
||||
set softtabstop=4 " 设置4个空格为制表符
|
||||
set smarttab " 在行和段开始处使用制表符
|
||||
set nowrap " 禁止折行
|
||||
set backspace=2 " 使用回车键正常处理indent,eol,start等
|
||||
set sidescroll=10 " 设置向右滚动字符数
|
||||
set nofoldenable " 禁用折叠代码
|
||||
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
" 代码补全
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
set wildmenu " vim自身命名行模式智能补全
|
||||
set completeopt-=preview " 补全时不显示窗口,只显示补全列表
|
||||
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
" 搜索设置
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
set hlsearch " 高亮显示搜索结果
|
||||
set incsearch " 开启实时搜索功能
|
||||
set ignorecase " 搜索时大小写不敏感
|
||||
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
" 缓存设置
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
set nobackup " 设置不备份
|
||||
set noswapfile " 禁止生成临时文件
|
||||
set autoread " 文件在vim之外修改过,自动重新读入
|
||||
set autowrite " 设置自动保存
|
||||
set confirm " 在处理未保存或只读文件的时候,弹出确认
|
||||
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
"调整窗
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
nmap wj :resize -3<CR>
|
||||
nmap wk :resize +3<CR>
|
||||
nmap wh :vertical resize -3<CR>
|
||||
nmap wl :vertical resize +3<CR>
|
||||
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
"编码"
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
set langmenu=zh_CN.UTF-8
|
||||
set helplang=cn
|
||||
set termencoding=utf-8
|
||||
set encoding=utf8
|
||||
set fileencodings=utf8,ucs-bom,gbk,cp936,gb2312,gb18030
|
||||
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
"代码补全“
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
inoremap ' ''<ESC>i
|
||||
inoremap " ""<ESC>i
|
||||
inoremap ( ()<ESC>i
|
||||
inoremap [ []<ESC>i
|
||||
inoremap { {<CR>}<ESC>O
|
||||
: set nu
|
||||
: set ai
|
||||
: syntax on
|
||||
: filetype on
|
||||
set tabstop=4
|
||||
set ignorecase
|
||||
noremap <C-h> <C -w>h
|
||||
noremap <C-j> <C -w>j
|
||||
noremap <C-k> <C -w>r
|
||||
noremap <C-l> <C -w>l
|
||||
" Specify a directory for plugins
|
||||
" - For Neovim: stdpath('data') . '/plugged'
|
||||
" - Avoid using standard Vim directory names like 'plugin'
|
||||
let g:coc_disable_startup_warning = 1
|
||||
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
"tmux"
|
||||
"复用终端、分屏"
|
||||
"let g:EasyMotion_startofline = 0 " keep cursor colum when JK motion
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
map <Leader><leader>h <Plug>(easymotion-linebackward)
|
||||
map <Leader><Leader>j <Plug>(easymotion-j)
|
||||
map <Leader><Leader>k <Plug>(easymotion-k)
|
||||
map <Leader><leader>l <Plug>(easymotion-lineforward)
|
||||
" 重复上一次操作, 类似repeat插件, 很强大
|
||||
map <Leader><leader>. <Plug>(easymotion-repeat)
|
||||
nmap s <Plug>(easymotion-s)
|
||||
@@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright © 2023 OpenIM. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -13,110 +15,62 @@
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
||||
source "${OPENIM_ROOT}/scripts/install/environment.sh"
|
||||
|
||||
openim::util::onCtrlC
|
||||
|
||||
# docker-compose.yaml file name
|
||||
docker_compose_file_name="docker-compose.yaml"
|
||||
|
||||
trap 'onCtrlC' INT
|
||||
function onCtrlC () {
|
||||
#Capture CTRL+C, terminate the background process of the program when the script is terminated in the form of ctrl+c
|
||||
kill -9 ${do_sth_pid} ${progress_pid}
|
||||
echo
|
||||
echo 'Ctrl+C is captured'
|
||||
exit 1
|
||||
# Load environment variables from .env file
|
||||
load_env() {
|
||||
source ${OPENIM_ROOT}/.env
|
||||
}
|
||||
|
||||
do_sth() {
|
||||
#Main program to run
|
||||
echo "++++++++++++++++++++++++"
|
||||
sleep 5
|
||||
echo "++++++++++++++++++++++++"
|
||||
|
||||
sleep 10
|
||||
}
|
||||
|
||||
#Import environment variables
|
||||
source .env
|
||||
|
||||
#Get the public IP address of the local machine
|
||||
internet_ip=$(curl ifconfig.me -s)
|
||||
echo -e "\033[1;34mCurrent public IP address: ${internet_ip}\033[0m\n"
|
||||
|
||||
#If MINIO_ENDPOINT is "http://127.0.0.1:10005", replace it with the current public IP address
|
||||
if [[ $MINIO_ENDPOINT == "http://127.0.0.1:10005" ]]; then
|
||||
sed -i "s/127.0.0.1/${internet_ip}/" .env
|
||||
fi
|
||||
|
||||
do_progress_bar() {
|
||||
local duration=${1}
|
||||
local max_progress=20
|
||||
local current_progress=0
|
||||
|
||||
while true; do
|
||||
((current_progress++))
|
||||
if [[ $current_progress -gt $max_progress ]]; then
|
||||
break
|
||||
fi
|
||||
sleep "$duration"
|
||||
echo "=====> Progress: [${current_progress}/${max_progress}]"
|
||||
done
|
||||
}
|
||||
|
||||
#Start Docker containers
|
||||
start_docker_containers() {
|
||||
if command -v docker-compose >/dev/null 2>&1; then
|
||||
echo -e "\033[1;34mFound docker-compose command, starting docker containers...\033[0m\n"
|
||||
docker-compose -f ${OPENIM_ROOT}/${docker_compose_file_name} up -d
|
||||
else
|
||||
if command -v docker >/dev/null 2>&1; then
|
||||
echo -e "\033[1;34mFound docker command, starting docker containers...\033[0m\n"
|
||||
docker compose -f ${OPENIM_ROOT}/${docker_compose_file_name} up -d
|
||||
else
|
||||
echo -e "\033[1;31mFailed to find docker-compose or docker command, please make sure they are installed and configured correctly.\033[0m"
|
||||
return 1
|
||||
fi
|
||||
# Replace local IP with public IP in .env
|
||||
replace_ip() {
|
||||
if [ "$API_URL" == "http://127.0.0.1:10002/object/" ]; then
|
||||
sed -i "s/127.0.0.1/${internet_ip}/" ${OPENIM_ROOT}/.env
|
||||
fi
|
||||
|
||||
if [ "$MINIO_ENDPOINT" == "http://127.0.0.1:10005" ]; then
|
||||
sed -i "s/127.0.0.1/${internet_ip}/" ${OPENIM_ROOT}/.env
|
||||
fi
|
||||
|
||||
openim::log::info "Your minio endpoint is ${MINIO_ENDPOINT}"
|
||||
}
|
||||
|
||||
#Execute scripts
|
||||
setup_script() {
|
||||
chmod +x ${SCRIPTS_ROOT}/*.sh
|
||||
echo -e "\033[1;34m============>Executing init_pwd.sh script...\033[0m\n"
|
||||
${SCRIPTS_ROOT}/init_pwd.sh
|
||||
echo -e "\033[1;34m============>Executing env_check.sh script...\033[0m\n"
|
||||
${SCRIPTS_ROOT}/env_check.sh
|
||||
# Execute necessary scripts
|
||||
execute_scripts() {
|
||||
chmod +x ${OPENIM_ROOT}/scripts/*.sh
|
||||
openim::log::info "Executing init_pwd.sh"
|
||||
${OPENIM_ROOT}/scripts/init_pwd.sh
|
||||
|
||||
openim::log::info "Executing env_check.sh"
|
||||
${OPENIM_ROOT}/scripts/env_check.sh
|
||||
}
|
||||
|
||||
setup_script &
|
||||
# Start docker compose
|
||||
start_docker_compose() {
|
||||
openim::log::info "Checking if docker-compose command is available"
|
||||
if command -v docker-compose &> /dev/null; then
|
||||
docker-compose up -d
|
||||
else
|
||||
docker compose up -d
|
||||
fi
|
||||
|
||||
#Start Docker containers (timeout 10 seconds)
|
||||
start_docker_containers
|
||||
${OPENIM_ROOT}/scripts/docker-check-service.sh
|
||||
}
|
||||
|
||||
docker_pid=$!
|
||||
timeout 10s tail --pid=${docker_pid} -f /dev/null
|
||||
docker_exit_code=$?
|
||||
main() {
|
||||
load_env
|
||||
openim::util::get_server_ip
|
||||
replace_ip
|
||||
execute_scripts
|
||||
start_docker_compose
|
||||
openim::log::success "Script executed successfully"
|
||||
}
|
||||
|
||||
if [ $docker_exit_code -eq 0 ]; then
|
||||
echo -e "\033[1;32m============>Docker containers started successfully!\033[0m\n"
|
||||
else
|
||||
echo -e "\033[1;31m============>Failed to start Docker containers, please check the environment configuration and dependencies.\033[0m\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "\033[1;34m============>Executing docker_check_service.sh script...\033[0m\n"
|
||||
|
||||
#View running Docker containers
|
||||
echo -e "\033[1;34m============>Viewing running Docker containers...\033[0m\n"
|
||||
echo ""
|
||||
docker ps
|
||||
|
||||
#Replace the progress bar section with the pv command
|
||||
echo -e "\033[1;34m============>Starting progress bar...\033[0m\n"
|
||||
do_progress_bar 0.5 | pv -l -s 20 > /dev/null
|
||||
echo -e "\033[1;34m============>Progress bar completed.\033[0m\n"
|
||||
|
||||
#Execute the main program
|
||||
do_sth
|
||||
# Run the main function
|
||||
main
|
||||
@@ -1,85 +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.
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
|
||||
source $SCRIPTS_ROOT/style_info.sh
|
||||
|
||||
# docker-compose.yaml file name
|
||||
docker_compose_file_name="docker-compose.yaml"
|
||||
|
||||
trap 'onCtrlC' INT
|
||||
function onCtrlC () {
|
||||
#Capture CTRL+C, terminate the background process of the program when the script is terminated in the form of ctrl+c
|
||||
kill -9 ${do_sth_pid} ${progress_pid}
|
||||
echo
|
||||
echo 'Ctrl+C is captured'
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Load environment variables from .env file
|
||||
source ${OPENIM_ROOT}/.env
|
||||
|
||||
# Get the public internet IP address
|
||||
internet_ip=$(curl ifconfig.me -s)
|
||||
echo -e "${PURPLE_PREFIX}=========> Your public internet IP address is ${internet_ip} ${COLOR_SUFFIX} \n"
|
||||
|
||||
# Replace local IP address with the public IP address in .env file
|
||||
if [ $API_URL == "http://127.0.0.1:10002/object/" ]; then
|
||||
sed -i "s/127.0.0.1/${internet_ip}/" ${OPENIM_ROOT}/.env
|
||||
fi
|
||||
|
||||
if [ $MINIO_ENDPOINT == "http://127.0.0.1:10005" ]; then
|
||||
sed -i "s/127.0.0.1/${internet_ip}/" ${OPENIM_ROOT}/.env
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
echo -e "${PURPLE_PREFIX}=========> Your minio endpoint is ${MINIO_ENDPOINT} ${COLOR_SUFFIX} \n"
|
||||
|
||||
# Change directory to scripts folder
|
||||
|
||||
chmod +x ${SCRIPTS_ROOT}/*.sh
|
||||
|
||||
# Execute necessary scripts
|
||||
echo -e "${PURPLE_PREFIX}=========> init_pwd.sh ${COLOR_SUFFIX} \n"
|
||||
|
||||
${SCRIPTS_ROOT}/init_pwd.sh
|
||||
|
||||
echo -e "${PURPLE_PREFIX}=========> env_check.sh ${COLOR_SUFFIX} \n"
|
||||
|
||||
${SCRIPTS_ROOT}/env_check.sh
|
||||
|
||||
# Go back to the previous directory
|
||||
cd ${OPENIM_ROOT}
|
||||
|
||||
# Check if docker-compose command is available
|
||||
if command -v docker-compose &> /dev/null
|
||||
then
|
||||
docker-compose up -d
|
||||
else
|
||||
docker compose up -d
|
||||
fi
|
||||
|
||||
${SCRIPTS_ROOT}/docker_check_service.sh
|
||||
Executable
+178
@@ -0,0 +1,178 @@
|
||||
# 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.
|
||||
|
||||
# A set of helpers for starting/running chat for tests
|
||||
|
||||
CHAT_VERSION=${CHAT_VERSION:-1.1.0}
|
||||
CHAT_HOST=${CHAT_HOST:-127.0.0.1}
|
||||
CHAT_PORT=${CHAT_PORT:-2379}
|
||||
# This is intentionally not called CHAT_LOG_LEVEL:
|
||||
# chat checks that and compains when it is set in addition
|
||||
# to the command line argument, even when both have the same value.
|
||||
CHAT_LOGLEVEL=${CHAT_LOGLEVEL:-warn}
|
||||
export OPENIM_INTEGRATION_CHAT_URL="http://${CHAT_HOST}:${CHAT_PORT}"
|
||||
|
||||
openim::chat::validate() {
|
||||
# validate if in path
|
||||
command -v chat >/dev/null || {
|
||||
openim::log::usage "chat must be in your PATH"
|
||||
openim::log::info "You can use 'hack/install-chat.sh' to install a copy in third_party/."
|
||||
exit 1
|
||||
}
|
||||
|
||||
# validate chat port is free
|
||||
local port_check_command
|
||||
if command -v ss &> /dev/null && ss -Version | grep 'iproute2' &> /dev/null; then
|
||||
port_check_command="ss"
|
||||
elif command -v netstat &>/dev/null; then
|
||||
port_check_command="netstat"
|
||||
else
|
||||
openim::log::usage "unable to identify if chat is bound to port ${CHAT_PORT}. unable to find ss or netstat utilities."
|
||||
exit 1
|
||||
fi
|
||||
if ${port_check_command} -nat | grep "LISTEN" | grep "[\.:]${CHAT_PORT:?}" >/dev/null 2>&1; then
|
||||
openim::log::usage "unable to start chat as port ${CHAT_PORT} is in use. please stop the process listening on this port and retry."
|
||||
openim::log::usage "$(${port_check_command} -nat | grep "LISTEN" | grep "[\.:]${CHAT_PORT:?}")"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# need set the env of "CHAT_UNSUPPORTED_ARCH" on unstable arch.
|
||||
arch=$(uname -m)
|
||||
if [[ $arch =~ arm* ]]; then
|
||||
export CHAT_UNSUPPORTED_ARCH=arm
|
||||
fi
|
||||
# validate installed version is at least equal to minimum
|
||||
version=$(chat --version | grep Version | head -n 1 | cut -d " " -f 3)
|
||||
if [[ $(openim::chat::version "${CHAT_VERSION}") -gt $(openim::chat::version "${version}") ]]; then
|
||||
export PATH=${OPENIM_ROOT}/third_party/chat:${PATH}
|
||||
hash chat
|
||||
echo "${PATH}"
|
||||
version=$(chat --version | grep Version | head -n 1 | cut -d " " -f 3)
|
||||
if [[ $(openim::chat::version "${CHAT_VERSION}") -gt $(openim::chat::version "${version}") ]]; then
|
||||
openim::log::usage "chat version ${CHAT_VERSION} or greater required."
|
||||
openim::log::info "You can use 'hack/install-chat.sh' to install a copy in third_party/."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
openim::chat::version() {
|
||||
printf '%s\n' "${@}" | awk -F . '{ printf("%d%03d%03d\n", $1, $2, $3) }'
|
||||
}
|
||||
|
||||
openim::chat::start() {
|
||||
# validate before running
|
||||
openim::chat::validate
|
||||
|
||||
# Start chat
|
||||
CHAT_DIR=${CHAT_DIR:-$(mktemp -d 2>/dev/null || mktemp -d -t test-chat.XXXXXX)}
|
||||
if [[ -d "${ARTIFACTS:-}" ]]; then
|
||||
CHAT_LOGFILE="${ARTIFACTS}/chat.$(uname -n).$(id -un).log.DEBUG.$(date +%Y%m%d-%H%M%S).$$"
|
||||
else
|
||||
CHAT_LOGFILE=${CHAT_LOGFILE:-"/dev/null"}
|
||||
fi
|
||||
openim::log::info "chat --advertise-client-urls ${OPENIM_INTEGRATION_CHAT_URL} --data-dir ${CHAT_DIR} --listen-client-urls http://${CHAT_HOST}:${CHAT_PORT} --log-level=${CHAT_LOGLEVEL} 2> \"${CHAT_LOGFILE}\" >/dev/null"
|
||||
chat --advertise-client-urls "${OPENIM_INTEGRATION_CHAT_URL}" --data-dir "${CHAT_DIR}" --listen-client-urls "${OPENIM_INTEGRATION_CHAT_URL}" --log-level="${CHAT_LOGLEVEL}" 2> "${CHAT_LOGFILE}" >/dev/null &
|
||||
CHAT_PID=$!
|
||||
|
||||
echo "Waiting for chat to come up."
|
||||
openim::util::wait_for_url "${OPENIM_INTEGRATION_CHAT_URL}/health" "chat: " 0.25 80
|
||||
curl -fs -X POST "${OPENIM_INTEGRATION_CHAT_URL}/v3/kv/put" -d '{"key": "X3Rlc3Q=", "value": ""}'
|
||||
}
|
||||
|
||||
openim::chat::start_scraping() {
|
||||
if [[ -d "${ARTIFACTS:-}" ]]; then
|
||||
CHAT_SCRAPE_DIR="${ARTIFACTS}/chat-scrapes"
|
||||
else
|
||||
CHAT_SCRAPE_DIR=$(mktemp -d -t test.XXXXXX)/chat-scrapes
|
||||
fi
|
||||
openim::log::info "Periodically scraping chat to ${CHAT_SCRAPE_DIR} ."
|
||||
mkdir -p "${CHAT_SCRAPE_DIR}"
|
||||
(
|
||||
while sleep 30; do
|
||||
openim::chat::scrape
|
||||
done
|
||||
) &
|
||||
CHAT_SCRAPE_PID=$!
|
||||
}
|
||||
|
||||
openim::chat::scrape() {
|
||||
curl -s -S "${OPENIM_INTEGRATION_CHAT_URL}/metrics" > "${CHAT_SCRAPE_DIR}/next" && mv "${CHAT_SCRAPE_DIR}/next" "${CHAT_SCRAPE_DIR}/$(date +%s).scrape"
|
||||
}
|
||||
|
||||
openim::chat::stop() {
|
||||
if [[ -n "${CHAT_SCRAPE_PID:-}" ]] && [[ -n "${CHAT_SCRAPE_DIR:-}" ]] ; then
|
||||
kill "${CHAT_SCRAPE_PID}" &>/dev/null || :
|
||||
wait "${CHAT_SCRAPE_PID}" &>/dev/null || :
|
||||
openim::chat::scrape || :
|
||||
(
|
||||
# shellcheck disable=SC2015
|
||||
cd "${CHAT_SCRAPE_DIR}"/.. && \
|
||||
tar czf chat-scrapes.tgz chat-scrapes && \
|
||||
rm -rf chat-scrapes || :
|
||||
)
|
||||
fi
|
||||
if [[ -n "${CHAT_PID-}" ]]; then
|
||||
kill "${CHAT_PID}" &>/dev/null || :
|
||||
wait "${CHAT_PID}" &>/dev/null || :
|
||||
fi
|
||||
}
|
||||
|
||||
openim::chat::clean_chat_dir() {
|
||||
if [[ -n "${CHAT_DIR-}" ]]; then
|
||||
rm -rf "${CHAT_DIR}"
|
||||
fi
|
||||
}
|
||||
|
||||
openim::chat::cleanup() {
|
||||
openim::chat::stop
|
||||
openim::chat::clean_chat_dir
|
||||
}
|
||||
|
||||
openim::chat::install() {
|
||||
(
|
||||
local os
|
||||
local arch
|
||||
|
||||
os=$(openim::util::host_os)
|
||||
arch=$(openim::util::host_arch)
|
||||
|
||||
cd "${OPENIM_ROOT}/third_party" || return 1
|
||||
if [[ $(readlink chat) == chat-v${CHAT_VERSION}-${os}-* ]]; then
|
||||
openim::log::info "chat v${CHAT_VERSION} already installed. To use:"
|
||||
openim::log::info "export PATH=\"$(pwd)/chat:\${PATH}\""
|
||||
return #already installed
|
||||
fi
|
||||
|
||||
if [[ ${os} == "darwin" ]]; then
|
||||
download_file="chat-v${CHAT_VERSION}-${os}-${arch}.zip"
|
||||
url="https://github.com/chat-io/chat/releases/download/v${CHAT_VERSION}/${download_file}"
|
||||
openim::util::download_file "${url}" "${download_file}"
|
||||
unzip -o "${download_file}"
|
||||
ln -fns "chat-v${CHAT_VERSION}-${os}-${arch}" chat
|
||||
rm "${download_file}"
|
||||
elif [[ ${os} == "linux" ]]; then
|
||||
url="https://github.com/coreos/chat/releases/download/v${CHAT_VERSION}/chat-v${CHAT_VERSION}-${os}-${arch}.tar.gz"
|
||||
download_file="chat-v${CHAT_VERSION}-${os}-${arch}.tar.gz"
|
||||
openim::util::download_file "${url}" "${download_file}"
|
||||
tar xzf "${download_file}"
|
||||
ln -fns "chat-v${CHAT_VERSION}-${os}-${arch}" chat
|
||||
rm "${download_file}"
|
||||
else
|
||||
openim::log::info "${os} is NOT supported."
|
||||
fi
|
||||
openim::log::info "chat v${CHAT_VERSION} installed. To use:"
|
||||
openim::log::info "export PATH=\"$(pwd)/chat:\${PATH}\""
|
||||
)
|
||||
}
|
||||
+92
-28
@@ -14,24 +14,47 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# this script is used to install the dependencies of the project
|
||||
#
|
||||
# Usage: `scripts/color.sh`.
|
||||
################################################################################
|
||||
|
||||
# shellcheck disable=SC2034
|
||||
if [[ ! -v COLOR_OPEN ]]; then
|
||||
COLOR_OPEN=1
|
||||
fi
|
||||
|
||||
# Function for colored echo
|
||||
openim::color::echo() {
|
||||
COLOR=$1
|
||||
[ $COLOR_OPEN -eq 1 ] && echo -e "${COLOR} $(date '+%Y-%m-%d %H:%M:%S') $@ ${COLOR_SUFFIX}"
|
||||
shift
|
||||
}
|
||||
|
||||
# Define color variables
|
||||
# Feature
|
||||
# --- Feature ---
|
||||
COLOR_NORMAL='\033[0m';COLOR_BOLD='\033[1m';COLOR_DIM='\033[2m';COLOR_UNDER='\033[4m';
|
||||
COLOR_ITALIC='\033[3m';COLOR_NOITALIC='\033[23m';COLOR_BLINK='\033[5m';
|
||||
COLOR_REVERSE='\033[7m';COLOR_CONCEAL='\033[8m';COLOR_NOBOLD='\033[22m';
|
||||
COLOR_NOUNDER='\033[24m';COLOR_NOBLINK='\033[25m';
|
||||
|
||||
# Front color
|
||||
COLOR_BLACK='\033[30m';COLOR_RED='\033[31m';COLOR_GREEN='\033[32m';COLOR_YELLOW='\033[33m';
|
||||
COLOR_BLUE='\033[34m';COLOR_MAGENTA='\033[35m';COLOR_CYAN='\033[36m';COLOR_WHITE='\033[37m';
|
||||
# --- Front color ---
|
||||
COLOR_BLACK='\033[30m';
|
||||
COLOR_RED='\033[31m';
|
||||
COLOR_GREEN='\033[32m';
|
||||
COLOR_YELLOW='\033[33m';
|
||||
COLOR_BLUE='\033[34m';
|
||||
COLOR_MAGENTA='\033[35m';
|
||||
COLOR_CYAN='\033[36m';
|
||||
COLOR_WHITE='\033[37m';
|
||||
|
||||
# background color
|
||||
# --- background color ---
|
||||
COLOR_BBLACK='\033[40m';COLOR_BRED='\033[41m';
|
||||
COLOR_BGREEN='\033[42m';COLOR_BYELLOW='\033[43m';
|
||||
COLOR_BBLUE='\033[44m';COLOR_BMAGENTA='\033[45m';
|
||||
COLOR_BCYAN='\033[46m';COLOR_BWHITE='\033[47m';
|
||||
|
||||
# --- Color definitions ---
|
||||
# Color definitions
|
||||
COLOR_SUFFIX="\033[0m" # End all colors and special effects
|
||||
BLACK_PREFIX="\033[30m" # Black prefix
|
||||
@@ -44,31 +67,18 @@ WHITE_PREFIX="\033[37m" # White prefix
|
||||
BOLD_PREFIX="\033[1m" # Bold prefix
|
||||
UNDERLINE_PREFIX="\033[4m" # Underline prefix
|
||||
ITALIC_PREFIX="\033[3m" # Italic prefix
|
||||
BRIGHT_GREEN_PREFIX='\033[1;32m' # Bright green prefix
|
||||
CYAN_PREFIX="\033[0;36m" # Cyan prefix
|
||||
|
||||
# --- helper functions for logs ---
|
||||
info()
|
||||
{
|
||||
echo -e "[${GREEN_PREFIX}INFO${COLOR_SUFFIX}] " "$@"
|
||||
}
|
||||
warn()
|
||||
{
|
||||
echo -e "[${YELLOW_PREFIX}WARN${COLOR_SUFFIX}] " "$@" >&2
|
||||
}
|
||||
fatal()
|
||||
{
|
||||
echo -e "[${RED_PREFIX}ERROR${COLOR_SUFFIX}] " "$@" >&2
|
||||
exit 1
|
||||
}
|
||||
debug()
|
||||
{
|
||||
echo -e "[${BLUE_PREFIX}DEBUG${COLOR_SUFFIX}]===> " "$@"
|
||||
}
|
||||
success()
|
||||
{
|
||||
echo -e "${BRIGHT_GREEN_PREFIX}===> [SUCCESS] <===${COLOR_SUFFIX}\n=> " "$@"
|
||||
}
|
||||
# --- make demo (run demo) ---
|
||||
reset=$(tput sgr0)
|
||||
bold=$(tput bold)
|
||||
black=$(tput setaf 0)
|
||||
red=$(tput setaf 1)
|
||||
green=$(tput bold; tput setaf 2)
|
||||
yellow=$(tput bold; tput setaf 3)
|
||||
blue=$(tput bold; tput setaf 6)
|
||||
timeout=$(if [ "$(uname)" == "Darwin" ]; then echo "1"; else echo "0.1"; fi)
|
||||
|
||||
|
||||
# Print colors you can use
|
||||
openim::color::print_color()
|
||||
@@ -85,3 +95,57 @@ openim::color::print_color()
|
||||
dim; blink; nobold; under"
|
||||
echo
|
||||
}
|
||||
|
||||
# test functions
|
||||
openim::color::test() {
|
||||
echo "Starting the color tests..."
|
||||
|
||||
echo "Testing normal echo without color"
|
||||
openim::color::echo $COLOR_NORMAL "This is a normal text"
|
||||
|
||||
echo "Testing bold echo"
|
||||
openim::color::echo $COLOR_BOLD "This is bold text"
|
||||
|
||||
echo "Testing dim echo"
|
||||
openim::color::echo $COLOR_DIM "This is dim text"
|
||||
|
||||
echo "Testing underlined echo"
|
||||
openim::color::echo $COLOR_UNDER "This is underlined text"
|
||||
|
||||
echo "Testing italic echo"
|
||||
openim::color::echo $COLOR_ITALIC "This is italic text"
|
||||
|
||||
echo "Testing red color"
|
||||
openim::color::echo $COLOR_RED "This is red text"
|
||||
|
||||
echo "Testing green color"
|
||||
openim::color::echo $COLOR_GREEN "This is green text"
|
||||
|
||||
echo "Testing yellow color"
|
||||
openim::color::echo $COLOR_YELLOW "This is yellow text"
|
||||
|
||||
echo "Testing blue color"
|
||||
openim::color::echo $COLOR_BLUE "This is blue text"
|
||||
|
||||
echo "Testing magenta color"
|
||||
openim::color::echo $COLOR_MAGENTA "This is magenta text"
|
||||
|
||||
echo "Testing cyan color"
|
||||
openim::color::echo $COLOR_CYAN "This is cyan text"
|
||||
|
||||
echo "Testing black background"
|
||||
openim::color::echo $COLOR_BBLACK "This is text with black background"
|
||||
|
||||
echo "Testing red background"
|
||||
openim::color::echo $COLOR_BRED "This is text with red background"
|
||||
|
||||
echo "Testing green background"
|
||||
openim::color::echo $COLOR_BGREEN "This is text with green background"
|
||||
|
||||
echo "Testing blue background"
|
||||
openim::color::echo $COLOR_BBLUE "This is text with blue background"
|
||||
|
||||
echo "All tests completed!"
|
||||
}
|
||||
|
||||
# openim::color::test
|
||||
|
||||
+123
-8
@@ -13,24 +13,58 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
# shellcheck disable=SC2034 # Variables sourced in other scripts.
|
||||
# The golang package that we are building.
|
||||
OPENIM_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
|
||||
readonly OPENIM_GO_PACKAGE=github.com/openimsdk/open-im-server
|
||||
|
||||
# The server platform we are building on.
|
||||
readonly OPENIM_SUPPORTED_SERVER_PLATFORMS=(
|
||||
linux/amd64
|
||||
linux/arm64
|
||||
linux/s390x
|
||||
linux_mips64
|
||||
linux_mips64le
|
||||
darwin_amd64
|
||||
windows_amd64
|
||||
linux_amd64
|
||||
linux_arm64
|
||||
linux_ppc64le
|
||||
)
|
||||
|
||||
# If we update this we should also update the set of platforms whose standard
|
||||
# library is precompiled for in build/build-image/cross/Dockerfile
|
||||
readonly OPENIM_SUPPORTED_CLIENT_PLATFORMS=(
|
||||
linux/amd64
|
||||
linux/arm64
|
||||
linux/s390x
|
||||
linux/ppc64le
|
||||
windows/amd64
|
||||
)
|
||||
|
||||
# openim chat
|
||||
readonly OPENIM_CHAT_SUPPORTED_PLATFORMS=(
|
||||
linux/amd64
|
||||
linux/arm64
|
||||
linux/s390x
|
||||
linux/ppc64le
|
||||
windows/amd64
|
||||
)
|
||||
|
||||
# Which platforms we should compile test targets for.
|
||||
# Not all client platforms need these tests
|
||||
readonly KUBE_SUPPORTED_TEST_PLATFORMS=(
|
||||
linux/amd64
|
||||
linux/arm64
|
||||
linux/s390x
|
||||
linux/ppc64le
|
||||
darwin/amd64
|
||||
darwin/arm64
|
||||
windows/amd64
|
||||
windows/arm64
|
||||
)
|
||||
|
||||
# The set of server targets that we are only building for Linux
|
||||
# If you update this list, please also update build/BUILD.
|
||||
# TODO: Label
|
||||
openim::golang::server_targets() {
|
||||
local targets=(
|
||||
openim-api
|
||||
@@ -54,14 +88,84 @@ IFS=" " read -ra OPENIM_SERVER_TARGETS <<< "$(openim::golang::server_targets)"
|
||||
readonly OPENIM_SERVER_TARGETS
|
||||
readonly OPENIM_SERVER_BINARIES=("${OPENIM_SERVER_TARGETS[@]##*/}")
|
||||
|
||||
# TODO: Label
|
||||
START_SCRIPTS_PATH="${OPENIM_ROOT}/scripts/install/"
|
||||
openim::golang::start_script_list() {
|
||||
local targets=(
|
||||
openim-api.sh
|
||||
openim-rpc.sh
|
||||
openim-push.sh
|
||||
openim-msgtransfer.sh
|
||||
openim-msggateway.sh
|
||||
openim-crontask.sh
|
||||
openim-tools.sh
|
||||
)
|
||||
local result=()
|
||||
for target in "${targets[@]}"; do
|
||||
result+=("${START_SCRIPTS_PATH}${target}")
|
||||
done
|
||||
|
||||
echo "${result[@]}"
|
||||
}
|
||||
|
||||
# Populate the OPENIM_SERVER_SCRIPT_START_LIST with the full path names of the scripts.
|
||||
IFS=" " read -ra OPENIM_SERVER_SCRIPT_START_LIST <<< "$(openim::golang::start_script_list)"
|
||||
readonly OPENIM_SERVER_SCRIPT_START_LIST
|
||||
|
||||
# Extract just the script names from the full paths.
|
||||
readonly OPENIM_SERVER_SCRIPTARIES=("${OPENIM_SERVER_SCRIPT_START_LIST[@]##*/}")
|
||||
|
||||
openim::golang::check_openim_binaries() {
|
||||
local missing_binaries=()
|
||||
for binary in "${OPENIM_SERVER_BINARIES[@]}"; do
|
||||
if [[ ! -x "${OPENIM_OUTPUT_HOSTBIN}/${binary}" ]]; then
|
||||
missing_binaries+=("${binary}")
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ ${#missing_binaries[@]} -ne 0 ]]; then
|
||||
echo "The following binaries were not found in ${OPENIM_OUTPUT_HOSTBIN}:"
|
||||
for missing in "${missing_binaries[@]}"; do
|
||||
echo " - ${missing}"
|
||||
done
|
||||
return 1
|
||||
else
|
||||
echo "All binaries have been installed in ${OPENIM_OUTPUT_HOSTBIN}。"
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
openim::golang::tools_targets() {
|
||||
local targets=(
|
||||
yamlfmt
|
||||
changelog
|
||||
infra
|
||||
ncpu
|
||||
)
|
||||
echo "${targets[@]}"
|
||||
}
|
||||
|
||||
IFS=" " read -ra OPENIM_TOOLS_TARGETS <<< "$(openim::golang::tools_targets)"
|
||||
readonly OPENIM_TOOLS_TARGETS
|
||||
readonly OPENIM_TOOLS_BINARIES=("${OPENIM_TOOLS_TARGETS[@]##*/}")
|
||||
|
||||
# The set of server targets we build docker images for
|
||||
openim::golang::server_image_targets() {
|
||||
# NOTE: this contains cmd targets for openim::build::get_docker_wrapped_binaries
|
||||
local targets=(
|
||||
cmd/openim-apiserver
|
||||
cmd/openim-authz-server
|
||||
cmd/openim-pump
|
||||
cmd/openim-watcher
|
||||
cmd/openim-api
|
||||
cmd/openim-cmdutils
|
||||
cmd/openim-crontask
|
||||
cmd/openim-msggateway
|
||||
cmd/openim-msgtransfer
|
||||
cmd/openim-push
|
||||
cmd/openim-rpc-auth
|
||||
cmd/openim-rpc-conversation
|
||||
cmd/openim-rpc-friend
|
||||
cmd/openim-rpc-group
|
||||
cmd/openim-rpc-msg
|
||||
cmd/openim-rpc-third
|
||||
cmd/openim-rpc-user
|
||||
)
|
||||
echo "${targets[@]}"
|
||||
}
|
||||
@@ -70,6 +174,8 @@ IFS=" " read -ra OPENIM_SERVER_IMAGE_TARGETS <<< "$(openim::golang::server_image
|
||||
readonly OPENIM_SERVER_IMAGE_TARGETS
|
||||
readonly OPENIM_SERVER_IMAGE_BINARIES=("${OPENIM_SERVER_IMAGE_TARGETS[@]##*/}")
|
||||
|
||||
# shellcheck disable=SC2034 # Variables sourced in other scripts.
|
||||
|
||||
# ------------
|
||||
# NOTE: All functions that return lists should use newlines.
|
||||
# bash functions can't return arrays, and spaces are tricky, so newline
|
||||
@@ -87,12 +193,21 @@ openim::golang::dups() {
|
||||
printf "%s\n" "$@" | sort | uniq -d
|
||||
}
|
||||
|
||||
# echo "aa: $OPENIM_SERVER_IMAGE_TARGETS"
|
||||
# echo "aa: $OPENIM_SERVER_IMAGE_BINARIES"
|
||||
|
||||
openim::golang::dups $OPENIM_SERVER_IMAGE_TARGETS
|
||||
openim::golang::dups $OPENIM_SERVER_IMAGE_BINARIES
|
||||
|
||||
# Returns a sorted newline-separated list with duplicated items removed.
|
||||
openim::golang::dedup() {
|
||||
# We use printf to insert newlines, which are required by sort.
|
||||
printf "%s\n" "$@" | sort -u
|
||||
}
|
||||
|
||||
# openim::golang::dedup $OPENIM_SERVER_IMAGE_TARGETS
|
||||
# openim::golang::dedup $OPENIM_SERVER_IMAGE_BINARIES
|
||||
|
||||
# Depends on values of user-facing OPENIM_BUILD_PLATFORMS, OPENIM_FASTBUILD,
|
||||
# and OPENIM_BUILDER_OS.
|
||||
# Configures OPENIM_SERVER_PLATFORMS and OPENIM_CLIENT_PLATFORMS, then sets them
|
||||
@@ -175,7 +290,7 @@ EOF
|
||||
local go_version
|
||||
IFS=" " read -ra go_version <<< "$(go version)"
|
||||
local minimum_go_version
|
||||
minimum_go_version=go1.13.4
|
||||
minimum_go_version=go1.18
|
||||
if [[ "${minimum_go_version}" != $(echo -e "${minimum_go_version}\n${go_version[2]}" | sort -s -t. -k 1,1 -k 2,2n -k 3,3n | head -n1) && "${go_version[2]}" != "devel" ]]; then
|
||||
openim::log::usage_from_stdin <<EOF
|
||||
Detected go version: ${go_version[*]}.
|
||||
|
||||
+176
-7
@@ -13,25 +13,194 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
set -o errexit
|
||||
set +o nounset
|
||||
set -o pipefail
|
||||
|
||||
# Short-circuit if init.sh has already been sourced
|
||||
[[ $(type -t openim::init::loaded) == function ]] && return 0
|
||||
|
||||
# Unset CDPATH so that path interpolation can work correctly
|
||||
unset CDPATH
|
||||
|
||||
# Default use go modules
|
||||
# Until all GOPATH references are removed from all build scripts as well,
|
||||
# explicitly disable module mode to avoid picking up user-set GO111MODULE preferences.
|
||||
# As individual scripts (like hack/update-vendor.sh) make use of go modules,
|
||||
# they can explicitly set GO111MODULE=on
|
||||
export GO111MODULE=on
|
||||
|
||||
# The root of the build/dist directory
|
||||
OPENIM_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
|
||||
|
||||
source "${OPENIM_ROOT}/scripts/lib/util.sh"
|
||||
source "${OPENIM_ROOT}/scripts/lib/logging.sh"
|
||||
source "${OPENIM_ROOT}/scripts/lib/color.sh"
|
||||
OPENIM_OUTPUT_SUBPATH="${OPENIM_OUTPUT_SUBPATH:-_output}"
|
||||
OPENIM_OUTPUT="${OPENIM_ROOT}/${OPENIM_OUTPUT_SUBPATH}"
|
||||
|
||||
OPENIM_OUTPUT_BINPATH="${OPENIM_OUTPUT}/bin/platforms"
|
||||
OPENIM_OUTPUT_BINTOOLPATH="${OPENIM_OUTPUT}/bin/tools"
|
||||
OPENIM_OUTPUT_TOOLS="${OPENIM_OUTPUT}/tools"
|
||||
OPENIM_OUTPUT_TMP="${OPENIM_OUTPUT}/tmp"
|
||||
OPENIM_OUTPUT_LOGS="${OPENIM_OUTPUT}/logs"
|
||||
|
||||
# This controls rsync compression. Set to a value > 0 to enable rsync
|
||||
# compression for build container
|
||||
OPENIM_RSYNC_COMPRESS="${KUBE_RSYNC_COMPRESS:-0}"
|
||||
|
||||
# Set no_proxy for localhost if behind a proxy, otherwise,
|
||||
# the connections to localhost in scripts will time out
|
||||
export no_proxy="127.0.0.1,localhost${no_proxy:+,${no_proxy}}"
|
||||
|
||||
# This is a symlink to binaries for "this platform", e.g. build tools.
|
||||
export THIS_PLATFORM_BIN="${OPENIM_ROOT}/_output/bin/platforms"
|
||||
export THIS_PLATFORM_BIN_TOOLS="${OPENIM_ROOT}/_output/bin/tools"
|
||||
|
||||
. $(dirname ${BASH_SOURCE})/color.sh
|
||||
. $(dirname ${BASH_SOURCE})/util.sh
|
||||
. $(dirname ${BASH_SOURCE})/logging.sh
|
||||
|
||||
openim::log::install_errexit
|
||||
openim::util::ensure-bash-version
|
||||
|
||||
source "${OPENIM_ROOT}/scripts/lib/version.sh"
|
||||
source "${OPENIM_ROOT}/scripts/lib/golang.sh"
|
||||
. $(dirname ${BASH_SOURCE})/version.sh
|
||||
. $(dirname ${BASH_SOURCE})/golang.sh
|
||||
. $(dirname ${BASH_SOURCE})/release.sh
|
||||
. $(dirname ${BASH_SOURCE})/chat.sh
|
||||
|
||||
OPENIM_OUTPUT_HOSTBIN="${OPENIM_OUTPUT_BINPATH}/$(openim::util::host_platform)"
|
||||
export OPENIM_OUTPUT_HOSTBIN
|
||||
OPENIM_OUTPUT_HOSTBIN_TOOLS="${OPENIM_OUTPUT_BINTOOLPATH}/$(openim::util::host_platform)"
|
||||
export OPENIM_OUTPUT_HOSTBIN_TOOLS
|
||||
|
||||
export OPENIM_NONSERVER_GROUP_VERSIONS
|
||||
|
||||
|
||||
# This emulates "readlink -f" which is not available on MacOS X.
|
||||
# Test:
|
||||
# T=/tmp/$$.$RANDOM
|
||||
# mkdir $T
|
||||
# touch $T/file
|
||||
# mkdir $T/dir
|
||||
# ln -s $T/file $T/linkfile
|
||||
# ln -s $T/dir $T/linkdir
|
||||
# function testone() {
|
||||
# X=$(readlink -f $1 2>&1)
|
||||
# Y=$(kube::readlinkdashf $1 2>&1)
|
||||
# if [ "$X" != "$Y" ]; then
|
||||
# echo readlinkdashf $1: expected "$X", got "$Y"
|
||||
# fi
|
||||
# }
|
||||
# testone /
|
||||
# testone /tmp
|
||||
# testone $T
|
||||
# testone $T/file
|
||||
# testone $T/dir
|
||||
# testone $T/linkfile
|
||||
# testone $T/linkdir
|
||||
# testone $T/nonexistant
|
||||
# testone $T/linkdir/file
|
||||
# testone $T/linkdir/dir
|
||||
# testone $T/linkdir/linkfile
|
||||
# testone $T/linkdir/linkdir
|
||||
function openim::readlinkdashf {
|
||||
# run in a subshell for simpler 'cd'
|
||||
(
|
||||
if [[ -d "${1}" ]]; then # This also catch symlinks to dirs.
|
||||
cd "${1}"
|
||||
pwd -P
|
||||
else
|
||||
cd "$(dirname "${1}")"
|
||||
local f
|
||||
f=$(basename "${1}")
|
||||
if [[ -L "${f}" ]]; then
|
||||
readlink "${f}"
|
||||
else
|
||||
echo "$(pwd -P)/${f}"
|
||||
fi
|
||||
fi
|
||||
)
|
||||
}
|
||||
|
||||
# This emulates "readlink -f" which is not available on MacOS X.
|
||||
# Test:
|
||||
# T=/tmp/$$.$RANDOM
|
||||
# mkdir $T
|
||||
# touch $T/file
|
||||
# mkdir $T/dir
|
||||
# ln -s $T/file $T/linkfile
|
||||
# ln -s $T/dir $T/linkdir
|
||||
# function testone() {
|
||||
# X=$(readlink -f $1 2>&1)
|
||||
# Y=$(kube::readlinkdashf $1 2>&1)
|
||||
# if [ "$X" != "$Y" ]; then
|
||||
# echo readlinkdashf $1: expected "$X", got "$Y"
|
||||
# fi
|
||||
# }
|
||||
# testone /
|
||||
# testone /tmp
|
||||
# testone $T
|
||||
# testone $T/file
|
||||
# testone $T/dir
|
||||
# testone $T/linkfile
|
||||
# testone $T/linkdir
|
||||
# testone $T/nonexistant
|
||||
# testone $T/linkdir/file
|
||||
# testone $T/linkdir/dir
|
||||
# testone $T/linkdir/linkfile
|
||||
# testone $T/linkdir/linkdir
|
||||
function openim::readlinkdashf {
|
||||
# run in a subshell for simpler 'cd'
|
||||
(
|
||||
if [[ -d "${1}" ]]; then # This also catch symlinks to dirs.
|
||||
cd "${1}"
|
||||
pwd -P
|
||||
else
|
||||
cd "$(dirname "${1}")"
|
||||
local f
|
||||
f=$(basename "${1}")
|
||||
if [[ -L "${f}" ]]; then
|
||||
readlink "${f}"
|
||||
else
|
||||
echo "$(pwd -P)/${f}"
|
||||
fi
|
||||
fi
|
||||
)
|
||||
}
|
||||
|
||||
# This emulates "realpath" which is not available on MacOS X
|
||||
# Test:
|
||||
# T=/tmp/$$.$RANDOM
|
||||
# mkdir $T
|
||||
# touch $T/file
|
||||
# mkdir $T/dir
|
||||
# ln -s $T/file $T/linkfile
|
||||
# ln -s $T/dir $T/linkdir
|
||||
# function testone() {
|
||||
# X=$(realpath $1 2>&1)
|
||||
# Y=$(kube::realpath $1 2>&1)
|
||||
# if [ "$X" != "$Y" ]; then
|
||||
# echo realpath $1: expected "$X", got "$Y"
|
||||
# fi
|
||||
# }
|
||||
# testone /
|
||||
# testone /tmp
|
||||
# testone $T
|
||||
# testone $T/file
|
||||
# testone $T/dir
|
||||
# testone $T/linkfile
|
||||
# testone $T/linkdir
|
||||
# testone $T/nonexistant
|
||||
# testone $T/linkdir/file
|
||||
# testone $T/linkdir/dir
|
||||
# testone $T/linkdir/linkfile
|
||||
# testone $T/linkdir/linkdir
|
||||
openim::realpath() {
|
||||
if [[ ! -e "${1}" ]]; then
|
||||
echo "${1}: No such file or directory" >&2
|
||||
return 1
|
||||
fi
|
||||
openim::readlinkdashf "${1}"
|
||||
}
|
||||
|
||||
# Marker function to indicate init.sh has been fully sourced
|
||||
openim::init::loaded() {
|
||||
return 0
|
||||
}
|
||||
+67
-15
@@ -13,10 +13,39 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
# Controls verbosity of the script output and logging.
|
||||
OPENIM_VERBOSE="${OPENIM_VERBOSE:-5}"
|
||||
|
||||
# Enable logging by default. Set to false to disable.
|
||||
ENABLE_LOGGING=true
|
||||
|
||||
# If OPENIM_OUTPUT is not set, set it to the default value
|
||||
if [[ ! -v OPENIM_OUTPUT ]]; then
|
||||
OPENIM_OUTPUT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../_output" && pwd -P)"
|
||||
fi
|
||||
|
||||
# Set the log file path
|
||||
LOG_FILE="${OPENIM_OUTPUT}/logs/openim_$(date '+%Y%m%d').log"
|
||||
|
||||
if [[ ! -d "${OPENIM_OUTPUT}/logs" ]]; then
|
||||
mkdir -p "${OPENIM_OUTPUT}/logs"
|
||||
touch "$LOG_FILE"
|
||||
fi
|
||||
|
||||
# Define the logging function
|
||||
function echo_log() {
|
||||
if $ENABLE_LOGGING; then
|
||||
echo -e "$@" | tee -a "${LOG_FILE}"
|
||||
else
|
||||
echo -e "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
# MAX_LOG_SIZE=10485760 # 10MB
|
||||
|
||||
# Clear logs from 5 days ago
|
||||
# find $OPENIM_OUTPUT_LOGS -type f -name "*.log" -mtime +5 -exec rm -f {} \;
|
||||
|
||||
# Handler for when we exit automatically on an error.
|
||||
# Borrowed from https://gist.github.com/ahendrix/7030300
|
||||
openim::log::errexit() {
|
||||
@@ -58,7 +87,7 @@ openim::log::stack() {
|
||||
local stack_skip=${1:-0}
|
||||
stack_skip=$((stack_skip + 1))
|
||||
if [[ ${#FUNCNAME[@]} -gt ${stack_skip} ]]; then
|
||||
echo "Call stack:" >&2
|
||||
echo_log "Call stack:" >&2
|
||||
local i
|
||||
for ((i=1 ; i <= ${#FUNCNAME[@]} - stack_skip ; i++))
|
||||
do
|
||||
@@ -66,7 +95,7 @@ openim::log::stack() {
|
||||
local source_file=${BASH_SOURCE[${frame_no}]}
|
||||
local source_lineno=${BASH_LINENO[$((frame_no - 1))]}
|
||||
local funcname=${FUNCNAME[${frame_no}]}
|
||||
echo " ${i}: ${source_file}:${source_lineno} ${funcname}(...)" >&2
|
||||
echo_log " ${i}: ${source_file}:${source_lineno} ${funcname}(...)" >&2
|
||||
done
|
||||
fi
|
||||
}
|
||||
@@ -85,14 +114,14 @@ openim::log::error_exit() {
|
||||
if [[ ${OPENIM_VERBOSE} -ge 4 ]]; then
|
||||
local source_file=${BASH_SOURCE[${stack_skip}]}
|
||||
local source_line=${BASH_LINENO[$((stack_skip - 1))]}
|
||||
echo "!!! Error in ${source_file}:${source_line}" >&2
|
||||
echo_log -e "${COLOR_RED}!!! Error in ${source_file}:${source_line} ${COLOR_SUFFIX}" >&2
|
||||
[[ -z ${1-} ]] || {
|
||||
echo " ${1}" >&2
|
||||
echo_log " ${1}" >&2
|
||||
}
|
||||
|
||||
openim::log::stack ${stack_skip}
|
||||
|
||||
echo "Exiting with status ${code}" >&2
|
||||
echo_log "Exiting with status ${code}" >&2
|
||||
fi
|
||||
|
||||
exit "${code}"
|
||||
@@ -101,21 +130,21 @@ openim::log::error_exit() {
|
||||
# Log an error but keep going. Don't dump the stack or exit.
|
||||
openim::log::error() {
|
||||
timestamp=$(date +"[%m%d %H:%M:%S]")
|
||||
echo "!!! ${timestamp} ${1-}" >&2
|
||||
echo_log "!!! ${timestamp} ${1-}" >&2
|
||||
shift
|
||||
for message; do
|
||||
echo " ${message}" >&2
|
||||
echo_log " ${message}" >&2
|
||||
done
|
||||
}
|
||||
|
||||
# Print an usage message to stderr. The arguments are printed directly.
|
||||
openim::log::usage() {
|
||||
echo >&2
|
||||
echo_log >&2
|
||||
local message
|
||||
for message; do
|
||||
echo "${message}" >&2
|
||||
echo_log "${message}" >&2
|
||||
done
|
||||
echo >&2
|
||||
echo_log >&2
|
||||
}
|
||||
|
||||
openim::log::usage_from_stdin() {
|
||||
@@ -135,17 +164,18 @@ openim::log::info() {
|
||||
fi
|
||||
|
||||
for message; do
|
||||
echo "${message}"
|
||||
echo_log "${message}"
|
||||
done
|
||||
}
|
||||
|
||||
# Just like openim::log::info, but no \n, so you can make a progress bar
|
||||
openim::log::progress() {
|
||||
for message; do
|
||||
echo -e -n "${message}"
|
||||
echo_log -e -n "${message}"
|
||||
done
|
||||
}
|
||||
|
||||
# Print out some info that isn't a top level status line
|
||||
openim::log::info_from_stdin() {
|
||||
local messages=()
|
||||
while read -r line; do
|
||||
@@ -163,9 +193,31 @@ openim::log::status() {
|
||||
fi
|
||||
|
||||
timestamp=$(date +"[%m%d %H:%M:%S]")
|
||||
echo "+++ ${timestamp} ${1}"
|
||||
echo_log "+++ ${timestamp} ${1}"
|
||||
shift
|
||||
for message; do
|
||||
echo " ${message}"
|
||||
echo_log " ${message}"
|
||||
done
|
||||
}
|
||||
|
||||
openim::log::success()
|
||||
{
|
||||
local V="${V:-0}"
|
||||
if [[ ${OPENIM_VERBOSE} < ${V} ]]; then
|
||||
return
|
||||
fi
|
||||
timestamp=$(date +"%m%d %H:%M:%S")
|
||||
echo_log -e "${COLOR_GREEN}[success ${timestamp}] ${COLOR_SUFFIX}==> " "$@"
|
||||
}
|
||||
|
||||
function openim::log::test_log() {
|
||||
echo_log "test log"
|
||||
openim::log::error "openim::log::error"
|
||||
openim::log::info "openim::log::info"
|
||||
openim::log::progress "openim::log::progress"
|
||||
openim::log::status "openim::log::status"
|
||||
openim::log::success "openim::log::success"
|
||||
openim::log::error_exit "openim::log::error_exit"
|
||||
}
|
||||
|
||||
# openim::log::test_log
|
||||
@@ -38,6 +38,7 @@ readonly RELEASE_IMAGES="${LOCAL_OUTPUT_ROOT}/release-images"
|
||||
# OpenIM github account info
|
||||
readonly OPENIM_GITHUB_ORG=OpenIMSDK
|
||||
readonly OPENIM_GITHUB_REPO=Open-IM-Server
|
||||
readonly CHAT_GITHUB_REPO=chat
|
||||
|
||||
readonly ARTIFACT=openim.tar.gz
|
||||
readonly CHECKSUM=${ARTIFACT}.sha1sum
|
||||
@@ -104,7 +105,7 @@ function openim::release::package_tarballs() {
|
||||
mkdir -p "${RELEASE_TARS}"
|
||||
openim::release::package_src_tarball &
|
||||
openim::release::package_client_tarballs &
|
||||
openim::release::package_iam_manifests_tarball &
|
||||
openim::release::package_openim_manifests_tarball &
|
||||
openim::release::package_server_tarballs &
|
||||
openim::util::wait-for-jobs || { openim::log::error "previous tarball phase failed"; return 1; }
|
||||
|
||||
@@ -143,8 +144,8 @@ function openim::release::package_src_tarball() {
|
||||
-path "${OPENIM_ROOT}"/.config\* -o \
|
||||
-path "${OPENIM_ROOT}"/.chglog\* -o \
|
||||
-path "${OPENIM_ROOT}"/.gitlint -o \
|
||||
-path "${OPENIM_ROOT}"/.golangci.yml -o \
|
||||
-path "${OPENIM_ROOT}"/.goreleaser.yml -o \
|
||||
-path "${OPENIM_ROOT}"/scripts/golangci.yml -o \
|
||||
-path "${OPENIM_ROOT}"/build/goreleaser.yaml -o \
|
||||
-path "${OPENIM_ROOT}"/.note.md -o \
|
||||
-path "${OPENIM_ROOT}"/.todo.md \
|
||||
\) -prune \
|
||||
@@ -395,7 +396,7 @@ EOF
|
||||
}
|
||||
|
||||
# This will pack openim-system manifests files for distros such as COS.
|
||||
function openim::release::package_iam_manifests_tarball() {
|
||||
function openim::release::package_openim_manifests_tarball() {
|
||||
openim::log::status "Building tarball: manifests"
|
||||
|
||||
local src_dir="${OPENIM_ROOT}/deployments"
|
||||
@@ -456,11 +457,6 @@ EOF
|
||||
cp -R "${OPENIM_ROOT}/scripts/release" "${release_stage}/"
|
||||
cat <<EOF > "${release_stage}/release/get-openim-binaries.sh"
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright 2020 Lingfei Kong <colin404@foxmail.com>. All rights reserved.
|
||||
# Use of this source code is governed by a MIT style
|
||||
# license that can be found in the LICENSE file.
|
||||
|
||||
# This file download openim client and server binaries from tencent cos bucket.
|
||||
|
||||
os=linux arch=amd64 version=${OPENIM_GIT_VERSION} && wget https://${BUCKET}.cos.${REGION}.myqcloud.com/${COS_RELEASE_DIR}/\$version/{openim-client-\$os-\$arch.tar.gz,openim-server-\$os-\$arch.tar.gz}
|
||||
|
||||
+593
-42
@@ -13,6 +13,74 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# this script is used to check whether the code is formatted by gofmt or not
|
||||
#
|
||||
# Usage: source scripts/lib/util.sh
|
||||
################################################################################
|
||||
|
||||
# TODO Debug: Just for testing, please comment out
|
||||
# OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
|
||||
# source "${OPENIM_ROOT}/scripts/lib/logging.sh"
|
||||
|
||||
#1、将IP写在一个文件里,比如文件名为hosts_file,一行一个IP地址。
|
||||
#2、修改ssh-mutual-trust.sh里面的用户名及密码,默认为root用户及密码123。
|
||||
# hosts_file_path="path/to/your/hosts/file"
|
||||
# openim:util::setup_ssh_key_copy "$hosts_file_path" "root" "123"
|
||||
function openim:util::setup_ssh_key_copy() {
|
||||
local hosts_file="$1"
|
||||
local username="${2:-root}"
|
||||
local password="${3:-123}"
|
||||
|
||||
local sshkey_file=~/.ssh/id_rsa.pub
|
||||
|
||||
# check sshkey file
|
||||
if [[ ! -e $sshkey_file ]]; then
|
||||
expect -c "
|
||||
spawn ssh-keygen -t rsa
|
||||
expect \"Enter*\" { send \"\n\"; exp_continue; }
|
||||
"
|
||||
fi
|
||||
|
||||
# get hosts list
|
||||
local hosts=$(awk '/^[^#]/ {print $1}' "${hosts_file}")
|
||||
|
||||
ssh_key_copy() {
|
||||
local target=$1
|
||||
|
||||
# delete history
|
||||
sed -i "/$target/d" ~/.ssh/known_hosts
|
||||
|
||||
# copy key
|
||||
expect -c "
|
||||
set timeout 100
|
||||
spawn ssh-copy-id $username@$target
|
||||
expect {
|
||||
\"yes/no\" { send \"yes\n\"; exp_continue; }
|
||||
\"*assword\" { send \"$password\n\"; }
|
||||
\"already exist on the remote system\" { exit 1; }
|
||||
}
|
||||
expect eof
|
||||
"
|
||||
}
|
||||
|
||||
# auto sshkey pair
|
||||
for host in $hosts; do
|
||||
if ! ping -i 0.2 -c 3 -W 1 "$host" > /dev/null 2>&1; then
|
||||
echo "[ERROR]: Can't connect $host"
|
||||
continue
|
||||
fi
|
||||
|
||||
local host_entry=$(awk "/$host/"'{print $1, $2}' /etc/hosts)
|
||||
if [[ $host_entry ]]; then
|
||||
local hostaddr=$(echo "$host_entry" | awk '{print $1}')
|
||||
local hostname=$(echo "$host_entry" | awk '{print $2}')
|
||||
ssh_key_copy "$hostaddr"
|
||||
ssh_key_copy "$hostname"
|
||||
else
|
||||
ssh_key_copy "$host"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function openim::util::sourced_variable {
|
||||
# Call this function to tell shellcheck that a variable is supposed to
|
||||
@@ -64,7 +132,7 @@ openim::util::wait_for_url() {
|
||||
return 1
|
||||
}
|
||||
|
||||
# Example: openim::util::wait_for_success 120 5 "imctl get nodes|grep localhost"
|
||||
# Example: openim::util::wait_for_success 120 5 "openimctl get nodes|grep localhost"
|
||||
# arguments: wait time, sleep time, shell command
|
||||
# returns 0 if the shell command get output, 1 otherwise.
|
||||
openim::util::wait_for_success(){
|
||||
@@ -122,7 +190,7 @@ openim::util::cleanup-temp-dir() {
|
||||
# OPENIM_TEMP
|
||||
openim::util::ensure-temp-dir() {
|
||||
if [[ -z ${OPENIM_TEMP-} ]]; then
|
||||
OPENIM_TEMP=$(mktemp -d 2>/dev/null || mktemp -d -t iamrnetes.XXXXXX)
|
||||
OPENIM_TEMP=$(mktemp -d 2>/dev/null || mktemp -d -t openimrnetes.XXXXXX)
|
||||
openim::util::trap_add openim::util::cleanup-temp-dir EXIT
|
||||
fi
|
||||
}
|
||||
@@ -182,6 +250,272 @@ openim::util::host_arch() {
|
||||
echo "${host_arch}"
|
||||
}
|
||||
|
||||
# The `openim::util::check_ports` function analyzes the state of processes based on given ports.
|
||||
# It accepts multiple ports as arguments and prints:
|
||||
# 1. The state of the process (whether it's running or not).
|
||||
# 2. The start time of the process if it's running.
|
||||
# User:
|
||||
# openim::util::check_ports 8080 8081 8082
|
||||
# The function returns a status of 1 if any of the processes is not running.
|
||||
openim::util::check_ports() {
|
||||
# An array to collect ports of processes that are not running.
|
||||
local not_started=()
|
||||
|
||||
# An array to collect information about processes that are running.
|
||||
local started=()
|
||||
|
||||
openim::log::info "Checking ports: $*"
|
||||
# Iterate over each given port.
|
||||
for port in "$@"; do
|
||||
# Use the `lsof` command to find process information related to the given port.
|
||||
local info=$(lsof -i :$port -n -P | grep LISTEN || true)
|
||||
|
||||
# If there's no process information, it means the process associated with the port is not running.
|
||||
if [[ -z $info ]]; then
|
||||
not_started+=($port)
|
||||
else
|
||||
# If there's process information, extract relevant details:
|
||||
# Process ID, Command Name, and Start Time.
|
||||
local pid=$(echo $info | awk '{print $2}')
|
||||
local command=$(echo $info | awk '{print $1}')
|
||||
local start_time=$(ps -o lstart= -p $pid)
|
||||
started+=("Port $port - Command: $command, PID: $pid, Start time: $start_time")
|
||||
fi
|
||||
done
|
||||
echo
|
||||
# Print information about ports whose processes are not running.
|
||||
if [[ ${#not_started[@]} -ne 0 ]]; then
|
||||
openim::log::info "### Not started ports:"
|
||||
for port in "${not_started[@]}"; do
|
||||
openim::log::error "Port $port is not started."
|
||||
done
|
||||
fi
|
||||
|
||||
# Print information about ports whose processes are running.
|
||||
if [[ ${#started[@]} -ne 0 ]]; then
|
||||
echo
|
||||
openim::log::info "### Started ports:"
|
||||
for info in "${started[@]}"; do
|
||||
openim::log::info "$info"
|
||||
done
|
||||
fi
|
||||
|
||||
# If any of the processes is not running, return a status of 1.
|
||||
if [[ ${#not_started[@]} -ne 0 ]]; then
|
||||
echo "++++ OpenIM Log >> cat ${LOG_FILE}"
|
||||
return 1
|
||||
else
|
||||
openim::log::success "started[@] processes are running."
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
# openim::util::check_ports 10002 1004
|
||||
|
||||
# The `openim::util::check_process_names` function analyzes the state of processes based on given names.
|
||||
# It accepts multiple process names as arguments and prints:
|
||||
# 1. The state of the process (whether it's running or not).
|
||||
# 2. The start time of the process if it's running.
|
||||
# User:
|
||||
# openim::util::check_process_names nginx mysql redis
|
||||
# The function returns a status of 1 if any of the processes is not running.
|
||||
openim::util::check_process_names() {
|
||||
# Arrays to collect details of processes
|
||||
local not_started=()
|
||||
local started=()
|
||||
|
||||
openim::log::info "Checking processes: $*"
|
||||
# Iterate over each given process name
|
||||
for process_name in "$@"; do
|
||||
# Use `pgrep` to find process IDs related to the given process name
|
||||
local pids=($(pgrep -f $process_name))
|
||||
|
||||
# Check if any process IDs were found
|
||||
if [[ ${#pids[@]} -eq 0 ]]; then
|
||||
not_started+=($process_name)
|
||||
else
|
||||
# If there are PIDs, loop through each one
|
||||
for pid in "${pids[@]}"; do
|
||||
local command=$(ps -p $pid -o cmd=)
|
||||
local start_time=$(ps -p $pid -o lstart=)
|
||||
local port=$(ss -ltnp 2>/dev/null | grep $pid | awk '{print $4}' | cut -d ':' -f2)
|
||||
|
||||
# Check if port information was found for the PID
|
||||
if [[ -z $port ]]; then
|
||||
port="N/A"
|
||||
fi
|
||||
|
||||
started+=("Process $process_name - Command: $command, PID: $pid, Port: $port, Start time: $start_time")
|
||||
done
|
||||
fi
|
||||
done
|
||||
|
||||
# Print information
|
||||
if [[ ${#not_started[@]} -ne 0 ]]; then
|
||||
openim::log::info "Not started processes:"
|
||||
for process_name in "${not_started[@]}"; do
|
||||
openim::log::error "Process $process_name is not started."
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ ${#started[@]} -ne 0 ]]; then
|
||||
echo
|
||||
openim::log::info "Started processes:"
|
||||
for info in "${started[@]}"; do
|
||||
openim::log::info "$info"
|
||||
done
|
||||
fi
|
||||
|
||||
# Return status
|
||||
if [[ ${#not_started[@]} -ne 0 ]]; then
|
||||
echo "++++ OpenIM Log >> cat ${LOG_FILE}"
|
||||
return 1
|
||||
else
|
||||
openim::log::success "All processes are running."
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
# openim::util::check_process_names docker-pr
|
||||
|
||||
# The `openim::util::stop_services_on_ports` function stops services running on specified ports.
|
||||
# It accepts multiple ports as arguments and performs the following:
|
||||
# 1. Attempts to stop any services running on the specified ports.
|
||||
# 2. Prints details of services successfully stopped and those that failed to stop.
|
||||
# Usage:
|
||||
# openim::util::stop_services_on_ports 8080 8081 8082
|
||||
# The function returns a status of 1 if any service couldn't be stopped.
|
||||
openim::util::stop_services_on_ports() {
|
||||
# An array to collect ports of processes that couldn't be stopped.
|
||||
local not_stopped=()
|
||||
|
||||
# An array to collect information about processes that were stopped.
|
||||
local stopped=()
|
||||
|
||||
openim::log::info "Stopping services on ports: $*"
|
||||
# Iterate over each given port.
|
||||
for port in "$@"; do
|
||||
# Use the `lsof` command to find process information related to the given port.
|
||||
info=$(lsof -i :$port -n -P | grep LISTEN || true)
|
||||
|
||||
# If there's process information, it means the process associated with the port is running.
|
||||
if [[ -n $info ]]; then
|
||||
# Extract the Process ID.
|
||||
while read -r line; do
|
||||
local pid=$(echo $line | awk '{print $2}')
|
||||
|
||||
# Try to stop the service by killing its process.
|
||||
if kill -TERM $pid; then
|
||||
stopped+=($port)
|
||||
else
|
||||
not_stopped+=($port)
|
||||
fi
|
||||
done <<< "$info"
|
||||
fi
|
||||
done
|
||||
|
||||
# Print information about ports whose processes couldn't be stopped.
|
||||
if [[ ${#not_stopped[@]} -ne 0 ]]; then
|
||||
openim::log::info "Ports that couldn't be stopped:"
|
||||
for port in "${not_stopped[@]}"; do
|
||||
openim::log::status "Failed to stop service on port $port."
|
||||
done
|
||||
fi
|
||||
|
||||
# Print information about ports whose processes were successfully stopped.
|
||||
if [[ ${#stopped[@]} -ne 0 ]]; then
|
||||
echo
|
||||
openim::log::info "Stopped services on ports:"
|
||||
for port in "${stopped[@]}"; do
|
||||
openim::log::info "Successfully stopped service on port $port."
|
||||
done
|
||||
fi
|
||||
|
||||
# If any of the processes couldn't be stopped, return a status of 1.
|
||||
if [[ ${#not_stopped[@]} -ne 0 ]]; then
|
||||
return 1
|
||||
else
|
||||
openim::log::success "All specified services were stopped."
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
# nc -l -p 12345
|
||||
# nc -l -p 123456
|
||||
# ps -ef | grep "nc -l"
|
||||
# openim::util::stop_services_on_ports 1234 12345
|
||||
|
||||
|
||||
# The `openim::util::stop_services_with_name` function stops services with specified names.
|
||||
# It accepts multiple service names as arguments and performs the following:
|
||||
# 1. Attempts to stop any services with the specified names.
|
||||
# 2. Prints details of services successfully stopped and those that failed to stop.
|
||||
# Usage:
|
||||
# openim::util::stop_services_with_name nginx apache
|
||||
# The function returns a status of 1 if any service couldn't be stopped.
|
||||
openim::util::stop_services_with_name() {
|
||||
# An array to collect names of processes that couldn't be stopped.
|
||||
local not_stopped=()
|
||||
|
||||
# An array to collect information about processes that were stopped.
|
||||
local stopped=()
|
||||
|
||||
openim::log::info "Stopping services with names: $*"
|
||||
# Iterate over each given service name.
|
||||
for server_name in "$@"; do
|
||||
# Use the `pgrep` command to find process IDs related to the given service name.
|
||||
local pids=$(pgrep -f "$server_name")
|
||||
|
||||
# If no process was found with the name, add it to the not_stopped list
|
||||
if [[ -z $pids ]]; then
|
||||
not_stopped+=("$server_name")
|
||||
continue
|
||||
fi
|
||||
local stopped_this_time=false
|
||||
for pid in $pids; do
|
||||
|
||||
# Exclude the PID of the current script
|
||||
if [[ "$pid" == "$$" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# If there's a Process ID, it means the service with the name is running.
|
||||
if [[ -n $pid ]]; then
|
||||
# Try to stop the service by killing its process.
|
||||
if kill -TERM $pid 2>/dev/null; then
|
||||
stopped_this_time=true
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if $stopped_this_time; then
|
||||
stopped+=("$server_name")
|
||||
else
|
||||
not_stopped+=("$server_name")
|
||||
fi
|
||||
done
|
||||
|
||||
# Print information about services whose processes couldn't be stopped.
|
||||
if [[ ${#not_stopped[@]} -ne 0 ]]; then
|
||||
openim::log::info "Services that couldn't be stopped:"
|
||||
for name in "${not_stopped[@]}"; do
|
||||
openim::log::status "Failed to stop the $name service."
|
||||
done
|
||||
fi
|
||||
|
||||
# Print information about services whose processes were successfully stopped.
|
||||
if [[ ${#stopped[@]} -ne 0 ]]; then
|
||||
echo
|
||||
openim::log::info "Stopped services:"
|
||||
for name in "${stopped[@]}"; do
|
||||
openim::log::info "Successfully stopped the $name service."
|
||||
done
|
||||
fi
|
||||
|
||||
openim::log::success "All specified services were stopped."
|
||||
}
|
||||
# sleep 333333&
|
||||
# sleep 444444&
|
||||
# ps -ef | grep "sleep"
|
||||
# openim::util::stop_services_with_name "sleep 333333" "sleep 444444"
|
||||
|
||||
# This figures out the host platform without relying on golang. We need this as
|
||||
# we don't want a golang install to be a prerequisite to building yet we need
|
||||
# this info to figure out where the final binaries are placed.
|
||||
@@ -213,14 +547,14 @@ openim::util::find-binary() {
|
||||
openim::util::find-binary-for-platform "$1" "$(openim::util::host_platform)"
|
||||
}
|
||||
|
||||
# Run all known doc generators (today gendocs and genman for imctl)
|
||||
# Run all known doc generators (today gendocs and genman for openimctl)
|
||||
# $1 is the directory to put those generated documents
|
||||
openim::util::gen-docs() {
|
||||
local dest="$1"
|
||||
|
||||
# Find binary
|
||||
gendocs=$(openim::util::find-binary "gendocs")
|
||||
geniamdocs=$(openim::util::find-binary "geniamdocs")
|
||||
genopenimdocs=$(openim::util::find-binary "genopenimdocs")
|
||||
genman=$(openim::util::find-binary "genman")
|
||||
genyaml=$(openim::util::find-binary "genyaml")
|
||||
genfeddocs=$(openim::util::find-binary "genfeddocs")
|
||||
@@ -229,24 +563,24 @@ openim::util::gen-docs() {
|
||||
# least from k/k tree), remove it completely.
|
||||
openim::util::sourced_variable "${genfeddocs}"
|
||||
|
||||
mkdir -p "${dest}/docs/guide/en-US/cmd/imctl/"
|
||||
"${gendocs}" "${dest}/docs/guide/en-US/cmd/imctl/"
|
||||
mkdir -p "${dest}/docs/guide/en-US/cmd/openimctl/"
|
||||
"${gendocs}" "${dest}/docs/guide/en-US/cmd/openimctl/"
|
||||
|
||||
mkdir -p "${dest}/docs/guide/en-US/cmd/"
|
||||
"${geniamdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-api"
|
||||
"${geniamdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-cmdutils"
|
||||
"${geniamdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-crontask"
|
||||
"${geniamdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-msggateway"
|
||||
"${geniamdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-msgtransfer"
|
||||
"${geniamdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-push"
|
||||
"${geniamdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-rpc-auth"
|
||||
"${geniamdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-rpc-conversation"
|
||||
"${geniamdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-rpc-friend"
|
||||
"${geniamdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-rpc-group"
|
||||
"${geniamdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-rpc-msg"
|
||||
"${geniamdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-rpc-third"
|
||||
"${geniamdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-rpc-user"
|
||||
"${geniamdocs}" "${dest}/docs/guide/en-US/cmd/imctl" "imctl"
|
||||
"${genopenimdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-api"
|
||||
"${genopenimdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-cmdutils"
|
||||
"${genopenimdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-crontask"
|
||||
"${genopenimdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-msggateway"
|
||||
"${genopenimdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-msgtransfer"
|
||||
"${genopenimdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-push"
|
||||
"${genopenimdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-rpc-auth"
|
||||
"${genopenimdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-rpc-conversation"
|
||||
"${genopenimdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-rpc-friend"
|
||||
"${genopenimdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-rpc-group"
|
||||
"${genopenimdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-rpc-msg"
|
||||
"${genopenimdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-rpc-third"
|
||||
"${genopenimdocs}" "${dest}/docs/guide/en-US/cmd/" "openim-rpc-user"
|
||||
"${genopenimdocs}" "${dest}/docs/guide/en-US/cmd/openimctl" "openimctl"
|
||||
|
||||
mkdir -p "${dest}/docs/man/man1/"
|
||||
"${genman}" "${dest}/docs/man/man1/" "openim-api"
|
||||
@@ -263,8 +597,8 @@ openim::util::gen-docs() {
|
||||
"${genman}" "${dest}/docs/man/man1/" "openim-rpc-third"
|
||||
"${genman}" "${dest}/docs/man/man1/" "openim-rpc-user"
|
||||
|
||||
mkdir -p "${dest}/docs/guide/en-US/yaml/imctl/"
|
||||
"${genyaml}" "${dest}/docs/guide/en-US/yaml/imct/"
|
||||
mkdir -p "${dest}/docs/guide/en-US/yaml/openimctl/"
|
||||
"${genyaml}" "${dest}/docs/guide/en-US/yaml/openimctl/"
|
||||
|
||||
# create the list of generated files
|
||||
pushd "${dest}" > /dev/null || return 1
|
||||
@@ -290,7 +624,7 @@ openim::util::remove-gen-docs() {
|
||||
# repo, e.g. "upstream" or "origin".
|
||||
openim::util::git_upstream_remote_name() {
|
||||
git remote -v | grep fetch |\
|
||||
grep -E 'github.com[/:]marmotedu/openim|marmotedu.io/openim' |\
|
||||
grep -E 'github.com[/:]OpenIMSDK/Open-IM-Server|openim.cc/server' |\
|
||||
head -n 1 | awk '{print $1}'
|
||||
}
|
||||
|
||||
@@ -455,8 +789,8 @@ function openim::util::create_serving_certkey {
|
||||
EOF
|
||||
}
|
||||
|
||||
# creates a self-contained iamconfig: args are sudo, dest-dir, ca file, host, port, client id, token(optional)
|
||||
function openim::util::write_client_iamconfig {
|
||||
# creates a self-contained openimconfig: args are sudo, dest-dir, ca file, host, port, client id, token(optional)
|
||||
function openim::util::write_client_openimconfig {
|
||||
local sudo=$1
|
||||
local dest_dir=$2
|
||||
local ca_file=$3
|
||||
@@ -464,7 +798,7 @@ function openim::util::write_client_iamconfig {
|
||||
local api_port=$5
|
||||
local client_id=$6
|
||||
local token=${7:-}
|
||||
cat <<EOF | ${sudo} tee "${dest_dir}"/"${client_id}".iamconfig > /dev/null
|
||||
cat <<EOF | ${sudo} tee "${dest_dir}"/"${client_id}".openimconfig > /dev/null
|
||||
apiVersion: v1
|
||||
kind: Config
|
||||
clusters:
|
||||
@@ -486,12 +820,12 @@ contexts:
|
||||
current-context: local-up-cluster
|
||||
EOF
|
||||
|
||||
# flatten the iamconfig files to make them self contained
|
||||
# flatten the openimconfig files to make them self contained
|
||||
username=$(whoami)
|
||||
${sudo} /usr/bin/env bash -e <<EOF
|
||||
$(openim::util::find-binary imct) --iamconfig="${dest_dir}/${client_id}.iamconfig" config view --minify --flatten > "/tmp/${client_id}.iamconfig"
|
||||
mv -f "/tmp/${client_id}.iamconfig" "${dest_dir}/${client_id}.iamconfig"
|
||||
chown ${username} "${dest_dir}/${client_id}.iamconfig"
|
||||
$(openim::util::find-binary openimctl) --openimconfig="${dest_dir}/${client_id}.openimconfig" config view --minify --flatten > "/tmp/${client_id}.openimconfig"
|
||||
mv -f "/tmp/${client_id}.openimconfig" "${dest_dir}/${client_id}.openimconfig"
|
||||
chown ${username} "${dest_dir}/${client_id}.openimconfig"
|
||||
EOF
|
||||
}
|
||||
|
||||
@@ -545,6 +879,29 @@ function openim::util::join {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
# Function: openim::util::list-to-string <list...>
|
||||
# Description: Converts a list to a string, removing spaces, brackets, and commas.
|
||||
# Example input: [1002 3 , 2 32 3 , 3 434 ,]
|
||||
# Example output: 10023 2323 3434
|
||||
# Example usage:
|
||||
# result=$(openim::util::list-to-string "[10023, 2323, 3434]")
|
||||
# echo $result
|
||||
function openim::util::list-to-string() {
|
||||
# Capture all arguments into a single string
|
||||
ports_list="$*"
|
||||
|
||||
# Use sed for transformations:
|
||||
# 1. Remove spaces
|
||||
# 2. Replace commas with spaces
|
||||
# 3. Remove opening and closing brackets
|
||||
ports_array=$(echo "$ports_list" | sed 's/ //g; s/,/ /g; s/^\[\(.*\)\]$/\1/')
|
||||
|
||||
# For external use, we might want to echo the result so that it can be captured by callers
|
||||
echo "$ports_array"
|
||||
}
|
||||
# MSG_GATEWAY_PROM_PORTS=$(openim::util::list-to-string "10023, 2323, 34 34")
|
||||
# echo ${MSG_GATEWAY_PROM_PORTS}
|
||||
|
||||
# Downloads cfssl/cfssljson/cfssl-certinfo into $1 directory if they do not already exist in PATH
|
||||
#
|
||||
# Assumed vars:
|
||||
@@ -616,6 +973,47 @@ function openim::util::ensure-cfssl {
|
||||
popd > /dev/null || return 1
|
||||
}
|
||||
|
||||
function openim::util::ensure-docker-buildx {
|
||||
# podman returns 0 on `docker buildx version`, docker on `docker buildx`. One of them must succeed.
|
||||
if docker buildx version >/dev/null 2>&1 || docker buildx >/dev/null 2>&1; then
|
||||
return 0
|
||||
else
|
||||
echo "ERROR: docker buildx not available. Docker 19.03 or higher is required with experimental features enabled"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# openim::util::ensure-bash-version
|
||||
# Check if we are using a supported bash version
|
||||
#
|
||||
function openim::util::ensure-bash-version {
|
||||
# shellcheck disable=SC2004
|
||||
if ((${BASH_VERSINFO[0]}<4)) || ( ((${BASH_VERSINFO[0]}==4)) && ((${BASH_VERSINFO[1]}<2)) ); then
|
||||
echo "ERROR: This script requires a minimum bash version of 4.2, but got version of ${BASH_VERSINFO[0]}.${BASH_VERSINFO[1]}"
|
||||
if [ "$(uname)" = 'Darwin' ]; then
|
||||
echo "On macOS with homebrew 'brew install bash' is sufficient."
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# openim::util::ensure-install-nginx
|
||||
# Check if nginx is installed
|
||||
#
|
||||
function openim::util::ensure-install-nginx {
|
||||
if ! command -v nginx &>/dev/null; then
|
||||
echo "ERROR: nginx not found. Please install nginx."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for port in 80
|
||||
do
|
||||
if echo |telnet 127.0.0.1 $port 2>&1|grep refused &>/dev/null;then
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# openim::util::ensure-gnu-sed
|
||||
# Determines which sed binary is gnu-sed on linux/darwin
|
||||
#
|
||||
@@ -624,7 +1022,7 @@ function openim::util::ensure-cfssl {
|
||||
#
|
||||
function openim::util::ensure-gnu-sed {
|
||||
# NOTE: the echo below is a workaround to ensure sed is executed before the grep.
|
||||
# see: https://github.com/iamrnetes/iamrnetes/issues/87251
|
||||
# see: https://github.com/openimrnetes/openimrnetes/issues/87251
|
||||
sed_help="$(LANG=C sed --help 2>&1 || true)"
|
||||
if echo "${sed_help}" | grep -q "GNU\|BusyBox"; then
|
||||
SED="sed"
|
||||
@@ -637,6 +1035,26 @@ function openim::util::ensure-gnu-sed {
|
||||
openim::util::sourced_variable "${SED}"
|
||||
}
|
||||
|
||||
# openim::util::ensure-gnu-date
|
||||
# Determines which date binary is gnu-date on linux/darwin
|
||||
#
|
||||
# Sets:
|
||||
# DATE: The name of the gnu-date binary
|
||||
#
|
||||
function openim::util::ensure-gnu-date {
|
||||
# NOTE: the echo below is a workaround to ensure date is executed before the grep.
|
||||
date_help="$(LANG=C date --help 2>&1 || true)"
|
||||
if echo "${date_help}" | grep -q "GNU\|BusyBox"; then
|
||||
DATE="date"
|
||||
elif command -v gdate &>/dev/null; then
|
||||
DATE="gdate"
|
||||
else
|
||||
openim::log::error "Failed to find GNU date as date or gdate. If you are on Mac: brew install coreutils." >&2
|
||||
return 1
|
||||
fi
|
||||
openim::util::sourced_variable "${DATE}"
|
||||
}
|
||||
|
||||
# openim::util::check-file-in-alphabetical-order <file>
|
||||
# Check that the file is in alphabetical order
|
||||
#
|
||||
@@ -710,22 +1128,155 @@ fi
|
||||
|
||||
# ex: ts=2 sw=2 et filetype=sh
|
||||
|
||||
function openim::util::desc() {
|
||||
openim::util:run::maybe_first_prompt
|
||||
rate=25
|
||||
if [ -n "$DEMO_RUN_FAST" ]; then
|
||||
rate=1000
|
||||
fi
|
||||
echo "$blue# $@$reset" | pv -qL $rate
|
||||
openim::util:run::prompt
|
||||
}
|
||||
|
||||
# input: [10023, 2323, 3434]
|
||||
# output: 10023 2323 3434
|
||||
function openim::util:run::prompt() {
|
||||
echo -n "$yellow\$ $reset"
|
||||
}
|
||||
|
||||
# Function function: Converts a list to a string, removing Spaces and parentheses
|
||||
function list_to_string() {
|
||||
ports_list=$* # 获取传入的参数列表
|
||||
sub_s1=$(echo $ports_list | sed 's/ //g') # 去除空格
|
||||
sub_s2=${sub_s1//,/ } # 将逗号替换为空格
|
||||
sub_s3=${sub_s2#*[} # 去除左括号及其之前的内容
|
||||
sub_s4=${sub_s3%]*} # 去除右括号及其之后的内容
|
||||
ports_array=$sub_s4 # 将处理后的字符串赋值给变量 ports_array
|
||||
started=""
|
||||
function openim::util:run::maybe_first_prompt() {
|
||||
if [ -z "$started" ]; then
|
||||
openim::util:run::prompt
|
||||
started=true
|
||||
fi
|
||||
}
|
||||
|
||||
# After a `run` this variable will hold the stdout of the command that was run.
|
||||
# If the command was interactive, this will likely be garbage.
|
||||
DEMO_RUN_STDOUT=""
|
||||
|
||||
function openim::util::run() {
|
||||
openim::util:run::maybe_first_prompt
|
||||
rate=25
|
||||
if [ -n "$DEMO_RUN_FAST" ]; then
|
||||
rate=1000
|
||||
fi
|
||||
echo "$green$1$reset" | pv -qL $rate
|
||||
if [ -n "$DEMO_RUN_FAST" ]; then
|
||||
sleep 0.5
|
||||
fi
|
||||
OFILE="$(mktemp -t $(basename $0).XXXXXX)"
|
||||
if [ "$(uname)" == "Darwin" ]; then
|
||||
script -q "$OFILE" $1
|
||||
else
|
||||
script -eq -c "$1" -f "$OFILE"
|
||||
fi
|
||||
r=$?
|
||||
read -d '' -t "${timeout}" -n 10000 # clear stdin
|
||||
openim::util:run::prompt
|
||||
if [ -z "$DEMO_AUTO_RUN" ]; then
|
||||
read -s
|
||||
fi
|
||||
DEMO_RUN_STDOUT="$(tail -n +2 $OFILE | sed 's/\r//g')"
|
||||
return $r
|
||||
}
|
||||
|
||||
function openim::util::run::relative() {
|
||||
for arg; do
|
||||
echo "$(realpath $(dirname $(which $0)))/$arg" | sed "s|$(realpath $(pwd))|.|"
|
||||
done
|
||||
}
|
||||
|
||||
# This function retrieves the IP address of the current server.
|
||||
# It primarily uses the `curl` command to fetch the public IP address from ifconfig.me.
|
||||
# If curl or the service is not available, it falls back
|
||||
# to the internal IP address provided by the hostname command.
|
||||
# TODO: If a delay is found, the delay needs to be addressed
|
||||
function openim::util::get_server_ip() {
|
||||
# Check if the 'curl' command is available
|
||||
if command -v curl &> /dev/null; then
|
||||
# Try to retrieve the public IP address using curl and ifconfig.me
|
||||
IP=$(dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | sed 's/"//g' | tr -d '\n')
|
||||
|
||||
# Check if IP retrieval was successful
|
||||
if [[ -z "$IP" ]]; then
|
||||
# If not, get the internal IP address
|
||||
IP=$(ip addr show | grep 'inet ' | grep -v 127.0.0.1 | awk '{print $2}' | cut -d'/' -f1 | head -n 1)
|
||||
fi
|
||||
else
|
||||
# If curl is not available, get the internal IP address
|
||||
IP=$(ip addr show | grep 'inet ' | grep -v 127.0.0.1 | awk '{print $2}' | cut -d'/' -f1 | head -n 1)
|
||||
fi
|
||||
|
||||
# Return the fetched IP address
|
||||
echo "$IP"
|
||||
}
|
||||
|
||||
function openim::util::onCtrlC() {
|
||||
kill -9 "${do_sth_pid}" "${progress_pid}" "${countdown_pid}"
|
||||
echo
|
||||
echo 'Ctrl+C is captured'
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Function Function: Remove Spaces in the string
|
||||
function remove_space() {
|
||||
function openim::util::remove_space() {
|
||||
value=$* # 获取传入的参数
|
||||
result=$(echo $value | sed 's/ //g') # 去除空格
|
||||
}
|
||||
|
||||
function openim::util::gencpu() {
|
||||
# Check the system type
|
||||
system_type=$(uname)
|
||||
|
||||
if [[ "$system_type" == "Darwin" ]]; then
|
||||
# macOS (using sysctl)
|
||||
cpu_count=$(sysctl -n hw.ncpu)
|
||||
elif [[ "$system_type" == "Linux" ]]; then
|
||||
# Linux (using lscpu)
|
||||
cpu_count=$(lscpu --parse | grep -E '^([^#].*,){3}[^#]' | sort -u | wc -l)
|
||||
else
|
||||
echo "Unsupported operating system: $system_type"
|
||||
exit 1
|
||||
fi
|
||||
echo $cpu_count
|
||||
}
|
||||
|
||||
function openim::util::gen_os_arch() {
|
||||
# Get the current operating system and architecture
|
||||
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
|
||||
ARCH=$(uname -m)
|
||||
|
||||
# Select the repository home directory based on the operating system and architecture
|
||||
if [[ "$OS" == "darwin" ]]; then
|
||||
if [[ "$ARCH" == "x86_64" ]]; then
|
||||
REPO_DIR="darwin/amd64"
|
||||
else
|
||||
REPO_DIR="darwin/386"
|
||||
fi
|
||||
elif [[ "$OS" == "linux" ]]; then
|
||||
if [[ "$ARCH" == "x86_64" ]]; then
|
||||
REPO_DIR="linux/amd64"
|
||||
elif [[ "$ARCH" == "arm64" ]]; then
|
||||
REPO_DIR="linux/arm64"
|
||||
elif [[ "$ARCH" == "mips64" ]]; then
|
||||
REPO_DIR="linux/mips64"
|
||||
elif [[ "$ARCH" == "mips64le" ]]; then
|
||||
REPO_DIR="linux/mips64le"
|
||||
elif [[ "$ARCH" == "ppc64le" ]]; then
|
||||
REPO_DIR="linux/ppc64le"
|
||||
elif [[ "$ARCH" == "s390x" ]]; then
|
||||
REPO_DIR="linux/s390x"
|
||||
else
|
||||
REPO_DIR="linux/386"
|
||||
fi
|
||||
elif [[ "$OS" == "windows" ]]; then
|
||||
if [[ "$ARCH" == "x86_64" ]]; then
|
||||
REPO_DIR="windows/amd64"
|
||||
else
|
||||
REPO_DIR="windows/386"
|
||||
fi
|
||||
else
|
||||
echo -e "${RED_PREFIX}Unsupported OS: $OS${COLOR_SUFFIX}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
# 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.
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Version management helpers. These functions help to set, save and load the
|
||||
|
||||
@@ -13,17 +13,14 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
#input:[10023,2323,3434]
|
||||
#output:10023 2323 3434
|
||||
list_to_string(){
|
||||
ports_list=$*
|
||||
sub_s1=`echo $ports_list | sed 's/ //g'`
|
||||
sub_s2=${sub_s1//,/ }
|
||||
sub_s3=${sub_s2#*[}
|
||||
sub_s4=${sub_s3%]*}
|
||||
ports_array=$sub_s4
|
||||
}
|
||||
remove_space(){
|
||||
value=$*
|
||||
result=`echo $value | sed 's/ //g'`
|
||||
}
|
||||
|
||||
# This script lists all of the [Feature:.+] tests in our e2e suite.
|
||||
#
|
||||
# Usage: `scripts/list-feature-tests.sh`.
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
grep "\[Feature:\w+\]" "${OPENIM_ROOT}"/test/e2e/**/*.go -Eoh | LC_ALL=C sort -u
|
||||
@@ -48,10 +48,16 @@ endif
|
||||
|
||||
# BIN_TOOLS_DIR: Directory where executable files are stored.
|
||||
ifeq ($(origin BIN_TOOLS_DIR),undefined)
|
||||
BIN_TOOLS_DIR := $(OUTPUT_DIR)/bin-tools
|
||||
BIN_TOOLS_DIR := $(BIN_DIR)/tools
|
||||
$(shell mkdir -p $(BIN_TOOLS_DIR))
|
||||
endif
|
||||
|
||||
# LOGS_DIR: Directory where log files are stored.
|
||||
ifeq ($(origin LOGS_DIR),undefined)
|
||||
LOGS_DIR := $(OUTPUT_DIR)/logs
|
||||
$(shell mkdir -p $(LOGS_DIR))
|
||||
endif
|
||||
|
||||
# TOOLS_DIR: The directory where tools are stored for build and testing.
|
||||
ifeq ($(origin TOOLS_DIR),undefined)
|
||||
TOOLS_DIR := $(OUTPUT_DIR)/tools
|
||||
@@ -65,7 +71,7 @@ $(shell mkdir -p $(TMP_DIR))
|
||||
endif
|
||||
|
||||
ifeq ($(origin VERSION), undefined)
|
||||
# VERSION := $(shell git describe --abbrev=0 --dirty --always --tags | sed 's/-/./g') #v2.3.3.dirty
|
||||
# VERSION := $(shell git describe --tags --always --match='v*')
|
||||
# git describe --tags --always --match="v*" --dirty
|
||||
VERSION := $(shell git describe --tags --always --match="v*" --dirty | sed 's/-/./g') #v2.3.3.631.g00abdc9b.dirty
|
||||
# v2.3.3: git tag
|
||||
@@ -94,7 +100,7 @@ endif
|
||||
# The OS must be linux when building docker images
|
||||
# PLATFORMS ?= linux_amd64 linux_arm64
|
||||
# The OS can be linux/windows/darwin when building binaries
|
||||
PLATFORMS ?= linux_s390x linux_mips64 linux_mips64le darwin_amd64 windows_amd64 linux_amd64 linux_arm64 linux_ppc64le
|
||||
PLATFORMS ?= linux_s390x linux_mips64 linux_mips64le darwin_amd64 windows_amd64 linux_amd64 linux_arm64 linux_ppc64le # wasip1_wasm
|
||||
|
||||
# only support linux
|
||||
GOOS=linux
|
||||
@@ -126,7 +132,7 @@ FIND := find . ! -path './utils/*' ! -path './vendor/*' ! -path './third_party/*
|
||||
XARGS := xargs -r --no-run-if-empty
|
||||
|
||||
# Linux command settings-CODE DIRS Copyright
|
||||
CODE_DIRS := $(ROOT_DIR)/pkg $(ROOT_DIR)/cmd $(ROOT_DIR)/config $(ROOT_DIR)/db $(ROOT_DIR)/.docker-compose_cfg $(ROOT_DIR)/internal $(ROOT_DIR)/scripts $(ROOT_DIR)/test $(ROOT_DIR)/.github $(ROOT_DIR)/build $(ROOT_DIR)/build $(ROOT_DIR)/deployments
|
||||
CODE_DIRS := $(ROOT_DIR)/pkg $(ROOT_DIR)/cmd $(ROOT_DIR)/config $(ROOT_DIR)/.docker-compose_cfg $(ROOT_DIR)/internal $(ROOT_DIR)/scripts $(ROOT_DIR)/test $(ROOT_DIR)/.github $(ROOT_DIR)/build $(ROOT_DIR)/tools $(ROOT_DIR)/deployments
|
||||
FINDS := find $(CODE_DIRS)
|
||||
|
||||
# Makefile settings: Select different behaviors by determining whether V option is set
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
# Makefile helper functions for copyright
|
||||
#
|
||||
|
||||
LICENSE_TEMPLATE ?= $(ROOT_DIR)/scripts/LICENSE/LICENSE_TEMPLATES
|
||||
LICENSE_TEMPLATE ?= $(ROOT_DIR)/scripts/template/LICENSE_TEMPLATES
|
||||
|
||||
## copyright.verify: Validate boilerplate headers for assign files
|
||||
.PHONY: copyright.verify
|
||||
|
||||
@@ -22,38 +22,52 @@
|
||||
# Makefile helper functions for generate necessary files
|
||||
#
|
||||
|
||||
## gen.init: Initialize openim server project ✨
|
||||
.PHONY: gen.init
|
||||
gen.init:
|
||||
@echo "===========> Initializing openim server project"
|
||||
@${ROOT_DIR}/scripts/init-config.sh
|
||||
|
||||
## gen.run: Generate necessary files and docs ✨
|
||||
.PHONY: gen.run
|
||||
#gen.run: gen.errcode gen.docgo
|
||||
gen.run: gen.clean gen.errcode gen.docgo.doc
|
||||
|
||||
## gen.errcode: Generate necessary files and docs ✨
|
||||
.PHONY: gen.errcode
|
||||
gen.errcode: gen.errcode.code gen.errcode.doc
|
||||
|
||||
## gen.errcode.code: Generate openim error code go source files ✨
|
||||
.PHONY: gen.errcode.code
|
||||
gen.errcode.code: tools.verify.codegen
|
||||
@echo "===========> Generating openim error code go source files"
|
||||
@codegen -type=int ${ROOT_DIR}/internal/pkg/code
|
||||
|
||||
## gen.errcode.doc: Generate openim error code markdown documentation ✨
|
||||
.PHONY: gen.errcode.doc
|
||||
gen.errcode.doc: tools.verify.codegen
|
||||
@echo "===========> Generating error code markdown documentation"
|
||||
@codegen -type=int -doc \
|
||||
-output ${ROOT_DIR}/docs/guide/zh-CN/api/error_code_generated.md ${ROOT_DIR}/internal/pkg/code
|
||||
|
||||
## gen.docgo: Generate missing doc.go for go packages ✨
|
||||
.PHONY: gen.ca.%
|
||||
gen.ca.%:
|
||||
$(eval CA := $(word 1,$(subst ., ,$*)))
|
||||
@echo "===========> Generating CA files for $(CA)"
|
||||
@${ROOT_DIR}/scripts/gencerts.sh generate-openim-cert $(OUTPUT_DIR)/cert $(CA)
|
||||
|
||||
## gen.ca: Generate CA files for all certificates ✨
|
||||
.PHONY: gen.ca
|
||||
gen.ca: $(addprefix gen.ca., $(CERTIFICATES))
|
||||
|
||||
## gen.docgo: Generate missing doc.go for go packages ✨
|
||||
.PHONY: gen.docgo.doc
|
||||
gen.docgo.doc:
|
||||
@echo "===========> Generating missing doc.go for go packages"
|
||||
@${ROOT_DIR}/scripts/gendoc.sh
|
||||
|
||||
## gen.docgo.check: Check if there are untracked doc.go files ✨
|
||||
.PHONY: gen.docgo.check
|
||||
gen.docgo.check: gen.docgo.doc
|
||||
@n="$$(git ls-files --others '*/doc.go' | wc -l)"; \
|
||||
@@ -63,14 +77,17 @@ gen.docgo.check: gen.docgo.doc
|
||||
false ; \
|
||||
fi
|
||||
|
||||
## gen.docgo.add: Add untracked doc.go files to git index ✨
|
||||
.PHONY: gen.docgo.add
|
||||
gen.docgo.add:
|
||||
@git ls-files --others '*/doc.go' | $(XARGS) -- git add
|
||||
|
||||
## gen.docgo: Generate missing doc.go for go packages ✨
|
||||
.PHONY: gen.defaultconfigs
|
||||
gen.defaultconfigs:
|
||||
@${ROOT_DIR}/scripts/gen_default_config.sh
|
||||
|
||||
## gen.docgo: Generate missing doc.go for go packages ✨
|
||||
.PHONY: gen.clean
|
||||
gen.clean:
|
||||
@rm -rf ./api/client/{clientset,informers,listers}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#
|
||||
|
||||
GO := go
|
||||
GO_SUPPORTED_VERSIONS ?= 1.18|1.19|1.20
|
||||
GO_SUPPORTED_VERSIONS ?= 1.18|1.19|1.20|1.21
|
||||
|
||||
GO_LDFLAGS += -X $(VERSION_PACKAGE).gitVersion=$(GIT_TAG) \
|
||||
-X $(VERSION_PACKAGE).gitCommit=$(GIT_COMMIT) \
|
||||
@@ -45,7 +45,7 @@ ifeq ($(origin GOBIN), undefined)
|
||||
endif
|
||||
|
||||
# COMMANDS is Specify all files under ${ROOT_DIR}/cmd/ and ${ROOT_DIR}/tools/ except those ending in.md
|
||||
COMMANDS ?= $(filter-out %.md, $(wildcard ${ROOT_DIR}/cmd/* ${ROOT_DIR}/tools/*))
|
||||
COMMANDS ?= $(filter-out %.md, $(wildcard ${ROOT_DIR}/cmd/* ${ROOT_DIR}/tools/* ${ROOT_DIR}/cmd/openim-rpc/*))
|
||||
ifeq (${COMMANDS},)
|
||||
$(error Could not determine COMMANDS, set ROOT_DIR or run in source dir)
|
||||
endif
|
||||
@@ -101,6 +101,24 @@ EXCLUDE_TESTS=github.com/OpenIMSDK/Open-IM-Server/test github.com/OpenIMSDK/Open
|
||||
go.build: go.build.verify $(addprefix go.build., $(addprefix $(PLATFORM)., $(BINS)))
|
||||
@echo "===========> Building binary $(BINS) $(VERSION) for $(PLATFORM)"
|
||||
|
||||
## go.start: Start openim
|
||||
.PHONY: go.start
|
||||
go.start:
|
||||
@echo "===========> Starting openim"
|
||||
@$(ROOT_DIR)/scripts/start-all.sh
|
||||
|
||||
## go.stop: Stop openim
|
||||
.PHONY: go.stop
|
||||
go.stop:
|
||||
@echo "===========> Stopping openim"
|
||||
@$(ROOT_DIR)/scripts/stop-all.sh
|
||||
|
||||
## go.check: Check openim
|
||||
.PHONY: go.check
|
||||
go.check:
|
||||
@echo "===========> Checking openim"
|
||||
@$(ROOT_DIR)/scripts/check-all.sh
|
||||
|
||||
## go.build.verify: Verify that a suitable version of Go exists
|
||||
.PHONY: go.build.verify
|
||||
go.build.verify:
|
||||
@@ -116,23 +134,21 @@ go.build.%:
|
||||
$(eval ARCH := $(word 2,$(subst _, ,$(PLATFORM))))
|
||||
@echo "=====> COMMAND=$(COMMAND)"
|
||||
@echo "=====> PLATFORM=$(PLATFORM)"
|
||||
@echo "=====> BIN_DIR=$(BIN_DIR)"
|
||||
@echo "===========> Building binary $(COMMAND) $(VERSION) for $(OS)_$(ARCH)"
|
||||
@mkdir -p $(BIN_DIR)/platforms/$(OS)/$(ARCH)
|
||||
@if [ "$(COMMAND)" == "openim-sdk-core" ]; then \
|
||||
echo "===========> DEBUG: OpenIM-SDK-Core It is no longer supported for openim-server $(COMMAND)"; \
|
||||
elif [ "$(COMMAND)" == "openim-rpc" ]; then \
|
||||
for d in $(wildcard $(ROOT_DIR)/cmd/openim-rpc/*); do \
|
||||
cd $${d} && CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o \
|
||||
$(BIN_DIR)/platforms/$(OS)/$(ARCH)/$$(basename $${d})$(GO_OUT_EXT) $${d}/main.go; \
|
||||
done; \
|
||||
elif [ -d $(ROOT_DIR)/cmd/openim-rpc/$(COMMAND) ]; then \
|
||||
CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o \
|
||||
$(BIN_DIR)/platforms/$(OS)/$(ARCH)/$(COMMAND)$(GO_OUT_EXT) $(ROOT_DIR)/cmd/openim-rpc/$(COMMAND)/main.go; \
|
||||
else \
|
||||
if [ -f $(ROOT_DIR)/cmd/$(COMMAND)/main.go ]; then \
|
||||
CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o \
|
||||
$(BIN_DIR)/platforms/$(OS)/$(ARCH)/$(COMMAND)$(GO_OUT_EXT) $(ROOT_DIR)/cmd/$(COMMAND)/main.go; \
|
||||
elif [ -f $(ROOT_DIR)/tools/$(COMMAND)/main.go ]; then \
|
||||
elif [ -f $(ROOT_DIR)/tools/$(COMMAND)/$(COMMAND).go ]; then \
|
||||
CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o \
|
||||
$(BIN_TOOLS_DIR)/platforms/$(OS)/$(ARCH)/$(COMMAND)$(GO_OUT_EXT) $(ROOT_DIR)/tools/$(COMMAND)/main.go; \
|
||||
$(BIN_TOOLS_DIR)/$(OS)/$(ARCH)/$(COMMAND)$(GO_OUT_EXT) $(ROOT_DIR)/tools/$(COMMAND)/$(COMMAND).go; \
|
||||
chmod +x $(BIN_TOOLS_DIR)/$(OS)/$(ARCH)/$(COMMAND)$(GO_OUT_EXT); \
|
||||
fi \
|
||||
fi
|
||||
|
||||
@@ -140,13 +156,7 @@ go.build.%:
|
||||
.PHONY: go.install
|
||||
go.install:
|
||||
@echo "===========> Installing deployment openim"
|
||||
@$(ROOT_DIR)/scripts/install_im_server.sh
|
||||
|
||||
## go.check: Check OpenIM deployment
|
||||
.PHONY: go.check
|
||||
go.check:
|
||||
@echo "===========> Checking OpenIM deployment"
|
||||
@$(ROOT_DIR)/scripts/check_all.sh
|
||||
@$(ROOT_DIR)/scripts/install-im-server.sh
|
||||
|
||||
## go.multiarch: Build multi-arch binaries
|
||||
.PHONY: go.build.multiarch
|
||||
@@ -156,13 +166,19 @@ go.build.multiarch: go.build.verify $(foreach p,$(PLATFORMS),$(addprefix go.buil
|
||||
.PHONY: go.lint
|
||||
go.lint: tools.verify.golangci-lint
|
||||
@echo "===========> Run golangci to lint source codes"
|
||||
@$(TOOLS_DIR)/golangci-lint run --color always -c $(ROOT_DIR)/.golangci.yml $(ROOT_DIR)/...
|
||||
@$(TOOLS_DIR)/golangci-lint run --color always -c $(ROOT_DIR)/scripts/golangci.yml $(ROOT_DIR)/...
|
||||
|
||||
## go.test: Run unit test
|
||||
.PHONY: go.test
|
||||
go.test:
|
||||
@$(GO) test ./...
|
||||
|
||||
## go.demo: Run demo
|
||||
.PHONY: go.demo
|
||||
go.demo:
|
||||
@echo "===========> Run demo"
|
||||
@$(ROOT_DIR)/scripts/demo.sh
|
||||
|
||||
## go.test.junit-report: Run unit test
|
||||
.PHONY: go.test.junit-report
|
||||
go.test.junit-report: tools.verify.go-junit-report
|
||||
@@ -189,11 +205,23 @@ go.format: tools.verify.golines tools.verify.goimports
|
||||
@$(FIND) -type f -name '*.go' -not -name '*pb*' | $(XARGS) $(TOOLS_DIR)/golines -w --max-len=200 --reformat-tags --shorten-comments --ignore-generated .
|
||||
@$(GO) mod edit -fmt
|
||||
|
||||
## imports: task to automatically handle import packages in Go files using goimports tool
|
||||
## go.imports: task to automatically handle import packages in Go files using goimports tool
|
||||
.PHONY: go.imports
|
||||
go.imports: tools.verify.goimports
|
||||
@$(TOOLS_DIR)/goimports -l -w $(SRC)
|
||||
|
||||
## go.verify: execute all verity scripts.
|
||||
.PHONY: go.verify
|
||||
go.verify:
|
||||
@echo "Starting verification..."
|
||||
@scripts_list=$$(find $(ROOT_DIR)/scripts -type f -name 'verify-*' | sort); \
|
||||
for script in $$scripts_list; do \
|
||||
echo "Executing $$script..."; \
|
||||
$$script || exit 1; \
|
||||
echo "$$script completed successfully"; \
|
||||
done
|
||||
@echo "All verification scripts executed successfully."
|
||||
|
||||
## go.updates: Check for updates to go.mod dependencies
|
||||
.PHONY: go.updates
|
||||
go.updates: tools.verify.go-mod-outdated
|
||||
@@ -202,11 +230,11 @@ go.updates: tools.verify.go-mod-outdated
|
||||
## go.clean: Clean all builds directories and files
|
||||
.PHONY: go.clean
|
||||
go.clean:
|
||||
@echo "===========> Cleaning all builds TMP_DIR($(TMP_DIR)) AND BIN_DIR($(BIN_DIR)) AND BIN_TOOLS_DIR($(BIN_TOOLS_DIR))"
|
||||
@-rm -vrf $(TMP_DIR) $(BIN_DIR) $(BIN_TOOLS_DIR)
|
||||
@echo "===========> Cleaning all builds tmp, bin, logs directories and files"
|
||||
@-rm -vrf $(TMP_DIR) $(BIN_DIR) $(BIN_TOOLS_DIR) $(LOGS_DIR)
|
||||
@echo "===========> End clean..."
|
||||
|
||||
## copyright.help: Show copyright help
|
||||
## go.help: Show go tools help
|
||||
.PHONY: go.help
|
||||
go.help: scripts/make-rules/golang.mk
|
||||
$(call smallhelp)
|
||||
|
||||
+25
-22
@@ -14,7 +14,6 @@
|
||||
|
||||
# ==============================================================================
|
||||
# Makefile helper functions for docker image
|
||||
# TODO: For the time being only used for compilation, it can be arm or amd, please do not delete it, it can be extended with new functions
|
||||
# ==============================================================================
|
||||
# Path: scripts/make-rules/image.mk
|
||||
# docker registry: registry.example.com/namespace/image:tag as: registry.hub.docker.com/cubxxw/<image-name>:<tag>
|
||||
@@ -24,8 +23,11 @@
|
||||
DOCKER := docker
|
||||
DOCKER_SUPPORTED_API_VERSION ?= 1.32|1.40|1.41
|
||||
|
||||
REGISTRY_PREFIX ?= ghcr.io/OpenIMSDK
|
||||
IMAGES ?= lvscare
|
||||
# read: https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/images.md
|
||||
REGISTRY_PREFIX ?= ghcr.io/openimsdk
|
||||
|
||||
BASE_IMAGE ?= ghcr.io/openim-sigs/openim-bash-image
|
||||
|
||||
IMAGE_PLAT ?= $(subst $(SPACE),$(COMMA),$(subst _,/,$(PLATFORMS)))
|
||||
|
||||
EXTRA_ARGS ?= --no-cache
|
||||
@@ -39,8 +41,8 @@ ifneq ($(EXTRA_ARGS), )
|
||||
_DOCKER_BUILD_EXTRA_ARGS += $(EXTRA_ARGS)
|
||||
endif
|
||||
|
||||
# Determine image files by looking into build/docker/*/Dockerfile
|
||||
IMAGES_DIR ?= $(wildcard ${ROOT_DIR}/build/docker/*)
|
||||
# Determine image files by looking into build/images/*/Dockerfile
|
||||
IMAGES_DIR ?= $(wildcard ${ROOT_DIR}/build/images/*)
|
||||
# Determine images names by stripping out the dir names
|
||||
IMAGES ?= $(filter-out tools,$(foreach image,${IMAGES_DIR},$(notdir ${image})))
|
||||
|
||||
@@ -58,11 +60,11 @@ endif
|
||||
# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
|
||||
# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
|
||||
# To properly provided solutions that supports more than one platform you should use this option.
|
||||
## Build and push docker image for the manager for cross-platform support
|
||||
## image.docker-buildx: Build and push docker image for the manager for cross-platform support
|
||||
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
|
||||
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
|
||||
.PHONY: docker-buildx
|
||||
docker-buildx:
|
||||
.PHONY: image.docker-buildx
|
||||
image.docker-buildx:
|
||||
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
|
||||
- $(CONTAINER_TOOL) buildx create --name project-v3-builder
|
||||
$(CONTAINER_TOOL) buildx use project-v3-builder
|
||||
@@ -102,25 +104,26 @@ image.build.multiarch: image.verify $(foreach p,$(PLATFORMS),$(addprefix image.b
|
||||
|
||||
## image.build.%: Build docker image for a specific platform
|
||||
.PHONY: image.build.%
|
||||
image.build.%: go.bin.%
|
||||
image.build.%: go.build.%
|
||||
$(eval IMAGE := $(COMMAND))
|
||||
$(eval IMAGE_PLAT := $(subst _,/,$(PLATFORM)))
|
||||
$(eval ARCH := $(word 2,$(subst _, ,$(PLATFORM))))
|
||||
@echo "===========> Building LOCAL docker image $(IMAGE) $(VERSION) for $(IMAGE_PLAT)"
|
||||
@echo "===========> Building docker image $(IMAGE) $(VERSION) for $(IMAGE_PLAT)"
|
||||
@mkdir -p $(TMP_DIR)/$(IMAGE)/$(PLATFORM)
|
||||
@cat $(ROOT_DIR)/docker/$(IMAGE)/Dockerfile\
|
||||
>$(TMP_DIR)/$(IMAGE)/Dockerfile
|
||||
@cp $(BIN_DIR)/$(PLATFORM)/$(IMAGE) $(TMP_DIR)/$(IMAGE)/$(PLATFORM)
|
||||
|
||||
$(eval BUILD_SUFFIX := --load --pull -t $(REGISTRY_PREFIX)/$(IMAGE):$(VERSION) $(TMP_DIR)/$(IMAGE))
|
||||
$(eval BUILD_SUFFIX_ARM := --load --pull -t $(REGISTRY_PREFIX)/$(IMAGE).$(ARCH):$(VERSION) $(TMP_DIR)/$(IMAGE))
|
||||
@if [ "$(ARCH)" == "amd64" ]; then \
|
||||
echo "===========> Creating LOCAL docker image tag $(REGISTRY_PREFIX)/$(IMAGE):$(VERSION) for $(ARCH)"; \
|
||||
$(DOCKER) buildx build --platform $(IMAGE_PLAT) $(BUILD_SUFFIX); \
|
||||
@awk '/FROM/ {c++; if (c==2) {print; next}} c>=2' $(ROOT_DIR)/build/images/$(IMAGE)/Dockerfile \
|
||||
| sed -e "s#BASE_IMAGE#$(BASE_IMAGE)#g" \
|
||||
-e 's/--from=builder //g' \
|
||||
-e 's#COPY /openim/openim-server/#COPY ./#g' > $(TMP_DIR)/$(IMAGE)/Dockerfile
|
||||
@cp $(BIN_DIR)/platforms/$(IMAGE_PLAT)/$(IMAGE) $(TMP_DIR)/$(IMAGE)
|
||||
$(eval BUILD_SUFFIX := $(_DOCKER_BUILD_EXTRA_ARGS) --pull -t $(REGISTRY_PREFIX)/$(IMAGE)-$(ARCH):$(VERSION) $(TMP_DIR)/$(IMAGE))
|
||||
@if [ $(shell $(GO) env GOARCH) != $(ARCH) ] ; then \
|
||||
$(MAKE) image.daemon.verify ;\
|
||||
$(DOCKER) build --platform $(IMAGE_PLAT) $(BUILD_SUFFIX) ; \
|
||||
else \
|
||||
echo "===========> Creating LOCAL docker image tag $(REGISTRY_PREFIX)/$(IMAGE).$(ARCH):$(VERSION) for $(ARCH)"; \
|
||||
$(DOCKER) buildx build --platform $(IMAGE_PLAT) $(BUILD_SUFFIX_ARM); \
|
||||
$(DOCKER) build $(BUILD_SUFFIX) ; \
|
||||
fi
|
||||
@rm -rf $(TMP_DIR)/$(IMAGE)
|
||||
|
||||
|
||||
# https://docs.docker.com/build/building/multi-platform/
|
||||
# busybox image supports amd64, arm32v5, arm32v6, arm32v7, arm64v8, i386, ppc64le, and s390x
|
||||
@@ -179,7 +182,7 @@ image.manifest.push.multiarch: image.push.multiarch $(addprefix image.manifest.p
|
||||
.PHONY: image.manifest.push.multiarch.%
|
||||
image.manifest.push.multiarch.%:
|
||||
@echo "===========> Pushing manifest $* $(VERSION) to $(REGISTRY_PREFIX) and then remove the local manifest list"
|
||||
REGISTRY_PREFIX=$(REGISTRY_PREFIX) PLATFROMS="$(PLATFORMS)" IMAGE=$* VERSION=$(VERSION) DOCKER_CLI_EXPERIMENTAL=enabled \
|
||||
REGISTRY_PREFIX=$(REGISTRY_PREFIX) PLATFORMS="$(PLATFORMS)" IMAGE=$* VERSION=$(VERSION) DOCKER_CLI_EXPERIMENTAL=enabled \
|
||||
$(ROOT_DIR)/build/lib/create-manifest.sh
|
||||
|
||||
## image.help: Print help for image targets
|
||||
|
||||
@@ -1,82 +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.
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
source $SCRIPTS_ROOT/style_info.sh
|
||||
source $SCRIPTS_ROOT/path_info.sh
|
||||
source $SCRIPTS_ROOT/function.sh
|
||||
|
||||
cd $SCRIPTS_ROOT
|
||||
|
||||
echo -e "${YELLOW_PREFIX}=======>SCRIPTS_ROOT=$SCRIPTS_ROOT${COLOR_SUFFIX}"
|
||||
echo -e "${YELLOW_PREFIX}=======>OPENIM_ROOT=$OPENIM_ROOT${COLOR_SUFFIX}"
|
||||
echo -e "${YELLOW_PREFIX}=======>pwd=$PWD${COLOR_SUFFIX}"
|
||||
|
||||
bin_dir="$BIN_DIR"
|
||||
logs_dir="$OPENIM_ROOT/logs"
|
||||
|
||||
ulimit -n 200000
|
||||
|
||||
list1=$(cat $config_path | grep openImMessageGatewayPort | awk -F '[:]' '{print $NF}')
|
||||
list2=$(cat $config_path | grep openImWsPort | awk -F '[:]' '{print $NF}')
|
||||
list3=$(cat $config_path | grep messageGatewayPrometheusPort | awk -F '[:]' '{print $NF}')
|
||||
list_to_string $list1
|
||||
rpc_ports=($ports_array)
|
||||
list_to_string $list2
|
||||
ws_ports=($ports_array)
|
||||
list_to_string $list3
|
||||
prome_ports=($ports_array)
|
||||
if [ ${#rpc_ports[@]} -ne ${#ws_ports[@]} ]; then
|
||||
|
||||
echo -e ${RED_PREFIX}"ws_ports does not match push_rpc_ports or prome_ports in quantity!!!"${COLOR_SUFFIX}
|
||||
exit -1
|
||||
|
||||
fi
|
||||
#Check if the service exists
|
||||
#If it is exists,kill this process
|
||||
#check=$(ps aux | grep -w ./${openim_msggateway} | grep -v grep | wc -l)
|
||||
#if [ $check -ge 1 ]; then
|
||||
# oldPid=$(ps aux | grep -w ./${openim_msggateway} | grep -v grep | awk '{print $2}')
|
||||
# kill -9 ${oldPid}
|
||||
#fi
|
||||
#Waiting port recycling
|
||||
sleep 1
|
||||
cd ${msg_gateway_binary_root}
|
||||
for ((i = 0; i < ${#ws_ports[@]}; i++)); do
|
||||
echo "==========================start msg_gateway server===========================">>$OPENIM_ROOT/logs/openIM.log
|
||||
nohup ./${openim_msggateway} --port ${rpc_ports[$i]} --ws_port ${ws_ports[$i]} --prometheus_port ${prome_ports[$i]} --config_folder_path ${configfile_path} >>$OPENIM_ROOT/logs/openIM.log 2>&1 &
|
||||
done
|
||||
|
||||
#Check launched service process
|
||||
sleep 3
|
||||
check=$(ps aux | grep -w ./${openim_msggateway} | grep -v grep | wc -l)
|
||||
allPorts=""
|
||||
if [ $check -ge 1 ]; then
|
||||
allNewPid=$(ps aux | grep -w ./${openim_msggateway} | grep -v grep | awk '{print $2}')
|
||||
for i in $allNewPid; do
|
||||
ports=$(netstat -netulp | grep -w ${i} | awk '{print $4}' | awk -F '[:]' '{print $NF}')
|
||||
allPorts=${allPorts}"$ports "
|
||||
done
|
||||
echo -e ${SKY_BLUE_PREFIX}"SERVICE START SUCCESS"${COLOR_SUFFIX}
|
||||
echo -e ${SKY_BLUE_PREFIX}"SERVICE_NAME: "${COLOR_SUFFIX}${BACKGROUND_GREEN}${openim_msggateway}${COLOR_SUFFIX}
|
||||
echo -e ${SKY_BLUE_PREFIX}"PID: "${COLOR_SUFFIX}${BACKGROUND_GREEN}${allNewPid}${COLOR_SUFFIX}
|
||||
echo -e ${SKY_BLUE_PREFIX}"LISTENING_PORT: "${COLOR_SUFFIX}${BACKGROUND_GREEN}${allPorts}${COLOR_SUFFIX}
|
||||
else
|
||||
exit -1
|
||||
fi
|
||||
@@ -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.
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
source $SCRIPTS_ROOT/style_info.sh
|
||||
source $SCRIPTS_ROOT/path_info.sh
|
||||
source $SCRIPTS_ROOT/function.sh
|
||||
|
||||
echo -e "${YELLOW_PREFIX}=======>SCRIPTS_ROOT=$SCRIPTS_ROOT${COLOR_SUFFIX}"
|
||||
echo -e "${YELLOW_PREFIX}=======>OPENIM_ROOT=$OPENIM_ROOT${COLOR_SUFFIX}"
|
||||
echo -e "${YELLOW_PREFIX}=======>pwd=$PWD${COLOR_SUFFIX}"
|
||||
|
||||
bin_dir="$BIN_DIR"
|
||||
logs_dir="$OPENIM_ROOT/logs"
|
||||
|
||||
cd $OPENIM_ROOT
|
||||
|
||||
list1=$(cat $config_path | grep messageTransferPrometheusPort | awk -F '[:]' '{print $NF}')
|
||||
list_to_string $list1
|
||||
prome_ports=($ports_array)
|
||||
|
||||
#Check if the service exists
|
||||
#If it is exists,kill this process
|
||||
#check=`ps | grep -w ./${openim_msgtransfer} | grep -v grep| wc -l`
|
||||
#if [ $check -ge 1 ]
|
||||
#then
|
||||
#oldPid=`ps | grep -w ./${openim_msgtransfer} | grep -v grep|awk '{print $2}'`
|
||||
# kill -9 $oldPid
|
||||
#fi
|
||||
#Waiting port recycling
|
||||
sleep 1
|
||||
|
||||
cd ${msg_transfer_binary_root}
|
||||
for ((i = 0; i < ${msg_transfer_service_num}; i++)); do
|
||||
prome_port=${prome_ports[$i]}
|
||||
cmd="nohup ./${openim_msgtransfer} --config_folder_path ${configfile_path} "
|
||||
if [ $prome_port != "" ]; then
|
||||
cmd="$cmd --prometheus_port $prome_port --config_folder_path ${configfile_path} "
|
||||
fi
|
||||
echo "==========================start msg_transfer server===========================">>$OPENIM_ROOT/logs/openIM.log
|
||||
$cmd >>$OPENIM_ROOT/logs/openIM.log 2>&1 &
|
||||
done
|
||||
|
||||
#Check launched service process
|
||||
check=`ps -axu| grep -w ./${openim_msgtransfer} | grep -v grep| wc -l`
|
||||
if [ $check -ge 1 ]
|
||||
then
|
||||
newPid=`ps -axu| grep -w ./${openim_msgtransfer} | grep -v grep|awk '{print $2}'`
|
||||
allPorts=""
|
||||
echo -e ${SKY_BLUE_PREFIX}"SERVICE START SUCCESS "${COLOR_SUFFIX}
|
||||
echo -e ${SKY_BLUE_PREFIX}"SERVICE_NAME: "${COLOR_SUFFIX}${BACKGROUND_GREEN}${openim_msgtransfer}${COLOR_SUFFIX}
|
||||
echo -e ${SKY_BLUE_PREFIX}"PID: "${COLOR_SUFFIX}${BACKGROUND_GREEN}${newPid}${COLOR_SUFFIX}
|
||||
echo -e ${SKY_BLUE_PREFIX}"LISTENING_PORT: "${COLOR_SUFFIX}${BACKGROUND_GREEN}${allPorts}${COLOR_SUFFIX}
|
||||
else
|
||||
exit -1
|
||||
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.
|
||||
|
||||
# Determine the architecture and version
|
||||
architecture=$(uname -m)
|
||||
version=$(uname -s | tr '[:upper:]' '[:lower:]')
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
source $SCRIPTS_ROOT/style_info.sh
|
||||
|
||||
cd $SCRIPTS_ROOT
|
||||
|
||||
# Define the supported architectures and corresponding bin directories
|
||||
declare -A supported_architectures=(
|
||||
["linux-amd64"]="_output/bin/platforms/linux/amd64"
|
||||
["linux-arm64"]="_output/bin/platforms/linux/arm64"
|
||||
["linux-mips64"]="_output/bin/platforms/linux/mips64"
|
||||
["linux-mips64le"]="_output/bin/platforms/linux/mips64le"
|
||||
["linux-ppc64le"]="_output/bin/platforms/linux/ppc64le"
|
||||
["linux-s390x"]="_output/bin/platforms/linux/s390x"
|
||||
["darwin-amd64"]="_output/bin/platforms/darwin/amd64"
|
||||
["windows-amd64"]="_output/bin/platforms/windows/amd64"
|
||||
["linux-x86_64"]="_output/bin/platforms/linux/amd64" # Alias for linux-amd64
|
||||
["darwin-x86_64"]="_output/bin/platforms/darwin/amd64" # Alias for darwin-amd64
|
||||
)
|
||||
|
||||
declare -A supported_architectures_tools=(
|
||||
["linux-amd64"]="_output/bin-tools/platforms/linux/amd64"
|
||||
["linux-arm64"]="_output/bin-tools/platforms/linux/arm64"
|
||||
["linux-mips64"]="_output/bin-tools/platforms/linux/mips64"
|
||||
["linux-mips64le"]="_output/bin-tools/platforms/linux/mips64le"
|
||||
["linux-ppc64le"]="_output/bin-tools/platforms/linux/ppc64le"
|
||||
["linux-s390x"]="_output/bin-tools/platforms/linux/s390x"
|
||||
["darwin-amd64"]="_output/bin-tools/platforms/darwin/amd64"
|
||||
["windows-amd64"]="_output/bin-tools/platforms/windows/amd64"
|
||||
["linux-x86_64"]="_output/bin-tools/platforms/linux/amd64" # Alias for linux-amd64
|
||||
["darwin-x86_64"]="_output/bin-tools/platforms/darwin/amd64" # Alias for darwin-amd64
|
||||
)
|
||||
|
||||
# Check if the architecture and version are supported
|
||||
if [[ -z ${supported_architectures["$version-$architecture"]} ]]; then
|
||||
echo -e "${BLUE_PREFIX}================> Unsupported architecture: $architecture or version: $version${COLOR_SUFFIX}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "${BLUE_PREFIX}================> Architecture: $architecture${COLOR_SUFFIX}"
|
||||
|
||||
# Set the BIN_DIR based on the architecture and version
|
||||
BIN_DIR=${supported_architectures["$version-$architecture"]}
|
||||
BIN_DIR_TOOLS=${supported_architectures_tools["$version-$architecture"]}
|
||||
|
||||
echo -e "${BLUE_PREFIX}================> BIN_DIR: $OPENIM_ROOT/$BIN_DIR${COLOR_SUFFIX}"
|
||||
|
||||
# Don't put the space between "="
|
||||
openim_msggateway="openim-msggateway"
|
||||
msg_gateway_binary_root="$OPENIM_ROOT/$BIN_DIR"
|
||||
msg_gateway_source_root="$OPENIM_ROOT/cmd/openim-msggateway/"
|
||||
|
||||
msg_name="openim-rpc-msg"
|
||||
msg_binary_root="$OPENIM_ROOT/$BIN_DIR"
|
||||
msg_source_root="$OPENIM_ROOT/cmd/openim-rpc/openim-rpc-msg/"
|
||||
|
||||
push_name="openim-push"
|
||||
push_binary_root="$OPENIM_ROOT/$BIN_DIR"
|
||||
push_source_root="$OPENIM_ROOT/cmd/openim-push/"
|
||||
|
||||
openim_msgtransfer="openim-msgtransfer"
|
||||
msg_transfer_binary_root="$OPENIM_ROOT/$BIN_DIR"
|
||||
msg_transfer_source_root="$OPENIM_ROOT/cmd/openim-msgtransfer/"
|
||||
msg_transfer_service_num=4
|
||||
|
||||
cron_task_name="openim-crontask"
|
||||
cron_task_binary_root="$OPENIM_ROOT/$BIN_DIR"
|
||||
cron_task_source_root="$OPENIM_ROOT/cmd/openim-crontask/"
|
||||
|
||||
cmd_utils_name="openim-cmdutils"
|
||||
cmd_utils_binary_root="$OPENIM_ROOT/$BIN_DIR"
|
||||
cmd_utils_source_root="$OPENIM_ROOT/cmd/openim-cmdutils/"
|
||||
|
||||
# Global configuration file default dir
|
||||
config_path="$OPENIM_ROOT/config/config.yaml"
|
||||
configfile_path="$OPENIM_ROOT/config"
|
||||
log_path="$OPENIM_ROOT/log"
|
||||
|
||||
|
||||
component_check="component"
|
||||
component_check_binary_root="$OPENIM_ROOT/$BIN_DIR_TOOLS"
|
||||
|
||||
# servicefile dir path
|
||||
service_source_root=(
|
||||
# api service file
|
||||
"$OPENIM_ROOT/cmd/api/"
|
||||
# rpc service file
|
||||
"$OPENIM_ROOT/cmd/openim-rpc/openim-rpc-user/"
|
||||
"$OPENIM_ROOT/cmd/openim-rpc/openim-rpc-friend/"
|
||||
"$OPENIM_ROOT/cmd/openim-rpc/openim-rpc-group/"
|
||||
"$OPENIM_ROOT/cmd/openim-rpc/openim-rpc-auth/"
|
||||
"$OPENIM_ROOT/cmd/openim-rpc/openim-rpc-conversation/"
|
||||
"$OPENIM_ROOT/cmd/openim-rpc/openim-rpc-third/"
|
||||
"$OPENIM_ROOT/cmd/openim-crontask"
|
||||
"${msg_gateway_source_root}"
|
||||
"${msg_transfer_source_root}"
|
||||
"${msg_source_root}"
|
||||
"${push_source_root}"
|
||||
# "${sdk_server_source_root}"
|
||||
)
|
||||
|
||||
# service filename
|
||||
service_names=(
|
||||
# api service filename
|
||||
"openim-api"
|
||||
# rpc service filename
|
||||
"openim-rpc-user"
|
||||
"openim-rpc-friend"
|
||||
"openim-rpc-group"
|
||||
"openim-rpc-auth"
|
||||
"openim-rpc-conversation"
|
||||
"openim-rpc-third"
|
||||
"openim-crontask"
|
||||
"${openim_msggateway}"
|
||||
"${openim_msgtransfer}"
|
||||
"${msg_name}"
|
||||
"${push_name}"
|
||||
# "${sdk_server_name}"
|
||||
)
|
||||
@@ -1,78 +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.
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
source $SCRIPTS_ROOT/style_info.sh
|
||||
source $SCRIPTS_ROOT/path_info.sh
|
||||
source $SCRIPTS_ROOT/function.sh
|
||||
|
||||
cd $SCRIPTS_ROOT
|
||||
|
||||
echo -e "${YELLOW_PREFIX}=======>SCRIPTS_ROOT=$SCRIPTS_ROOT${COLOR_SUFFIX}"
|
||||
echo -e "${YELLOW_PREFIX}=======>OPENIM_ROOT=$OPENIM_ROOT${COLOR_SUFFIX}"
|
||||
echo -e "${YELLOW_PREFIX}=======>pwd=$PWD${COLOR_SUFFIX}"
|
||||
|
||||
bin_dir="$BIN_DIR"
|
||||
logs_dir="$OPENIM_ROOT/logs"
|
||||
|
||||
cd "$OPENIM_ROOT/scripts/"
|
||||
|
||||
list1=$(cat $config_path | grep openImPushPort | awk -F '[:]' '{print $NF}')
|
||||
list2=$(cat $config_path | grep pushPrometheusPort | awk -F '[:]' '{print $NF}')
|
||||
list_to_string $list1
|
||||
rpc_ports=($ports_array)
|
||||
list_to_string $list2
|
||||
prome_ports=($ports_array)
|
||||
|
||||
#Check if the service exists
|
||||
#If it is exists,kill this process
|
||||
#check=$(ps | grep -w ./${push_name} | grep -v grep | wc -l)
|
||||
#if [ $check -ge 1 ]; then
|
||||
# oldPid=$(ps | grep -w ./${push_name} | grep -v grep | awk '{print $2}')
|
||||
# kill -9 $oldPid
|
||||
#fi
|
||||
#Waiting port recycling
|
||||
sleep 1
|
||||
cd ${push_binary_root}
|
||||
|
||||
for ((i = 0; i < ${#rpc_ports[@]}; i++)); do
|
||||
echo "==========================start push server===========================">>$OPENIM_ROOT/logs/openIM.log
|
||||
nohup ./${push_name} --port ${rpc_ports[$i]} --prometheus_port ${prome_ports[$i]} >>$OPENIM_ROOT/logs/openIM.log 2>&1 &
|
||||
done
|
||||
|
||||
sleep 3
|
||||
#Check launched service process
|
||||
check=$(ps -axu| grep -w ./${push_name} | grep -v grep | wc -l)
|
||||
if [ $check -ge 1 ]; then
|
||||
newPid=$(ps -axu| grep -w ./${push_name} | grep -v grep | awk '{print $2}')
|
||||
ports=$(netstat -netulp | grep -w ${newPid} | awk '{print $4}' | awk -F '[:]' '{print $NF}')
|
||||
allPorts=""
|
||||
|
||||
for i in $ports; do
|
||||
allPorts=${allPorts}"$i "
|
||||
done
|
||||
echo -e ${SKY_BLUE_PREFIX}"SERVICE START SUCCESS "${COLOR_SUFFIX}
|
||||
echo -e ${SKY_BLUE_PREFIX}"SERVICE_NAME: "${COLOR_SUFFIX}${BACKGROUND_GREEN}${push_name}${COLOR_SUFFIX}
|
||||
echo -e ${SKY_BLUE_PREFIX}"PID: "${COLOR_SUFFIX}${BACKGROUND_GREEN}${newPid}${COLOR_SUFFIX}
|
||||
echo -e ${SKY_BLUE_PREFIX}"LISTENING_PORT: "${COLOR_SUFFIX}${BACKGROUND_GREEN}${allPorts}${COLOR_SUFFIX}
|
||||
else
|
||||
exit -1
|
||||
fi
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
#!/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 sets up a temporary openim GOPATH and runs an arbitrary
|
||||
# command under it. Go tooling requires that the current directory be under
|
||||
# GOPATH or else it fails to find some things, such as the vendor directory for
|
||||
# the project.
|
||||
# Usage: `scripts/run-in-gopath.sh <command>`.
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
||||
|
||||
# This sets up a clean GOPATH and makes sure we are currently in it.
|
||||
openim::golang::setup_env
|
||||
|
||||
# Run the user-provided command.
|
||||
"${@}"
|
||||
Executable
+74
@@ -0,0 +1,74 @@
|
||||
#!/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.
|
||||
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
source "${OPENIM_ROOT}/scripts/install/common.sh"
|
||||
|
||||
set +o errexit
|
||||
openim::golang::check_openim_binaries
|
||||
if [[ $? -ne 0 ]]; then
|
||||
openim::log::error "OpenIM binaries are not found. Please run 'make build' to build binaries."
|
||||
${OPENIM_ROOT}/scripts/build-all-service.sh
|
||||
fi
|
||||
set -o errexit
|
||||
|
||||
echo "You need to start the following scripts in order: ${OPENIM_SERVER_SCRIPTARIES[@]}"
|
||||
openim::log::install_errexit
|
||||
|
||||
# Function to execute the scripts.
|
||||
function execute_scripts() {
|
||||
for script_path in "${OPENIM_SERVER_SCRIPT_START_LIST[@]}"; do
|
||||
# Extract the script name without extension for argument generation.
|
||||
script_name_with_prefix=$(basename "$script_path" .sh)
|
||||
|
||||
# Remove the "openim-" prefix.
|
||||
script_name=${script_name_with_prefix#openim-}
|
||||
|
||||
# Construct the argument based on the script name.
|
||||
arg="openim::${script_name}::start"
|
||||
|
||||
# Check if the script file exists and is executable.
|
||||
if [[ -x "$script_path" ]]; then
|
||||
openim::log::status "Starting script: ${script_path##*/}" # Log the script name.
|
||||
|
||||
# Execute the script with the constructed argument.
|
||||
"$script_path" "$arg"
|
||||
|
||||
# Check if the script executed successfully.
|
||||
if [[ $? -eq 0 ]]; then
|
||||
openim::log::info "${script_path##*/} executed successfully."
|
||||
else
|
||||
openim::log::errexit "Error executing ${script_path##*/}."
|
||||
fi
|
||||
else
|
||||
openim::log::errexit "Script ${script_path##*/} is missing or not executable."
|
||||
fi
|
||||
sleep 0.5
|
||||
done
|
||||
}
|
||||
|
||||
# TODO Prelaunch tools, simple for now, can abstract functions later
|
||||
TOOLS_START_SCRIPTS_PATH=${START_SCRIPTS_PATH}/openim-tools.sh
|
||||
${TOOLS_START_SCRIPTS_PATH} openim::tools::pre-start
|
||||
|
||||
execute_scripts
|
||||
|
||||
${TOOLS_START_SCRIPTS_PATH} openim::tools::post-start
|
||||
@@ -1,116 +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.
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
OPENIM_ROOT=$(dirname "${SCRIPTS_ROOT}")/..
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
source $SCRIPTS_ROOT/style_info.sh
|
||||
source $SCRIPTS_ROOT/path_info.sh
|
||||
source $SCRIPTS_ROOT/function.sh
|
||||
|
||||
cd $SCRIPTS_ROOT
|
||||
|
||||
echo -e "${YELLOW_PREFIX}=======>SCRIPTS_ROOT=$SCRIPTS_ROOT${COLOR_SUFFIX}"
|
||||
echo -e "${YELLOW_PREFIX}=======>OPENIM_ROOT=$OPENIM_ROOT${COLOR_SUFFIX}"
|
||||
echo -e "${YELLOW_PREFIX}=======>pwd=$PWD${COLOR_SUFFIX}"
|
||||
|
||||
if [ ! -d "${OPENIM_ROOT}/_output/bin/platforms" ]; then
|
||||
# exec build_all_service.sh
|
||||
"${SCRIPTS_ROOT}/build_all_service.sh"
|
||||
fi
|
||||
|
||||
bin_dir="$OPENIM_ROOT/_output/bin"
|
||||
logs_dir="$OPENIM_ROOT/logs"
|
||||
|
||||
if [ ! -d "$bin_dir" ]; then
|
||||
mkdir -p "$bin_dir"
|
||||
fi
|
||||
|
||||
if [ ! -d "$logs_dir" ]; then
|
||||
mkdir -p "$logs_dir"
|
||||
fi
|
||||
|
||||
if [ ! -d "$sdk_db_dir" ]; then
|
||||
mkdir -p "$sdk_db_dir"
|
||||
fi
|
||||
|
||||
# Print title
|
||||
echo -e "${BOLD_PREFIX}${BLUE_PREFIX}================> OpenIM Server Start${COLOR_SUFFIX}"
|
||||
|
||||
# Get current time
|
||||
time=$(date +"%Y-%m-%d %H:%M:%S")
|
||||
|
||||
# Print section separator
|
||||
echo -e "${PURPLE_PREFIX}==========================================================${COLOR_SUFFIX}"
|
||||
|
||||
# Print server start time
|
||||
echo -e "${BOLD_PREFIX}${CYAN_PREFIX}Server Start Time: ${time}${COLOR_SUFFIX}"
|
||||
|
||||
# Print section separator
|
||||
echo -e "${PURPLE_PREFIX}==========================================================${COLOR_SUFFIX}"
|
||||
|
||||
cd $SCRIPTS_ROOT
|
||||
|
||||
# FIXME Put the shell script names here
|
||||
need_to_start_server_shell=(
|
||||
start_rpc_service.sh
|
||||
push_start.sh
|
||||
msg_transfer_start.sh
|
||||
msg_gateway_start.sh
|
||||
start_cron.sh
|
||||
)
|
||||
|
||||
component_check=start_component_check.sh
|
||||
echo -e ""
|
||||
chmod +x $component_check
|
||||
echo -e "=========> ${BACKGROUND_GREEN}Executing ${component_check}...${COLOR_SUFFIX}"
|
||||
echo -e ""
|
||||
./$component_check
|
||||
if [ $? -ne 0 ]; then
|
||||
# Print error message and exit
|
||||
echo -e "${RED_PREFIX}${BOLD_PREFIX}Error executing ${component_check}. Exiting...${COLOR_SUFFIX}"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
|
||||
# Loop through the script names and execute them
|
||||
for i in ${need_to_start_server_shell[*]}; do
|
||||
chmod +x $i
|
||||
|
||||
echo -e ""
|
||||
# Print script execution message
|
||||
echo -e "=========> ${BACKGROUND_GREEN}Executing ${i}...${COLOR_SUFFIX}"
|
||||
echo -e ""
|
||||
|
||||
./$i
|
||||
|
||||
# Check if the script executed successfully
|
||||
if [ $? -ne 0 ]; then
|
||||
# Print error message and exit
|
||||
echo -e "${RED_PREFIX}${BOLD_PREFIX}Error executing ${i}. Exiting(please check open-im-server/logs/openIM.log)... ${COLOR_SUFFIX}"
|
||||
exit -1
|
||||
fi
|
||||
done
|
||||
|
||||
# Print section separator
|
||||
echo -e "${PURPLE_PREFIX}==========================================================${COLOR_SUFFIX}"
|
||||
|
||||
# Print completion message
|
||||
echo -e "${GREEN_PREFIX}${BOLD_PREFIX}OpenIM Server has been started successfully!${COLOR_SUFFIX}"
|
||||
@@ -1,42 +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.
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
source $SCRIPTS_ROOT/style_info.sh
|
||||
source $SCRIPTS_ROOT/path_info.sh
|
||||
source $SCRIPTS_ROOT/function.sh
|
||||
|
||||
echo -e "${YELLOW_PREFIX}=======>SCRIPTS_ROOT=$SCRIPTS_ROOT${COLOR_SUFFIX}"
|
||||
echo -e "${YELLOW_PREFIX}=======>OPENIM_ROOT=$OPENIM_ROOT${COLOR_SUFFIX}"
|
||||
echo -e "${YELLOW_PREFIX}=======>pwd=$PWD${COLOR_SUFFIX}"
|
||||
|
||||
bin_dir="$BIN_DIR"
|
||||
logs_dir="$OPENIM_ROOT/logs"
|
||||
|
||||
cd ${component_check_binary_root}
|
||||
echo -e "${YELLOW_PREFIX}=======>$PWD${COLOR_SUFFIX}"
|
||||
cmd="./${component_check}"
|
||||
echo "==========================start components checking===========================">>$OPENIM_ROOT/logs/openIM.log
|
||||
$cmd
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
@@ -1,64 +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.
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
source $SCRIPTS_ROOT/style_info.sh
|
||||
source $SCRIPTS_ROOT/path_info.sh
|
||||
source $SCRIPTS_ROOT/function.sh
|
||||
|
||||
cd $SCRIPTS_ROOT
|
||||
|
||||
echo -e "${YELLOW_PREFIX}=======>SCRIPTS_ROOT=$SCRIPTS_ROOT${COLOR_SUFFIX}"
|
||||
echo -e "${YELLOW_PREFIX}=======>OPENIM_ROOT=$OPENIM_ROOT${COLOR_SUFFIX}"
|
||||
echo -e "${YELLOW_PREFIX}=======>pwd=$PWD${COLOR_SUFFIX}"
|
||||
|
||||
bin_dir="$BIN_DIR"
|
||||
logs_dir="$OPENIM_ROOT/logs"
|
||||
|
||||
#Check if the service exists
|
||||
#If it is exists,kill this process
|
||||
check=`ps | grep -w ./${cron_task_name} | grep -v grep| wc -l`
|
||||
#if [ $check -ge 1 ]
|
||||
#then
|
||||
#oldPid=`ps | grep -w ./${cron_task_name} | grep -v grep|awk '{print $2}'`
|
||||
# kill -9 $oldPid
|
||||
#fi
|
||||
#Waiting port recycling
|
||||
sleep 1
|
||||
|
||||
cd ${cron_task_binary_root}
|
||||
#for ((i = 0; i < ${cron_task_service_num}; i++)); do
|
||||
echo "==========================start cron_task process===========================">>$OPENIM_ROOT/logs/openIM.log
|
||||
nohup ./${cron_task_name} >>$OPENIM_ROOT/logs/openIM.log 2>&1 &
|
||||
#done
|
||||
|
||||
#Check launched service process
|
||||
check=`ps -axu| grep -w ./${cron_task_name} | grep -v grep| wc -l`
|
||||
if [ $check -ge 1 ]
|
||||
then
|
||||
newPid=`ps -axu| grep -w ./${cron_task_name} | grep -v grep|awk '{print $2}'`
|
||||
allPorts=""
|
||||
echo -e ${SKY_BLUE_PREFIX}"SERVICE START SUCCESS "${COLOR_SUFFIX}
|
||||
echo -e ${SKY_BLUE_PREFIX}"SERVICE_NAME: "${COLOR_SUFFIX}${BACKGROUND_GREEN}${cron_task_name}${COLOR_SUFFIX}
|
||||
echo -e ${SKY_BLUE_PREFIX}"PID: "${COLOR_SUFFIX}${BACKGROUND_GREEN}${newPid}${COLOR_SUFFIX}
|
||||
echo -e ${SKY_BLUE_PREFIX}"LISTENING_PORT: "${COLOR_SUFFIX}${BACKGROUND_GREEN}${allPorts}${COLOR_SUFFIX}
|
||||
else
|
||||
exit -1
|
||||
fi
|
||||
@@ -1,117 +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.
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
source $SCRIPTS_ROOT/style_info.sh
|
||||
source $SCRIPTS_ROOT/path_info.sh
|
||||
source $SCRIPTS_ROOT/function.sh
|
||||
|
||||
cd $SCRIPTS_ROOT
|
||||
|
||||
echo -e "${BACKGROUND_GREEN}${CYAN_PREFIX}=======>SCRIPTS_ROOT=$SCRIPTS_ROOT${COLOR_SUFFIX}"
|
||||
echo -e "${BACKGROUND_GREEN}${CYAN_PREFIX}=======>OPENIM_ROOT=$OPENIM_ROOT${COLOR_SUFFIX}"
|
||||
echo -e "${BACKGROUND_GREEN}${CYAN_PREFIX}=======>pwd=$PWD${COLOR_SUFFIX}"
|
||||
|
||||
bin_dir="$BIN_DIR"
|
||||
logs_dir="$OPENIM_ROOT/logs"
|
||||
|
||||
#service filename
|
||||
service_filename=(
|
||||
#api
|
||||
openim-api
|
||||
#rpc
|
||||
openim-rpc-user
|
||||
openim-rpc-friend
|
||||
openim-rpc-group
|
||||
openim-rpc-auth
|
||||
${msg_name}
|
||||
openim-rpc-conversation
|
||||
openim-rpc-third
|
||||
)
|
||||
|
||||
#service config port name
|
||||
service_port_name=(
|
||||
#api port name
|
||||
openImApiPort
|
||||
#rpc port name
|
||||
openImUserPort
|
||||
openImFriendPort
|
||||
openImGroupPort
|
||||
openImAuthPort
|
||||
openImMessagePort
|
||||
openImConversationPort
|
||||
openImThirdPort
|
||||
)
|
||||
|
||||
service_prometheus_port_name=(
|
||||
#api port name
|
||||
openImApiPort
|
||||
#rpc port name
|
||||
userPrometheusPort
|
||||
friendPrometheusPort
|
||||
groupPrometheusPort
|
||||
authPrometheusPort
|
||||
messagePrometheusPort
|
||||
conversationPrometheusPort
|
||||
thirdPrometheusPort
|
||||
)
|
||||
|
||||
for ((i = 0; i < ${#service_filename[*]}; i++)); do
|
||||
#Check whether the service exists
|
||||
service_name="ps |grep -w ${service_filename[$i]} |grep -v grep"
|
||||
count="${service_name}| wc -l"
|
||||
|
||||
# if [ $(eval ${count}) -gt 0 ]; then
|
||||
# pid="${service_name}| awk '{print \$2}'"
|
||||
# echo "${service_filename[$i]} service has been started,pid:$(eval $pid)"
|
||||
# echo "killing the service ${service_filename[$i]} pid:$(eval $pid)"
|
||||
# #kill the service that existed
|
||||
# kill -9 $(eval $pid)
|
||||
# sleep 0.5
|
||||
# fi
|
||||
cd $OPENIM_ROOT
|
||||
cd $BIN_DIR
|
||||
# Get the rpc port in the configuration file
|
||||
portList=$(cat $config_path | grep ${service_port_name[$i]} | awk -F '[:]' '{print $NF}')
|
||||
list_to_string ${portList}
|
||||
service_ports=($ports_array)
|
||||
|
||||
portList2=$(cat $config_path | grep ${service_prometheus_port_name[$i]} | awk -F '[:]' '{print $NF}')
|
||||
list_to_string $portList2
|
||||
prome_ports=($ports_array)
|
||||
#Start related rpc services based on the number of ports
|
||||
for ((j = 0; j < ${#service_ports[*]}; j++)); do
|
||||
#Start the service in the background
|
||||
if [ -z "${prome_ports[$j]}" ]; then
|
||||
cmd="./${service_filename[$i]} --port ${service_ports[$j]} --config_folder_path ${configfile_path} "
|
||||
else
|
||||
cmd="./${service_filename[$i]} --port ${service_ports[$j]} --prometheus_port ${prome_ports[$j]} --config_folder_path ${configfile_path} "
|
||||
fi
|
||||
if [ $i -eq 0 -o $i -eq 1 ]; then
|
||||
cmd="./${service_filename[$i]} --port ${service_ports[$j]}"
|
||||
fi
|
||||
echo $cmd
|
||||
echo "=====================start ${service_filename[$i]}======================">>$OPENIM_ROOT/logs/openIM.log
|
||||
nohup $cmd >>$OPENIM_ROOT/logs/openIM.log 2>&1 &
|
||||
sleep 1
|
||||
pid="netstat -ntlp|grep $j |awk '{printf \$7}'|cut -d/ -f1"
|
||||
echo -e "${GREEN_PREFIX}${service_filename[$i]} start success,port number:${service_ports[$j]} pid:$(eval $pid)$COLOR_SUFFIX"
|
||||
done
|
||||
done
|
||||
Executable
+35
@@ -0,0 +1,35 @@
|
||||
#!/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 stop all openim service
|
||||
#
|
||||
# Usage: `scripts/stop.sh`.
|
||||
# Encapsulated as: `make stop`.
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
|
||||
source "${OPENIM_ROOT}/scripts/install/common.sh"
|
||||
|
||||
echo "++ Ready to stop port: ${OPENIM_SERVER_PORT_LISTARIES[@]}"
|
||||
|
||||
openim::util::stop_services_on_ports ${OPENIM_SERVER_PORT_LISTARIES[@]}
|
||||
|
||||
echo -e "\n++ Stop all processes in the path ${OPENIM_OUTPUT_HOSTBIN}"
|
||||
|
||||
openim::util::stop_services_with_name "${OPENIM_OUTPUT_HOSTBIN}"
|
||||
@@ -1,41 +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.
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
|
||||
#Include shell font styles and some basic information
|
||||
source $OPENIM_ROOT/scripts/style_info.sh
|
||||
source $OPENIM_ROOT/scripts/path_info.sh
|
||||
|
||||
bin_dir="$BIN_DIR"
|
||||
logs_dir="$OPENIM_ROOT/logs"
|
||||
sdk_db_dir="$OPENIM_ROOT/sdk/db/"
|
||||
|
||||
cd "$SCRIPTS_ROOT"
|
||||
|
||||
for i in ${service_names[*]}; do
|
||||
#Check whether the service exists
|
||||
name="ps -aux |grep -w $i |grep -v grep"
|
||||
count="${name}| wc -l"
|
||||
if [ $(eval ${count}) -gt 0 ]; then
|
||||
pid="${name}| awk '{print \$2}'"
|
||||
echo -e "${SKY_BLUE_PREFIX}Killing service:$i pid:$(eval $pid)${COLOR_SUFFIX}"
|
||||
#kill the service that existed
|
||||
kill -9 $(eval $pid)
|
||||
echo -e "${SKY_BLUE_PREFIX}service:$i was killed ${COLOR_SUFFIX}"
|
||||
fi
|
||||
done
|
||||
@@ -1,67 +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.
|
||||
|
||||
function style-info() {
|
||||
COLOR_SUFFIX="\033[0m" # End all colors and special effects
|
||||
|
||||
BLACK_PREFIX="\033[30m" # Black prefix
|
||||
RED_PREFIX="\033[31m" # Red prefix
|
||||
GREEN_PREFIX="\033[32m" # Green prefix
|
||||
YELLOW_PREFIX="\033[33m" # Yellow prefix
|
||||
BLUE_PREFIX="\033[34m" # Blue prefix
|
||||
PURPLE_PREFIX="\033[35m" # Purple prefix
|
||||
SKY_BLUE_PREFIX="\033[36m" # Sky blue prefix
|
||||
WHITE_PREFIX="\033[37m" # White prefix
|
||||
BOLD_PREFIX="\033[1m" # Bold prefix
|
||||
UNDERLINE_PREFIX="\033[4m" # Underline prefix
|
||||
ITALIC_PREFIX="\033[3m" # Italic prefix
|
||||
|
||||
CYAN_PREFIX="033[0;36m" # Cyan prefix
|
||||
|
||||
BACKGROUND_BLACK="\033[40m" # Black background
|
||||
BACKGROUND_RED="\033[41m" # Red background
|
||||
BACKGROUND_GREEN="\033[42m" # Green background
|
||||
BACKGROUND_YELLOW="\033[43m" # Yellow background
|
||||
BACKGROUND_BLUE="\033[44m" # Blue background
|
||||
BACKGROUND_PURPLE="\033[45m" # Purple background
|
||||
BACKGROUND_SKY_BLUE="\033[46m" # Sky blue background
|
||||
BACKGROUND_WHITE="\033[47m" # White background
|
||||
|
||||
BLINK="\033[5m" # Blinking effect
|
||||
INVERT="\033[7m" # Invert color
|
||||
HIDE="\033[8m" # Hide text
|
||||
|
||||
GRAY_PREFIX="\033[90m" # Gray prefix
|
||||
LIGHT_RED_PREFIX="\033[91m" # Light red prefix
|
||||
LIGHT_GREEN_PREFIX="\033[92m" # Light green prefix
|
||||
LIGHT_YELLOW_PREFIX="\033[93m" # Light yellow prefix
|
||||
LIGHT_BLUE_PREFIX="\033[94m" # Light blue prefix
|
||||
LIGHT_PURPLE_PREFIX="\033[95m" # Light purple prefix
|
||||
LIGHT_SKY_BLUE_PREFIX="\033[96m" # Light sky blue prefix
|
||||
LIGHT_WHITE_PREFIX="\033[97m" # Light white prefix
|
||||
|
||||
BACKGROUND_GRAY="\033[100m" # Gray background
|
||||
BACKGROUND_LIGHT_RED="\033[101m" # Light red background
|
||||
BACKGROUND_LIGHT_GREEN="\033[102m" # Light green background
|
||||
BACKGROUND_LIGHT_YELLOW="\033[103m" # Light yellow background
|
||||
BACKGROUND_LIGHT_BLUE="\033[104m" # Light blue background
|
||||
BACKGROUND_LIGHT_PURPLE="\033[105m" # Light purple background
|
||||
BACKGROUND_LIGHT_SKY_BLUE="\033[106m" # Light sky blue background
|
||||
BACKGROUND_LIGHT_WHITE="\033[107m" # Light white background
|
||||
|
||||
}
|
||||
|
||||
style-info
|
||||
@@ -0,0 +1,3 @@
|
||||
Copyright © {{.Year}} {{.Holder}} All rights reserved.
|
||||
Use of this source code is governed by a MIT style
|
||||
license that can be found in the LICENSE file.
|
||||
@@ -0,0 +1,19 @@
|
||||
**Full Changelog**: https://github.com/{{ .Env.USERNAME }}/{{ .ProjectName }}/compare/{{ .PreviousTag }}...{{ .Tag }}
|
||||
|
||||
## Get Involved with OpenIM!
|
||||
|
||||
Your patronage towards OpenIM is greatly appreciated 🎉🎉.
|
||||
|
||||
If you encounter any problems during its usage, please create an issue in the [GitHub repository](https://github.com/{{ .Env.USERNAME }}/{{ .ProjectName }}/), we're committed to resolving your problem as soon as possible.
|
||||
|
||||
**Here are some ways to get involved with the OpenIM community:**
|
||||
|
||||
📢 **Slack Channel**: Join our Slack channels for discussions, communication, and support. Click [here](https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg) to join the Open-IM-Server Slack team channel.
|
||||
|
||||
📧 **Gmail Contact**: If you have any questions, suggestions, or feedback for our open-source projects, please feel free to [contact us via email](https://mail.google.com/mail/?view=cm&fs=1&tf=1&to=winxu81@gmail.com).
|
||||
|
||||
📖 **Blog**: Stay up-to-date with OpenIM-Server projects and trends by reading our [blog](https://doc.rentsoft.cn/). We share the latest developments, tech trends, and other interesting information related to OpenIM.
|
||||
|
||||
📱 **WeChat**: Add us on WeChat (QR Code) and indicate that you are a user or developer of Open-IM-Server. We'll process your request as soon as possible.
|
||||
|
||||
Remember, your contributions play a vital role in making OpenIM successful, and we look forward to your active participation in our community! 🙌
|
||||
@@ -0,0 +1,31 @@
|
||||
## Welcome to the {{ .Tag }} release of [OpenIM](https://github.com/{{ .Env.USERNAME }}/{{ .ProjectName }})!🎉🎉!
|
||||
|
||||
We are excited to release {{.Tag}}, Branch: https://github.com/{{ .Env.USERNAME }}/{{ .ProjectName }}/tree/{{ .Tag }} , Git hash [{{ .ShortCommit }}], Install Address: [{{ .ReleaseURL }}]({{ .ReleaseURL }})
|
||||
|
||||
Learn more about versions of OpenIM:
|
||||
|
||||
+ We release logs are recorded on [✨CHANGELOG](https://github.com/{{ .Env.USERNAME }}/{{ .ProjectName }}/blob/main/CHANGELOG/CHANGELOG.md)
|
||||
|
||||
+ For information on versions of OpenIM and how to maintain branches, read [📚this article](https://github.com/{{ .Env.USERNAME }}/{{ .ProjectName }}/blob/main/docs/conversions/version.md)
|
||||
|
||||
+ If you wish to use mirroring, read OpenIM's [🤲image management policy](https://github.com/{{ .Env.USERNAME }}/{{ .ProjectName }}/blob/main/docs/conversions/images.md)
|
||||
|
||||
**Want to be one of them 😘?**
|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/kubbot" style="float: left; margin-right: 10px;">
|
||||
<img src="https://github.com/openimbot/openimbot/blob/main/assets/icon/blue%E9%80%8F%E6%98%8E.png" width="50" height="50" />
|
||||
</a>
|
||||
<a href="https://www.openim.online">
|
||||
<img src="https://github.com/{{ .Env.USERNAME }}/{{ .ProjectName }}/blob/main/assets/logo/openim-logo.png" />
|
||||
</a>
|
||||
<a href="https://github.com/openimbot" style="float: right; margin-left: 10px;">
|
||||
<img src="https://github.com/openimbot/openimbot/blob/main/assets/icon/red%E9%80%8F%E6%98%8E.png" width="50" height="50" />
|
||||
</a>
|
||||
</p>
|
||||
|
||||
> **Note**
|
||||
> @openimbot and @kubbot have made great contributions to the community as community 🤖robots(@openimsdk/bot), respectively.
|
||||
> Thanks to the @openimsdk/openim team for all their hard work on this release.
|
||||
> Thank you to all the [💕developers and contributors](https://github.com/{{ .Env.USERNAME }}/{{ .ProjectName }}/graphs/contributors), people from all over the world, OpenIM brings us together
|
||||
> Contributions to this project are welcome! Please see [CONTRIBUTING.md](https://github.com/{{ .Env.USERNAME }}/{{ .ProjectName }}/blob/main/CONTRIBUTING.md) for details.
|
||||
@@ -0,0 +1,41 @@
|
||||
# Project myproject
|
||||
|
||||
<!-- Write one paragraph of this project description here -->
|
||||
|
||||
## Features
|
||||
|
||||
<!-- Tell others the features of this project -->
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Prerequisites
|
||||
|
||||
<!-- Describe packages, tools and everything we needed here -->
|
||||
|
||||
### Building
|
||||
|
||||
<!-- Describe how to build this project -->
|
||||
|
||||
### Running
|
||||
|
||||
<!-- Describe how to run this project -->
|
||||
|
||||
## Using
|
||||
|
||||
<!-- Place user documents here -->
|
||||
|
||||
## Contributing
|
||||
|
||||
<!-- Tell others how to contribute this project -->
|
||||
|
||||
## Community(optional)
|
||||
|
||||
<!-- Tell something about the community if needed -->
|
||||
|
||||
## Authors
|
||||
|
||||
<!-- Put authors here -->
|
||||
|
||||
## License
|
||||
|
||||
<!-- A link to license file -->
|
||||
Executable
+49
@@ -0,0 +1,49 @@
|
||||
#!/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 file is not intended to be run automatically. It is meant to be run
|
||||
# immediately before exporting docs. We do not want to check these documents in
|
||||
# by default.
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
source "${OPENIM_ROOT}/hack/lib/init.sh"
|
||||
|
||||
openim::golang::setup_env
|
||||
|
||||
BINS=(
|
||||
cmd/gendocs
|
||||
cmd/genopenimdocs
|
||||
cmd/genman
|
||||
cmd/genyaml
|
||||
)
|
||||
make -C "${OPENIM_ROOT}" WHAT="${BINS[*]}"
|
||||
|
||||
openim::util::ensure-temp-dir
|
||||
|
||||
openim::util::gen-docs "${OPENIM_TEMP}"
|
||||
|
||||
# remove all of the old docs
|
||||
openim::util::remove-gen-docs
|
||||
|
||||
# Copy fresh docs into the repo.
|
||||
# the shopt is so that we get docs/.generated_docs from the glob.
|
||||
shopt -s dotglob
|
||||
cp -af "${OPENIM_TEMP}"/* "${OPENIM_ROOT}"
|
||||
shopt -u dotglob
|
||||
Executable
+43
@@ -0,0 +1,43 @@
|
||||
#!/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 -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
source "${OPENIM_ROOT}/hack/lib/init.sh"
|
||||
|
||||
kube::golang::setup_env
|
||||
|
||||
cd "${OPENIM_ROOT}"
|
||||
|
||||
find_files() {
|
||||
find . -not \( \
|
||||
\( \
|
||||
-wholename './output' \
|
||||
-o -wholename './.git' \
|
||||
-o -wholename './_output' \
|
||||
-o -wholename './_gopath' \
|
||||
-o -wholename './release' \
|
||||
-o -wholename './target' \
|
||||
-o -wholename '*/vendor/*' \
|
||||
\) -prune \
|
||||
\) -name 'OWNERS*'
|
||||
}
|
||||
|
||||
export GO111MODULE=on
|
||||
find_files | xargs go run tools/yamlfmt/main.go
|
||||
Executable
+35
@@ -0,0 +1,35 @@
|
||||
#!/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 verifies whether codes follow golang convention.
|
||||
# Usage: `scripts/verify-pkg-names.sh`.
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
||||
|
||||
openim::golang::verify_go_version
|
||||
|
||||
cd "${OPENIM_ROOT}"
|
||||
if git --no-pager grep -E $'^(import |\t)[a-z]+[A-Z_][a-zA-Z]* "[^"]+"$' -- '**/*.go' ':(exclude)vendor/*' ':(exclude)**/*.pb.go'; then
|
||||
openim::log::error "Some package aliases break go conventions."
|
||||
echo "To fix these errors, do not use capitalized or underlined characters"
|
||||
echo "in pkg aliases. Refer to https://blog.golang.org/package-names for more info."
|
||||
exit 1
|
||||
fi
|
||||
Executable
+139
@@ -0,0 +1,139 @@
|
||||
#!/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 lints each shell script by `shellcheck`.
|
||||
# Usage: `scripts/verify-shellcheck.sh`.
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
||||
|
||||
# allow overriding docker cli, which should work fine for this script
|
||||
DOCKER="${DOCKER:-docker}"
|
||||
|
||||
# required version for this script, if not installed on the host we will
|
||||
# use the official docker image instead. keep this in sync with SHELLCHECK_IMAGE
|
||||
SHELLCHECK_VERSION="0.8.0"
|
||||
SHELLCHECK_IMAGE="docker.io/koalaman/shellcheck-alpine:v0.8.0@sha256:f42fde76d2d14a645a848826e54a4d650150e151d9c81057c898da89a82c8a56"
|
||||
|
||||
# disabled lints
|
||||
disabled=(
|
||||
# this lint disallows non-constant source, which we use extensively without
|
||||
# any known bugs
|
||||
1090
|
||||
# this lint warns when shellcheck cannot find a sourced file
|
||||
# this wouldn't be a bad idea to warn on, but it fails on lots of path
|
||||
# dependent sourcing, so just disable enforcing it
|
||||
1091
|
||||
# this lint prefers command -v to which, they are not the same
|
||||
2230
|
||||
)
|
||||
# comma separate for passing to shellcheck
|
||||
join_by() {
|
||||
local IFS="$1";
|
||||
shift;
|
||||
echo "$*";
|
||||
}
|
||||
SHELLCHECK_DISABLED="$(join_by , "${disabled[@]}")"
|
||||
readonly SHELLCHECK_DISABLED
|
||||
|
||||
# ensure we're linting the k8s source tree
|
||||
cd "${OPENIM_ROOT}"
|
||||
|
||||
# Find all shell scripts excluding:
|
||||
# - Anything git-ignored - No need to lint untracked files.
|
||||
# - ./_* - No need to lint output directories.
|
||||
# - ./.git/* - Ignore anything in the git object store.
|
||||
# - ./vendor* - Vendored code should be fixed upstream instead.
|
||||
# - ./third_party/*, but re-include ./third_party/forked/* - only code we
|
||||
# forked should be linted and fixed.
|
||||
all_shell_scripts=()
|
||||
while IFS=$'\n' read -r script;
|
||||
do git check-ignore -q "$script" || all_shell_scripts+=("$script");
|
||||
done < <(find . -name "*.sh" \
|
||||
-not \( \
|
||||
-path ./_\* -o \
|
||||
-path ./.git\* -o \
|
||||
-path ./vendor\* -o \
|
||||
\( -path ./third_party\* -a -not -path ./third_party/forked\* \) \
|
||||
\))
|
||||
|
||||
# detect if the host machine has the required shellcheck version installed
|
||||
# if so, we will use that instead.
|
||||
HAVE_SHELLCHECK=false
|
||||
if which shellcheck &>/dev/null; then
|
||||
detected_version="$(shellcheck --version | grep 'version: .*')"
|
||||
if [[ "${detected_version}" = "version: ${SHELLCHECK_VERSION}" ]]; then
|
||||
HAVE_SHELLCHECK=true
|
||||
fi
|
||||
fi
|
||||
|
||||
# if KUBE_JUNIT_REPORT_DIR is set, disable colorized output.
|
||||
# Colorized output causes malformed XML in the JUNIT report.
|
||||
SHELLCHECK_COLORIZED_OUTPUT="auto"
|
||||
if [[ -n "${KUBE_JUNIT_REPORT_DIR:-}" ]]; then
|
||||
SHELLCHECK_COLORIZED_OUTPUT="never"
|
||||
fi
|
||||
|
||||
# common arguments we'll pass to shellcheck
|
||||
SHELLCHECK_OPTIONS=(
|
||||
# allow following sourced files that are not specified in the command,
|
||||
# we need this because we specify one file at a time in order to trivially
|
||||
# detect which files are failing
|
||||
"--external-sources"
|
||||
# include our disabled lints
|
||||
"--exclude=${SHELLCHECK_DISABLED}"
|
||||
# set colorized output
|
||||
"--color=${SHELLCHECK_COLORIZED_OUTPUT}"
|
||||
)
|
||||
|
||||
# tell the user which we've selected and lint all scripts
|
||||
# The shellcheck errors are printed to stdout by default, hence they need to be redirected
|
||||
# to stderr in order to be well parsed for Junit representation by juLog function
|
||||
res=0
|
||||
if ${HAVE_SHELLCHECK}; then
|
||||
openim::log::info "Using host shellcheck ${SHELLCHECK_VERSION} binary."
|
||||
shellcheck "${SHELLCHECK_OPTIONS[@]}" "${all_shell_scripts[@]}" >&2 || res=$?
|
||||
else
|
||||
openim::log::info "Using shellcheck ${SHELLCHECK_VERSION} docker image."
|
||||
"${DOCKER}" run \
|
||||
--rm -v "${OPENIM_ROOT}:${OPENIM_ROOT}" -w "${OPENIM_ROOT}" \
|
||||
"${SHELLCHECK_IMAGE}" \
|
||||
shellcheck "${SHELLCHECK_OPTIONS[@]}" "${all_shell_scripts[@]}" >&2 || res=$?
|
||||
fi
|
||||
|
||||
# print a message based on the result
|
||||
if [ $res -eq 0 ]; then
|
||||
echo 'Congratulations! All shell files are passing lint :-)'
|
||||
else
|
||||
{
|
||||
echo
|
||||
echo 'Please review the above warnings. You can test via "./scripts/verify-shellcheck.sh"'
|
||||
echo 'If the above warnings do not make sense, you can exempt this warning with a comment'
|
||||
echo ' (if your reviewer is okay with it).'
|
||||
echo 'In general please prefer to fix the error, we have already disabled specific lints'
|
||||
echo ' that the project chooses to ignore.'
|
||||
echo 'See: https://github.com/koalaman/shellcheck/wiki/Ignore#ignoring-one-specific-instance-in-a-file'
|
||||
echo
|
||||
} >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# preserve the result
|
||||
exit $res
|
||||
Executable
+41
@@ -0,0 +1,41 @@
|
||||
#!/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 checks commonly misspelled English words in all files in the
|
||||
# working directory by client9/misspell package.
|
||||
# Usage: `scripts/verify-spelling.sh`.
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
export OPENIM_ROOT
|
||||
source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
||||
|
||||
# Ensure that we find the binaries we build before anything else.
|
||||
export GOBIN="${KUBE_OUTPUT_BINPATH}"
|
||||
PATH="${GOBIN}:${PATH}"
|
||||
|
||||
# Install tools we need
|
||||
pushd "${OPENIM_ROOT}/tools" >/dev/null
|
||||
GO111MODULE=on go install github.com/client9/misspell/cmd/misspell
|
||||
popd >/dev/null
|
||||
|
||||
# Spell checking
|
||||
# All the skipping files are defined in scripts/.spelling_failures
|
||||
skipping_file="${OPENIM_ROOT}/scripts/.spelling_failures"
|
||||
failing_packages=$(sed "s| | -e |g" "${skipping_file}")
|
||||
git ls-files | grep -v -e "${failing_packages}" | xargs misspell -i "Creater,creater,ect" -error -o stderr
|
||||
Executable
+41
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright © 2023 OpenIM. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# This script does a fast type check of script srnetes code for all platforms.
|
||||
# Usage: `scripts/verify-typecheck.sh`.
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
||||
|
||||
openim::golang::verify_go_version
|
||||
|
||||
cd "${OPENIM_ROOT}"
|
||||
|
||||
# As of June, 2020 the typecheck tool is written in terms of go/packages, but
|
||||
# that library doesn't work well with multiple modules. Until that is done,
|
||||
# force this tooling to run in a fake GOPATH.
|
||||
ret=0
|
||||
TYPECHECK_SERIAL="${TYPECHECK_SERIAL:-false}"
|
||||
scripts/run-in-gopath.sh \
|
||||
go run test/typecheck/typecheck.go "$@" "--serial=$TYPECHECK_SERIAL" || ret=$?
|
||||
if [[ $ret -ne 0 ]]; then
|
||||
openim::log::error "Type Check has failed. This may cause cross platform build failures." >&2
|
||||
openim::log::error "Please see https://github.com/OpenIMSDK/Open-IM-Server/tree/main/test/typecheck for more information." >&2
|
||||
exit 1
|
||||
fi
|
||||
Executable
+48
@@ -0,0 +1,48 @@
|
||||
#!/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 checks whether the OWNERS files need to be formatted or not by
|
||||
# `yamlfmt`. Run `scripts/update-yamlfmt.sh` to actually format sources.
|
||||
#
|
||||
# Usage: `scripts/verify-yamlfmt.sh`.
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
||||
|
||||
openim::util::ensure_clean_working_dir
|
||||
# This sets up the environment, like GOCACHE, which keeps the worktree cleaner.
|
||||
openim::golang::setup_env
|
||||
|
||||
_tmpdir="$(openim::realpath "$(mktemp -d -t "$(basename "$0").XXXXXX")")"
|
||||
git worktree add -f -q "${_tmpdir}" HEAD
|
||||
openim::util::trap_add "git worktree remove -f ${_tmpdir}" EXIT
|
||||
cd "${_tmpdir}"
|
||||
|
||||
# Format YAML files
|
||||
hack/update-yamlfmt.sh
|
||||
|
||||
# Test for diffs
|
||||
diffs=$(git status --porcelain | wc -l)
|
||||
if [[ ${diffs} -gt 0 ]]; then
|
||||
echo "YAML files need to be formatted" >&2
|
||||
git diff
|
||||
echo "Please run 'hack/update-yamlfmt.sh'" >&2
|
||||
exit 1
|
||||
fi
|
||||
+28
-20
@@ -1,17 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright 2020 Lingfei Kong <colin404@foxmail.com>. All rights reserved.
|
||||
# Use of this source code is governed by a MIT style
|
||||
# license that can be found in the LICENSE file.
|
||||
|
||||
# Use this script to test if a given TCP host/port are available
|
||||
# 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.
|
||||
|
||||
WAITFORIT_cmdname=${0##*/}
|
||||
|
||||
openim_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
|
||||
source "${openim_root}/scripts/lib/color.sh"
|
||||
|
||||
echoerr() { if [[ $WAITFORIT_QUIET -ne 1 ]]; then info "$@" 1>&2; fi }
|
||||
echoerr() { if [[ $WAITFORIT_QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }
|
||||
|
||||
usage()
|
||||
{
|
||||
@@ -30,7 +34,7 @@ USAGE
|
||||
exit 1
|
||||
}
|
||||
|
||||
function wait_for()
|
||||
wait_for()
|
||||
{
|
||||
if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
|
||||
echoerr "$WAITFORIT_cmdname: waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
|
||||
@@ -44,7 +48,7 @@ function wait_for()
|
||||
nc -z $WAITFORIT_HOST $WAITFORIT_PORT
|
||||
WAITFORIT_result=$?
|
||||
else
|
||||
(echo > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1
|
||||
(echo -n > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1
|
||||
WAITFORIT_result=$?
|
||||
fi
|
||||
if [[ $WAITFORIT_result -eq 0 ]]; then
|
||||
@@ -57,7 +61,7 @@ function wait_for()
|
||||
return $WAITFORIT_result
|
||||
}
|
||||
|
||||
function wait_for_wrapper()
|
||||
wait_for_wrapper()
|
||||
{
|
||||
# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
|
||||
if [[ $WAITFORIT_QUIET -eq 1 ]]; then
|
||||
@@ -133,7 +137,7 @@ do
|
||||
usage
|
||||
;;
|
||||
*)
|
||||
warn "Unknown argument: $1"
|
||||
echoerr "Unknown argument: $1"
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
@@ -149,16 +153,20 @@ WAITFORIT_STRICT=${WAITFORIT_STRICT:-0}
|
||||
WAITFORIT_CHILD=${WAITFORIT_CHILD:-0}
|
||||
WAITFORIT_QUIET=${WAITFORIT_QUIET:-0}
|
||||
|
||||
# check to see if timeout is from busybox?
|
||||
# Check to see if timeout is from busybox?
|
||||
WAITFORIT_TIMEOUT_PATH=$(type -p timeout)
|
||||
WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH)
|
||||
if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then
|
||||
WAITFORIT_ISBUSY=1
|
||||
WAITFORIT_BUSYTIMEFLAG="-t"
|
||||
|
||||
WAITFORIT_BUSYTIMEFLAG=""
|
||||
if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then
|
||||
WAITFORIT_ISBUSY=1
|
||||
# Check if busybox timeout uses -t flag
|
||||
# (recent Alpine versions don't support -t anymore)
|
||||
if timeout &>/dev/stdout | grep -q -e '-t '; then
|
||||
WAITFORIT_BUSYTIMEFLAG="-t"
|
||||
fi
|
||||
else
|
||||
WAITFORIT_ISBUSY=0
|
||||
WAITFORIT_BUSYTIMEFLAG=""
|
||||
WAITFORIT_ISBUSY=0
|
||||
fi
|
||||
|
||||
if [[ $WAITFORIT_CHILD -gt 0 ]]; then
|
||||
|
||||
Reference in New Issue
Block a user