mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-06 18:15:59 +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,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)
|
||||
Reference in New Issue
Block a user