Clean up unnecessary scripts and templates

pull/2223/head
skiffer-git 1 year ago
parent e11b928f4f
commit 357b73e8cc

@ -1,87 +0,0 @@
# This is a comment.
# Each line is a file pattern followed by one or more owners.
# README files
README.md @openimsdk/openim @openimsdk/bot @Bloomingg @FGadvancer @skiffer-git @withchao
# Contributing guidelines
CONTRIBUTING.md @openimsdk/bot @Bloomingg @FGadvancer @skiffer-git @withchao
# License files
LICENSE @openimsdk/bot @Bloomingg @FGadvancer @skiffer-git @withchao
# Makefile
Makefile @openimsdk/bot @Bloomingg @FGadvancer @skiffer-git @withchao
# These owners will be the default owners for everything in
# the repo. Unless a later match takes precedence,
# and @openimsdk/bot will be requested for
# review when someone opens a pull request.
* @openimsdk/openim @openimsdk/bot @Bloomingg @FGadvancer @skiffer-git @withchao
# Order is important; the last matching pattern takes the most
# precedence. When someone opens a pull request that only
# modifies JS files, only @js-owner and not the global
# owner(s) will be requested for a review.
*.js @openimsdk/bot @Bloomingg @FGadvancer @skiffer-git @withchao
# You can also use email addresses if you prefer. They'll be
# used to look up users just like we do for commit author
# emails.
*.go 3293172751nss@gmail.com
*.py 3293172751nss@gmail.com
# Teams can be specified as code owners as well. Teams should
# be identified in the format @org/team-name. Teams must have
# explicit write access to the repository. In this example,
# the OpenIMSDK team in the github organization owns all .txt files.
*.txt @openimsdk/bot @Bloomingg @FGadvancer @skiffer-git @withchao
# The `docs/*` pattern will match files like
# `docs/getting-started.md` but not further nested files like
# `docs/build-app/troubleshooting.md`.
docs/* 3293172751nss@gmail.com @openimsdk/bot @skiffer-git
# In this example, @octocat owns any file in an apps directory
# anywhere in your repository.
api/ @openimsdk/openim @skiffer-git
# This is a comment.
# Each line is a file pattern followed by one or more owners.
# CHANGELOG file
CHANGELOG/* @skiffer-git
# _output directory
_output/* @skiffer-git
# bin directory
bin/* @skiffer-git @FGadvancer
# cmd directory
cmd/*
# config directory
config/* @skiffer-git
# internal directory
internal/ @openimsdk/openim @skiffer-git @FGadvancer
tools @openimsdk/openim @openimsdk/bot @skiffer-git @FGadvancer
# logs directory
logs/* @skiffer-git @FGadvancer
# pkg directory
pkg/a2r @openimsdk/openim @skiffer-git @openimsdk/bot
# scripts directory
scripts/template/* @openimsdk/openim @skiffer-git @FGadvancer
scripts/enterprise/* @openimsdk/openim @FGadvancer @skiffer-git @openimsdk/bot
scripts/githooks/* @openimsdk/openim @skiffer-git @FGadvancer
scripts/lib/* @openimsdk/openim @FGadvancer @skiffer-git @openimsdk/bot
scripts/make-rules/* @openimsdk/openim @FGadvancer @skiffer-git @openimsdk/bot
# test directory
test/mongo @FGadvancer @skiffer-git @openimsdk/bot
test/mysql @FGadvancer @skiffer-git @openimsdk/bot

@ -1,311 +0,0 @@
# OpenIM Scripts Directory Structure
- [OpenIM Scripts Directory Structure](#openim-scripts-directory-structure)
- [log directory](#log-directory)
- [Supported platforms](#supported-platforms)
- [Get started quickly - demo.sh](#get-started-quickly---demosh)
- [Guide: Using and Understanding OpenIM Utility Functions](#guide-using-and-understanding-openim-utility-functions)
- [Table of Contents](#table-of-contents)
- [1. Checking the Status of Services by Ports](#1-checking-the-status-of-services-by-ports)
- [Function: `openim::util::check_ports`](#function-openimutilcheck_ports)
- [Example:](#example)
- [2. Checking the Status of Services by Process Names](#2-checking-the-status-of-services-by-process-names)
- [Function: `openim::util::check_process_names`](#function-openimutilcheck_process_names)
- [Example:](#example-1)
- [3. Stopping Services by Ports](#3-stopping-services-by-ports)
- [Function: `openim::util::stop_services_on_ports`](#function-openimutilstop_services_on_ports)
- [Example:](#example-2)
- [4. Stopping Services by Process Names](#4-stopping-services-by-process-names)
- [Function: `openim::util::stop_services_with_name`](#function-openimutilstop_services_with_name)
- [Example:](#example-3)
- [system management and installation of openim via Linux system](#system-management-and-installation-of-openim-via-linux-system)
- [examples](#examples)
This document outlines the directory structure for scripts in the OpenIM Server project. These scripts play a critical role in various areas like building, deploying, running and managing the services of OpenIM.
```bash
scripts/
├── README.md # Documentation for the scripts directory.
├── advertise.sh # Script to advertise or broadcast services.
├── batch_start_all.sh # Batch script to start all services.
├── build-all-service.sh # Script to build all services.
├── build.cmd # Command script for building (usually for Windows).
├── check-all.sh # Check script for all components or services.
├── cherry-pick.sh # Helper script for git cherry-pick operations.
├── common.sh # Common utilities and shared functions.
├── coverage.awk # AWK script for processing code coverage data.
├── coverage.sh # Script to gather and report code coverage.
├── demo.sh # Demonstration or example script.
├── docker-check-service.sh # Docker script to check services' status.
├── docker-start-all.sh # Docker script to start all containers/services.
├── ensure-tag.sh # Ensure correct tags or labeling.
├── env_check.sh # Environment verification and checking.
├── gen-swagger-docs.sh # Script to generate Swagger documentation.
├── genconfig.sh # Generate configuration files.
├── gendoc.sh # General documentation generation script.
├── githooks # Directory containing git hooks.
│ ├── commit-msg # Git hook for commit messages.
│ ├── pre-commit # Pre-commit git hook.
│ └── pre-push # Pre-push git hook.
├── golangci.yml # Configuration for GolangCI linting.
├── init-config.sh # Initialize configurations.
├── init-env.sh # Initialize the environment.
├── init-pwd.sh # Initialize or set password.
├── install # Installation scripts directory.
│ ├── README.md # Installation documentation.
│ ├── common.sh # Common utilities for installation.
│ ├── dependency.sh # Script to install dependencies.
│ ├── environment.sh # Set up the environment during installation.
│ ├── install-protobuf.sh # Install Protocol Buffers.
│ ├── install.sh # Main installation script.
│ ├── openim-api.sh # Install OpenIM API.
│ ├── openim-crontask.sh # Install OpenIM crontask.
│ ├── openim-man.sh # Install OpenIM management tool.
│ ├── openim-msggateway.sh # Install OpenIM message gateway.
│ ├── openim-msgtransfer.sh # Install OpenIM message transfer.
│ ├── openim-push.sh # Install OpenIM push service.
│ ├── openim-rpc.sh # Install OpenIM RPC.
│ ├── openim-tools.sh # Install OpenIM tools.
│ ├── test.sh # Installation testing script.
│ └── vimrc # Vim configuration file.
├── install-im-server.sh # Script to install the OpenIM server.
├── install_im_compose.sh # Install OpenIM using Docker Compose.
├── lib # Library or utility scripts directory.
│ ├── chat.sh # Utilities related to chat.
│ ├── color.sh # Color-related utilities.
│ ├── golang.sh # Golang utilities.
│ ├── init.sh # Initialization utilities.
│ ├── logging.sh # Logging utilities.
│ ├── release.sh # Release related utilities.
│ ├── util.sh # General utility functions.
│ └── version.sh # Version management utilities.
├── list-feature-tests.sh # Script to list feature tests.
├── make-rules # Makefile rule templates.
│ ├── common.mk # Common make rules.
│ ├── copyright.mk # Copyright related make rules.
│ ├── dependencies.mk # Dependency management rules.
│ ├── gen.mk # Generic or general rules.
│ ├── golang.mk # Golang-specific make rules.
│ ├── image.mk # Image or container-related rules.
│ ├── release.mk # Release specific rules.
│ ├── swagger.mk # Swagger documentation rules.
│ └── tools.mk # Tooling-related make rules.
├── mongo-init.sh # MongoDB initialization script.
├── release.sh # Script for releasing or deployment.
├── run-in-gopath.sh # Script to run commands within GOPATH.
├── start-all.sh # Script to start all services.
├── start.bat # Batch file to start services (usually for Windows).
├── stop-all.sh # Script to stop all services.
├── template # Directory containing template files.
│ ├── LICENSE # License template.
│ ├── LICENSE_TEMPLATES # Collection of license templates.
│ ├── boilerplate.txt # Boilerplate template.
│ ├── footer.md.tmpl # Footer template for markdown.
│ ├── head.md.tmpl # Header template for markdown.
│ └── project_README.md # Project README template.
├── update-generated-docs.sh # Update generated documentation.
├── update-yamlfmt.sh # Update YAML formatting.
├── verify-pkg-names.sh # Verify package names.
├── verify-shellcheck.sh # Shell script linting verification.
├── verify-spelling.sh # Spelling verification script.
├── verify-typecheck.sh # Type checking verification.
├── verify-yamlfmt.sh # Verify YAML format.
└── wait-for-it.sh # Script to wait for a condition or service to be ready.
```
The purpose of having a structured scripts directory like this is to make the operations of OpenIM Server clear and easy to manage. Each script has its own responsibility, making it easier to maintain and update. It's also helpful for newcomers who can easily understand what each part of the system is doing by just looking at this directory structure.
Each directory and script in the structure should be understood as a part of a larger whole. All scripts work together to ensure the smooth operation and maintenance of the OpenIM Server.
## log directory
**PATH:** `scripts/lib/logging.sh`
+ [log details](../docs/contrib/bash-log.md)
## Supported platforms
- Linux x86_64 (linux_amd64) : 64-bit Linux for most desktop and server systems.
- Windows x86_64 (windows_amd64) : 64-bit version for most Windows operating systems.
- macOS x86_64 (darwin_amd64) : 64-bit version for Apple Macintosh computers.
- Linux ARM64 (linux_arm64) : For ARM-based 64-bit Linux systems such as Raspberry Pi 4 and Jetson Nano.
- Linux s390x (linux_s390x) : 64-bit Linux for IBM System z hosts.
- Linux MIPS64 (linux_mips64) : 64-bit Linux for MIPS architecture.
- Linux MIPS64LE (linux_mips64le) : Suitable for 64-bit Linux systems with little endian MIPS architecture.
## Get started quickly - demo.sh
Is the `demo.sh` script teaching you how to quickly get started with OpenIM development and use
Steps to run demo:
```sh
$ make demo
```
More about `make` read:
+ [makefile](../docs/contrib/go-code.md)
Instructions for producing the demo movie:
```bash
# Create temporary directory
mkdir /tmp/kb-demo
cd /tmp/kb-demo
asciinema rec
<path-to-KB-repo>/scripts/demo/run.sh
<CTRL-C> to terminate the script
<CTRL-D> to terminate the asciinema recording
<CTRL-C> to save the recording locally
# Edit the recorded file by editing the controller-gen path
# Once you are happy with the recording, use svg-term program to generate the svg
svg-term --cast=<movie-id> --out _output/demo.svg --window
```
Here you will learn how to test a script, We take the four functions for starting and checking a service as an example.
## Guide: Using and Understanding OpenIM Utility Functions
This document provides an overview of the four utility functions designed for managing processes and services. These functions can check the status of services based on ports and process names, as well as stop services based on the same criteria.
### Table of Contents
- [1. Checking the Status of Services by Ports](#checking-the-status-of-services-by-ports)
- [2. Checking the Status of Services by Process Names](#checking-the-status-of-services-by-process-names)
- [3. Stopping Services by Ports](#stopping-services-by-ports)
- [4. Stopping Services by Process Names](#stopping-services-by-process-names)
### 1. Checking the Status of Services by Ports
#### Function: `openim::util::check_ports`
This function checks the status of services running on specified ports.
**Usage**:
```bash
$ openim::util::check_ports <port1> <port2> ...
```
**Design**:
- The function iterates through each provided port.
- It uses the `lsof` command to identify if there is a service running on the specified port.
- If a service is running, it logs the command, PID, and start time of the service.
- If a service is not running, it logs that the port is not started.
- If any service is not running, the function returns a status of 1.
#### Example:
```bash
$ openim::util::check_ports 8080 8081 8082
```
### 2. Checking the Status of Services by Process Names
#### Function: `openim::util::check_process_names`
This function checks the status of services based on their process names.
**Usage**:
```bash
$ openim::util::check_process_names <process_name1> <process_name2> ...
```
**Design**:
- The function uses `pgrep` to find process IDs associated with the given process names.
- If processes are found, it logs the command, PID, associated port, and start time.
- If no processes are found for a name, it logs that the process is not started.
- If any process is not running, the function returns a status of 1.
#### Example:
```bash
$ openim::util::check_process_names nginx mysql redis
```
### 3. Stopping Services by Ports
#### Function: `openim::util::stop_services_on_ports`
This function attempts to stop services running on the specified ports.
**Usage**:
```bash
$ openim::util::stop_services_on_ports <port1> <port2> ...
```
**Design**:
- The function uses the `lsof` command to identify services running on the specified ports.
- If a service is running on a port, it tries to terminate the associated process using the `kill` command.
- It logs successful terminations and any failures.
- If any service couldn't be stopped, the function returns a status of 1.
#### Example:
```bash
$ openim::util::stop_services_on_ports 8080 8081 8082
```
### 4. Stopping Services by Process Names
#### Function: `openim::util::stop_services_with_name`
This function attempts to stop services based on their process names.
**Usage**:
```bash
$ openim::util::stop_services_with_name <process_name1> <process_name2> ...
```
**Design**:
- The function uses `pgrep` to identify processes associated with the specified names.
- If processes are found, it tries to terminate them using the `kill` command.
- It logs successful terminations and any failures.
- If any service couldn't be stopped, the function returns a status of 1.
#### Example:
```bash
$ openim::util::stop_services_with_name nginx apache
```
### system management and installation of openim via Linux system
```bash
$ ./scripts/install/install.sh
```
## examples
Scripts to perform various build, install, analysis, etc operations.
The script directory design of OpenIM and the writing of scripts and tools refer to many excellent open source projects, such as helm, iam, kubernetes, docker, etc.
Maybe they'll give you inspiration for later maintenance...
These scripts keep the root level Makefile small and simple.
Examples:
* https://github.com/kubernetes/helm/tree/master/scripts
* https://github.com/cockroachdb/cockroach/tree/master/scripts
* https://github.com/hashicorp/terraform/tree/master/scripts

@ -1,72 +0,0 @@
#!/usr/bin/env bash
# Copyright © 2023 OpenIM. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This script runs `make build` command.
# The command compiles all Makefile configs.
# Args:
# WHAT: Directory names to build. If any of these directories has a 'main'
# package, the build will produce executable files under $(OUT_DIR)/bin/platforms OR $(OUT_DIR)/bin—tools/platforms.
# If not specified, "everything" will be built.
# Usage: `scripts/build-all-service.sh`.
# Example: `scripts/build-go.sh WHAT=cmd/kubelet`.
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/lib/init.sh"
# CPU core number
pushd "${OPENIM_ROOT}/tools/ncpu" >/dev/null
cpu_count=$(go run .)
popd >/dev/null
openim::color::echo ${GREEN_PREFIX} "======> cpu_count=$cpu_count"
openim::log::info "Building OpenIM, Parallel compilation compile=$cpu_count"
compile_count=$((cpu_count / 2))
# For help output
ARGHELP=""
if [[ "$#" -gt 0 ]]; then
ARGHELP="'$*'"
fi
openim::color::echo $COLOR_CYAN "NOTE: $0 has been replaced by 'make multiarch' or 'make build'"
echo
echo "The equivalent of this invocation is: "
echo " make build ${ARGHELP}"
echo " ./scripts/build-all-service.sh ${ARGHELP}"
echo
echo " Example: "
echo " Print a single binary:"
echo " make build BINS=openim-api"
echo " ./scripts/build-all-service.sh BINS=openim-api"
echo " Print : Enable debugging and logging"
echo " make build BINS=openim-api V=1 DEBUG=1"
echo " ./scripts/build-all-service.sh BINS=openim-api V=1 DEBUG=1"
echo
if [ -z "$*" ]; then
openim::log::info "no args, build all service"
make --no-print-directory -C "${OPENIM_ROOT}" -j$compile_count build
else
openim::log::info "build service: $*"
make --no-print-directory -C "${OPENIM_ROOT}" -j$compile_count build "$*"
fi
if [ $? -eq 0 ]; then
openim::log::success "all service build success, run 'make start' or './scripts/start-all.sh'"
else
openim::log::error "make build Error, script exits"
fi

@ -1,113 +0,0 @@
#!/usr/bin/env bash
# Copyright © 2023 OpenIM. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This script is check openim service is running normally
#
# Usage: `scripts/check-all.sh`.
# Encapsulated as: `make check`.
# READ: https://github.com/openimsdk/open-im-server/tree/main/scripts/install/environment.sh
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/install/common.sh"
if openim::util::is_running_in_container; then
exec >> ${DOCKER_LOG_FILE} 2>&1
fi
OPENIM_VERBOSE=4
openim::log::info "\n# Begin to check all OpenIM service"
openim::log::status "Check all dependent service ports"
# Elegant printing function
# Elegant printing function
print_services_and_ports() {
local service_names=("$@")
local half_length=$((${#service_names[@]} / 2))
local service_ports=("${service_names[@]:half_length}")
echo "+-------------------------+----------+"
echo "| Service Name | Port |"
echo "+-------------------------+----------+"
for ((index=0; index < half_length; index++)); do
printf "| %-23s | %-8s |\n" "${service_names[$index]}" "${service_ports[$index]}"
done
echo "+-------------------------+----------+"
}
# Assuming OPENIM_SERVER_NAME_TARGETS and OPENIM_SERVER_PORT_TARGETS are defined
# Similarly for OPENIM_DEPENDENCY_TARGETS and OPENIM_DEPENDENCY_PORT_TARGETS
# Print out services and their ports
print_services_and_ports "${OPENIM_SERVER_NAME_TARGETS[@]}" "${OPENIM_SERVER_PORT_TARGETS[@]}"
# Print out dependencies and their ports
print_services_and_ports "${OPENIM_DEPENDENCY_TARGETS[@]}" "${OPENIM_DEPENDENCY_PORT_TARGETS[@]}"
# OpenIM check
#echo "++ The port being checked: ${OPENIM_SERVER_PORT_LISTARIES[@]}"
openim::log::info "\n## Check all dependent components service ports"
#echo "++ The port being checked: ${OPENIM_DEPENDENCY_PORT_LISTARIES[@]}"
# Later, after discarding Docker, the Docker keyword is unreliable, and Kubepods is used
if grep -qE 'docker|kubepods' /proc/1/cgroup || [ -f /.dockerenv ]; then
openim::color::echo ${COLOR_CYAN} "Environment in the interior of the container"
else
openim::color::echo ${COLOR_CYAN}"The environment is outside the container"
openim::util::check_ports ${OPENIM_DEPENDENCY_PORT_LISTARIES[@]}
fi
if [[ $? -ne 0 ]]; then
openim::log::error_exit "The service does not start properly, please check the port, query variable definition!"
echo "+++ https://github.com/openimsdk/open-im-server/tree/main/scripts/install/environment.sh +++"
else
openim::log::success "All components depended on by OpenIM are running normally! "
fi
openim::log::status "Check OpenIM service:"
openim::log::colorless "${OPENIM_OUTPUT_HOSTBIN}/openim-msgtransfer"
result=$(. $(dirname ${BASH_SOURCE})/install/openim-msgtransfer.sh openim::msgtransfer::check)
if [[ $? -ne 0 ]]; then
#echo "+++ cat openim log file >>> ${LOG_FILE}"
openim::log::error "The service is not running properly, please check the logs $result"
fi
openim::log::status "Check OpenIM service:"
for item in "${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]}"; do
openim::log::colorless "$item"
done
result=$(openim::util::check_process_names ${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]})
if [[ $? -ne 0 ]]; then
#echo "+++ cat OpenIM log file >>> ${LOG_FILE}"
openim::log::error "The service is not running properly, please check the logs "
echo "$result"
exit 1
else
openim::log::status "List the ports listened to by the OpenIM service:"
openim::util::find_ports_for_all_services ${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]}
openim::util::find_ports_for_all_services ${OPENIM_MSGTRANSFER_BINARY[@]}
openim::log::success "All OpenIM services are running normally! "
fi

@ -1,26 +0,0 @@
#!/usr/bin/env bash
# Copyright © 2023 OpenIM. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#fixme This scripts is the total startup scripts
#fixme The full name of the shell scripts that needs to be started is placed in the need_to_start_server_shell array
cd /openim/openim-server
mage start
tail -f /dev/null

@ -1,86 +0,0 @@
#!/usr/bin/env bash
# Copyright © 2024 OpenIM. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# OpenIM Docker Deployment Script
#
# This script automates the process of building the OpenIM server image
# and deploying it using Docker Compose.
#
# Variables:
# - SERVER_IMAGE_VERSION: Version of the server image (default: test)
# - IMAGE_REGISTRY: Docker image registry (default: openim)
# - DOCKER_COMPOSE_FILE_URL: URL to the docker-compose.yml file
#
# Usage:
# SERVER_IMAGE_VERSION=latest IMAGE_REGISTRY=myregistry ./this_script.sh
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/lib/init.sh"
trap 'openim::util::onCtrlC' INT
chmod +x "${OPENIM_ROOT}"/scripts/*.sh
openim::util::ensure_docker_daemon_connectivity
# Default values for variables
: ${SERVER_IMAGE_VERSION:=test}
: ${IMAGE_REGISTRY:=openim}
: ${DOCKER_COMPOSE_FILE_URL:="https://raw.githubusercontent.com/openimsdk/openim-docker/main/docker-compose.yaml"}
DOCKER_COMPOSE_COMMAND=
# Check if docker-compose command is available
openim::util::check_docker_and_compose_versions
if command -v docker compose &> /dev/null; then
openim::log::info "docker compose command is available"
DOCKER_COMPOSE_COMMAND="docker compose"
else
DOCKER_COMPOSE_COMMAND="docker-compose"
fi
export SERVER_IMAGE_VERSION
export IMAGE_REGISTRY
"${OPENIM_ROOT}"/scripts/init-config.sh
pushd "${OPENIM_ROOT}"
docker build -t "${IMAGE_REGISTRY}/openim-server:${SERVER_IMAGE_VERSION}" .
${DOCKER_COMPOSE_COMMAND} stop
curl "${DOCKER_COMPOSE_FILE_URL}" -o docker-compose.yml
${DOCKER_COMPOSE_COMMAND} up -d
# Function to check container status
check_containers() {
if ! ${DOCKER_COMPOSE_COMMAND} ps | grep -q 'Up'; then
echo "Error: One or more docker containers failed to start."
${DOCKER_COMPOSE_COMMAND} logs openim-server
${DOCKER_COMPOSE_COMMAND} logs openim-chat
return 1
fi
return 0
}
# Wait for a short period to allow containers to initialize
sleep 100
${DOCKER_COMPOSE_COMMAND} ps
check_containers
popd

@ -1,116 +0,0 @@
# OpenIM Suite Scripts
The OpenIM Suite represents a comprehensive collection of scripts, each tailored to manage and operate specific services within the OpenIM ecosystem. These scripts offer consistent, reliable, and efficient tools for initializing, controlling, and managing various OpenIM services on a Linux platform.
## Features
- **Robustness:** Built with Bash's error handling mechanisms (`errexit`, `nounset`, and `pipefail`), ensuring scripts fail fast and provide relevant error messages.
- **Modularity:** Each script is dedicated to a particular service, promoting clarity and ease of maintenance.
- **Comprehensive Logging:** Integrated logging utilities offer real-time insights into operations, enhancing transparency and debuggability.
- **Systemd Integration:** Where applicable, scripts integrate with the systemd service manager, offering standardized service controls like start, stop, restart, and status checks.
## Scripts Overview
1. **openim-api:** Control interface for the OpenIM API service.
2. **openim-cmdutils:** Utility toolkit for common OpenIM command-line operations.
3. **openim-crontask:** Manages the OpenIM CronTask service, with both direct and systemctl installation methods.
4. **openim-msggateway:** Script to operate the OpenIM Message Gateway service.
5. **openim-msgtransfer:** Manages the OpenIM Message Transfer functionalities.
6. **openim-push:** Interface for controlling the OpenIM Push Notification service.
7. **openim-rpc-auth:** Script dedicated to the OpenIM RPC Authentication service.
8. **openim-rpc-conversation:** Manages operations related to the OpenIM RPC Conversation service.
9. **openim-rpc-friend:** Control interface for the OpenIM RPC Friend functionalities.
10. **openim-rpc-group:** Script for managing the OpenIM RPC Group service.
11. **openim-rpc-msg:** Operates the OpenIM RPC Messaging service.
12. **openim-rpc-third:** Script dedicated to third-party integrations with OpenIM RPC.
13. **openim-rpc-user:** Control interface for OpenIM RPC User operations.
## OpenIM Server Installation Script Usage
The scripts within the OpenIM Suite generally adhere to two primary execution methodologies. To illustrate these methodologies, we'll use `openim-crontask` as a representative example.
1. **Direct Script Execution:** Running the script directly, typically for straightforward start/stop operations.
```bash
./[script-name].sh
```
2. **Function-based Execution:** Invoking specific functions within the script for more specialized operations (e.g., install, uninstall).
```bash
./scripts/install/install.sh [options]
```
**Description:**
This script is designed to handle the installation, uninstallation, and status checking of OpenIM components on the server. OpenIM is a presumed communication or messaging platform.
### Commands:
- **-i, --install**:
Initiate the installation of all OpenIM components.
- **-u, --uninstall**:
Uninstall or remove all OpenIM components from the server.
- **-s, --status**:
Check and report the current operational status of the installed OpenIM components.
- **-h, --help**:
Display the help menu for available commands.
### Example Usage:
To install all OpenIM components:
```bash
./scripts/install/install.sh -i
```
or
```bash
./scripts/install/install.sh --install
```
> **Note**:
> Ensure you have the necessary privileges to execute installation or uninstallation operations. It's generally recommended to take a backup before making major changes.
### 1. Direct Script Execution
This method involves invoking the script directly, initiating its default behavior. For instance, with `openim-crontask`, direct execution will start the OpenIM CronTask as a background process.
**Example:**
```bash
./openim-crontask.sh
```
Upon execution, the script will source any necessary configurations, log the start of the CronTask, and finally run the CronTask in the background. The log messages will provide feedback about the process, ensuring the user is informed of the task's progress.
### 2. Function-based Execution
This approach is more specialized, enabling users to call specific functions defined within the script. This is particularly useful for tasks like installation, uninstallation, and status checks.
For the `openim-crontask` script:
- **Installation**: It includes building the service, generating configuration files, setting up systemd services, and starting the service.
```bash
./openim-crontask.sh openim::crontask::install
```
- **Uninstallation**: Stops the service, removes associated binaries, configuration files, and systemd service files.
```bash
./openim-crontask.sh openim::crontask::uninstall
```
- **Status Check**: Verifies the running status of the service, checking for active processes and listening ports.
```bash
./openim-crontask.sh openim::crontask::status
```
It's crucial to familiarize oneself with the available functions within each script. This ensures optimal utilization of the provided tools and a deeper understanding of the underlying operations.
## Notes
- Always ensure you have the correct permissions before executing any script.
- Environment variables may need to be set or sourced depending on your installation and configuration.

@ -1,89 +0,0 @@
#!/usr/bin/env bash
# Copyright © 2023 OpenIM. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This script will install the dependencies required for openim
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
# Start MongoDB service
docker run -d \
--name mongo \
-p 37017:27017 \
-v "${DATA_DIR}/components/mongodb/data/db:/data/db" \
-v "${DATA_DIR}/components/mongodb/data/logs:/data/logs" \
-v "${DATA_DIR}/components/mongodb/data/conf:/etc/mongo" \
-v "./scripts/mongo-init.sh:/docker-entrypoint-initdb.d/mongo-init.sh:ro" \
-e TZ=Asia/Shanghai \
-e wiredTigerCacheSizeGB=1 \
-e MONGO_INITDB_ROOT_USERNAME=${OPENIM_USER} \
-e MONGO_INITDB_ROOT_PASSWORD=${PASSWORD} \
-e MONGO_INITDB_DATABASE=openim_v3 \
-e MONGO_OPENIM_USERNAME=${OPENIM_USER} \
-e MONGO_OPENIM_PASSWORD=${PASSWORD} \
--restart always \
mongo:6.0.2 --wiredTigerCacheSizeGB 1 --auth
# Start Redis service
docker run -d \
--name redis \
-p 16379:6379 \
-v "${DATA_DIR}/components/redis/data:/data" \
-v "${DATA_DIR}/components/redis/config/redis.conf:/usr/local/redis/config/redis.conf" \
-e TZ=Asia/Shanghai \
--sysctl net.core.somaxconn=1024 \
--restart always \
redis:7.0.0 redis-server --requirepass ${PASSWORD} --appendonly yes
# Start Zookeeper service
docker run -d \
--name zookeeper \
-p 2181:2181 \
-v "/etc/localtime:/etc/localtime" \
-e TZ=Asia/Shanghai \
--restart always \
wurstmeister/zookeeper
# Start Kafka service
docker run -d \
--name kafka \
-p 9092:9092 \
-e TZ=Asia/Shanghai \
-e KAFKA_BROKER_ID=0 \
-e KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 \
-e KAFKA_CREATE_TOPICS="latestMsgToRedis:8:1,msgToPush:8:1,offlineMsgToMongoMysql:8:1" \
-e KAFKA_ADVERTISED_LISTENERS="INSIDE://127.0.0.1:9092,OUTSIDE://103.116.45.174:9092" \
-e KAFKA_LISTENERS="INSIDE://:9092,OUTSIDE://:9093" \
-e KAFKA_LISTENER_SECURITY_PROTOCOL_MAP="INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT" \
-e KAFKA_INTER_BROKER_LISTENER_NAME=INSIDE \
--restart always \
--link zookeeper \
wurstmeister/kafka
# Start MinIO service
docker run -d \
--name minio \
-p 10005:9000 \
-p 9090:9090 \
-v "/mnt/data:/data" \
-v "/mnt/config:/root/.minio" \
-e MINIO_ROOT_USER=${OPENIM_USER} \
-e MINIO_ROOT_PASSWORD=${PASSWORD} \
--restart always \
minio/minio server /data --console-address ':9090'

@ -1,118 +0,0 @@
#!/usr/bin/env bash
# Copyright © 2023 OpenIM. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# --------------------------------------------------------------
# OpenIM Protoc Tool v1.0.0
# --------------------------------------------------------------
# OpenIM has released its custom Protoc tool version v1.0.0.
# This tool is customized to meet the specific needs of OpenIM and resides in its separate repository.
# It can be downloaded from the following link:
# https://github.com/OpenIMSDK/Open-IM-Protoc/releases/tag/v1.0.0
#
# About the tool:
# https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/protoc-tools.md
# Download link (Windows): https://github.com/OpenIMSDK/Open-IM-Protoc/releases/download/v1.0.0/windows.zip
# Download link (Linux): https://github.com/OpenIMSDK/Open-IM-Protoc/releases/download/v1.0.0/linux.zip
#
# Installation steps (taking Windows as an example):
# 1. Visit the above link and download the version suitable for Windows.
# 2. Extract the downloaded file.
# 3. Add the extracted tool to your PATH environment variable so that it can be run directly from the command line.
#
# Note: The specific installation and usage instructions may vary based on the tool's actual implementation. It's advised to refer to official documentation.
# --------------------------------------------------------------
PROTOC_DOWNLOAD_URL="https://github.com/OpenIMSDK/Open-IM-Protoc/releases/download/v1.0.0/linux.zip"
DOWNLOAD_DIR="/tmp/openim-protoc"
INSTALL_DIR="/usr/local/bin"
function help_message {
echo "Usage: ./install-protobuf.sh [option]"
echo "Options:"
echo "-i, --install Install the OpenIM Protoc tool."
echo "-u, --uninstall Uninstall the OpenIM Protoc tool."
echo "-r, --reinstall Reinstall the OpenIM Protoc tool."
echo "-c, --check Check if the OpenIM Protoc tool is installed."
echo "-h, --help Display this help message."
}
function install_protobuf {
echo "Installing OpenIM Protoc tool..."
# Create temporary directory and download the zip file
mkdir -p $DOWNLOAD_DIR
wget $PROTOC_DOWNLOAD_URL -O $DOWNLOAD_DIR/linux.zip
# Unzip the file
unzip -o $DOWNLOAD_DIR/linux.zip -d $DOWNLOAD_DIR
# Move binaries to the install directory and make them executable
sudo cp $DOWNLOAD_DIR/linux/protoc $INSTALL_DIR/
sudo cp $DOWNLOAD_DIR/linux/protoc-gen-go $INSTALL_DIR/
sudo chmod +x $INSTALL_DIR/protoc
sudo chmod +x $INSTALL_DIR/protoc-gen-go
# Clean up
rm -rf $DOWNLOAD_DIR
echo "OpenIM Protoc tool installed successfully!"
}
function uninstall_protobuf {
echo "Uninstalling OpenIM Protoc tool..."
# Removing binaries from the install directory
sudo rm -f $INSTALL_DIR/protoc
sudo rm -f $INSTALL_DIR/protoc-gen-go
echo "OpenIM Protoc tool uninstalled successfully!"
}
function reinstall_protobuf {
echo "Reinstalling OpenIM Protoc tool..."
uninstall_protobuf
install_protobuf
}
function check_protobuf {
echo "Checking for OpenIM Protoc tool installation..."
which protoc > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "OpenIM Protoc tool is installed."
else
echo "OpenIM Protoc tool is not installed."
fi
}
while [ "$1" != "" ]; do
case $1 in
-i | --install ) install_protobuf
;;
-u | --uninstall ) uninstall_protobuf
;;
-r | --reinstall ) reinstall_protobuf
;;
-c | --check ) check_protobuf
;;
-h | --help ) help_message
exit
;;
* ) help_message
exit 1
esac
shift
done

@ -1,155 +0,0 @@
#!/usr/bin/env bash
# Copyright © 2023 OpenIM. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# OpenIM Server Installation Script
#
# Description:
# This script is designed to handle the installation, Is a deployment solution
# that uses the Linux systen extension. uninstallation, and
# status checking of OpenIM components on the server. OpenIM is a presumed
# communication or messaging platform based on the context.
#
# Usage:
# To utilize this script, you need to invoke it with specific commands
# and options as detailed below.
#
# Commands:
# -i, --install : Use this command to initiate the installation of all
# OpenIM components.
# -u, --uninstall : Use this command to uninstall or remove all
# OpenIM components from the server.
# -s, --status : This command can be used to check and report the
# current operational status of the installed OpenIM components.
# -h, --help : For any assistance or to view the available commands,
# use this command to display the help menu.
#
# Example Usage:
# To install all OpenIM components:
# ./scripts/install/install.sh -i
# or
# ./scripts/install/install.sh --install
#
# Note:
# Ensure you have the necessary privileges to execute installation or
# uninstallation operations. It's generally recommended to take a backup
# before making major changes.
#
###############################################################################
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
${OPENIM_ROOT}/scripts/install/openim-man.sh
${OPENIM_ROOT}/scripts/install/openim-tools.sh
${OPENIM_ROOT}/scripts/install/test.sh
# Detailed help function
function openim::install::show_help() {
echo "OpenIM Installer"
echo "Usage: $0 <command> [options]"
echo ""
echo "Commands:"
echo " -i, --install Install all OpenIM components."
echo " -u, --uninstall Remove all OpenIM components."
echo " -s, --status Check the current status of OpenIM components."
echo " -h, --help Show this help menu."
echo ""
echo "Example: "
echo " $0 -i Will install all OpenIM components."
echo " $0 --install Same as above."
}
function openim::install::install_openim() {
openim::common::sudo "mkdir -p ${OPENIM_DATA_DIR} ${OPENIM_INSTALL_DIR} ${OPENIM_CONFIG_DIR} ${OPENIM_LOG_DIR}"
openim::log::info "check openim dependency"
openim::common::sudo "cp -r ${OPENIM_ROOT}/config/* ${OPENIM_CONFIG_DIR}/"
${OPENIM_ROOT}/scripts/genconfig.sh ${ENV_FILE} ${OPENIM_ROOT}/deployments/templates/config.yaml > ${OPENIM_CONFIG_DIR}/config.yaml
${OPENIM_ROOT}/scripts/genconfig.sh ${ENV_FILE} ${OPENIM_ROOT}/deployments/templates/prometheus.yml > ${OPENIM_CONFIG_DIR}/prometheus.yml
openim::util::check_ports ${OPENIM_DEPENDENCY_PORT_LISTARIES[@]}
${OPENIM_ROOT}/scripts/install/openim-msggateway.sh openim::msggateway::install || return 1
${OPENIM_ROOT}/scripts/install/openim-msgtransfer.sh openim::msgtransfer::install || return 1
${OPENIM_ROOT}/scripts/install/openim-push.sh openim::push::install || return 1
${OPENIM_ROOT}/scripts/install/openim-crontask.sh openim::crontask::install || return 1
${OPENIM_ROOT}/scripts/install/openim-rpc.sh openim::rpc::install || return 1
${OPENIM_ROOT}/scripts/install/openim-api.sh openim::api::install || return 1
openim::common::sudo "cp -r ${OPENIM_ROOT}/deployments/templates/openim.target /etc/systemd/system/openim.target"
openim::common::sudo "systemctl daemon-reload"
openim::common::sudo "systemctl restart openim.target"
openim::common::sudo "systemctl enable openim.target"
openim::log::success "openim install success"
}
function openim::uninstall::uninstall_openim() {
openim::log::info "uninstall openim"
${OPENIM_ROOT}/scripts/install/openim-msggateway.sh openim::msggateway::uninstall || return 1
${OPENIM_ROOT}/scripts/install/openim-msgtransfer.sh openim::msgtransfer::uninstall || return 1
${OPENIM_ROOT}/scripts/install/openim-push.sh openim::push::uninstall || return 1
${OPENIM_ROOT}/scripts/install/openim-crontask.sh openim::crontask::uninstall || return 1
${OPENIM_ROOT}/scripts/install/openim-rpc.sh openim::rpc::uninstall || return 1
${OPENIM_ROOT}/scripts/install/openim-api.sh openim::api::uninstall || return 1
set +o errexit
openim::common::sudo "systemctl stop openim.target"
openim::common::sudo "systemctl disable openim.target"
openim::common::sudo "rm -f /etc/systemd/system/openim.target"
openim::log::success "openim uninstall success"
}
function openim::install::status() {
openim::log::info "check openim status"
${OPENIM_ROOT}/scripts/install/openim-msggateway.sh openim::msggateway::status || return 1
${OPENIM_ROOT}/scripts/install/openim-msgtransfer.sh openim::msgtransfer::status || return 1
${OPENIM_ROOT}/scripts/install/openim-push.sh openim::push::status || return 1
${OPENIM_ROOT}/scripts/install/openim-crontask.sh openim::crontask::status || return 1
${OPENIM_ROOT}/scripts/install/openim-rpc.sh openim::rpc::status || return 1
${OPENIM_ROOT}/scripts/install/openim-api.sh openim::api::status || return 1
openim::log::success "openim status success"
}
# If no arguments are provided, show help
if [[ $# -eq 0 ]]; then
openim::install::show_help
exit 0
fi
# Argument parsing to call functions based on user input
while (( "$#" )); do
case "$1" in
-i|--install)
openim::install::install_openim
shift
;;
-u|--uninstall)
openim::uninstall::uninstall_openim
shift
;;
-s|--status)
openim::install::status
shift
;;
-h|--help|*)
openim::install::show_help
exit 0
;;
esac
done

@ -1,169 +0,0 @@
#!/usr/bin/env bash
# Copyright © 2023 OpenIM. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
SERVER_NAME="openim-api"
readonly OPENIM_API_PORT_TARGETS=(
${API_OPENIM_PORT}
)
readonly OPENIM_API_PORT_LISTARIES=("${OPENIM_API_PORT_TARGETS[@]##*/}")
readonly OPENIM_API_SERVICE_TARGETS=(
openim-api
)
readonly OPENIM_API_SERVICE_LISTARIES=("${OPENIM_API_SERVICE_TARGETS[@]##*/}")
readonly OPENIM_API_PROMETHEUS_PORT_TARGETS=(
${API_PROM_PORT}
)
readonly OPENIM_API_PROMETHEUS_PORT_LISTARIES=("${OPENIM_API_PROMETHEUS_PORT_TARGETS[@]##*/}")
function openim::api::start() {
rm -rf "$TMP_LOG_FILE"
echo "++ OPENIM_API_SERVICE_LISTARIES: ${OPENIM_API_SERVICE_LISTARIES[@]}"
echo "++ OPENIM_API_PORT_LISTARIES: ${OPENIM_API_PORT_LISTARIES[@]}"
echo "++ OpenIM API config path: ${OPENIM_API_CONFIG}"
openim::log::info "Starting ${SERVER_NAME} ..."
readonly OPENIM_API_SERVER_LIBRARIES="${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME}"
printf "+------------------------+--------------+\n"
printf "| Service Name | Port |\n"
printf "+------------------------+--------------+\n"
local length=${#OPENIM_API_SERVICE_LISTARIES[@]}
for ((i=0; i<length; i++)); do
printf "| %-22s | %6s |\n" "${OPENIM_API_SERVICE_LISTARIES[$i]}" "${OPENIM_API_PORT_LISTARIES[$i]}"
printf "+------------------------+--------------+\n"
# Stop services on the specified ports before starting new ones
openim::log::info "OpenIM ${OPENIM_API_SERVICE_LISTARIES[$i]} config path: ${OPENIM_API_CONFIG}"
# Start the service with Prometheus port if specified
result=$(openim::api::start_service "${OPENIM_API_SERVICE_LISTARIES[$i]}" "${OPENIM_API_PORT_LISTARIES[$i]}" "${OPENIM_API_PROMETHEUS_PORT_LISTARIES[$i]}")
if [[ $? -ne 0 ]]; then
openim::log::error "stop ${SERVER_NAME} failed"
else
openim::log::info "$result"
fi
done
return 0
}
function openim::api::start_service() {
local binary_name="$1"
local service_port="$2"
local prometheus_port="$3"
local cmd="${OPENIM_OUTPUT_HOSTBIN}/${binary_name} --port ${service_port} -c ${OPENIM_API_CONFIG}"
# Append Prometheus port argument if specified
if [ -n "${prometheus_port}" ]; then
cmd+=" --prometheus_port ${prometheus_port}"
fi
echo "Starting service with command: $cmd"
#nohup $cmd >> "${LOG_FILE}" 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE" >&2) &
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >> "${LOG_FILE}" 2>&1 &
if [ $? -ne 0 ]; then
openim::log::error_exit "Failed to start ${binary_name} on port ${service_port}."
return 1
fi
return 0
}
###################################### Linux Systemd ######################################
SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service"
# Print the necessary information after installation
function openim::api::info() {
cat << EOF
openim-api listen on: ${OPENIM_API_HOST}:${API_OPENIM_PORT}
EOF
}
# install openim-api
function openim::api::install() {
openim::log::info "Installing ${SERVER_NAME} ..."
pushd "${OPENIM_ROOT}"
# 1. Build openim-api
make build BINS=${SERVER_NAME}
openim::common::sudo "cp -r ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/${SERVER_NAME}/${SERVER_NAME}"
# 2. Generate and install the openim-api configuration file (config)
openim::log::status "${SERVER_NAME} config file: ${OPENIM_CONFIG_DIR}/config.yaml"
# 3. Create and install the ${SERVER_NAME} systemd unit file
echo ${LINUX_PASSWORD} | sudo -S bash -c \
"SERVER_NAME=${SERVER_NAME} ./scripts/genconfig.sh ${ENV_FILE} deployments/templates/openim.service > ${SYSTEM_FILE_PATH}"
openim::log::status "${SERVER_NAME} systemd file: ${SYSTEM_FILE_PATH}"
# 4. Start the openim-api service
openim::common::sudo "systemctl daemon-reload"
openim::common::sudo "systemctl restart ${SERVER_NAME}"
openim::common::sudo "systemctl enable ${SERVER_NAME}"
openim::api::status || return 1
openim::api::info
openim::log::info "install ${SERVER_NAME} successfully"
popd
}
# Unload
function openim::api::uninstall() {
openim::log::info "Uninstalling ${SERVER_NAME} ..."
set +o errexit
openim::common::sudo "systemctl stop ${SERVER_NAME}"
openim::common::sudo "systemctl disable ${SERVER_NAME}"
openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
openim::common::sudo "rm -f /etc/systemd/system/${SERVER_NAME}.service"
openim::log::info "uninstall ${SERVER_NAME} successfully"
}
# Status Check
function openim::api::status() {
openim::log::info "Checking ${SERVER_NAME} status ..."
# Check the running status of the ${SERVER_NAME}. If active (running) is displayed, the ${SERVER_NAME} is started successfully.
systemctl status ${SERVER_NAME}|grep -q 'active' || {
openim::log::error "${SERVER_NAME} failed to start, maybe not installed properly"
return 1
}
openim::util::check_ports ${OPENIM_API_PORT_LISTARIES[@]}
}
if [[ "$*" =~ openim::api:: ]];then
eval $*
fi

@ -1,126 +0,0 @@
#!/usr/bin/env bash
# Copyright © 2023 OpenIM. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# OpenIM CronTask Control Script
#
# Description:
# This script provides a control interface for the OpenIM CronTask service within a Linux environment. It supports two installation methods: installation via function calls to systemctl, and direct installation through background processes.
#
# Features:
# 1. Robust error handling leveraging Bash built-ins such as 'errexit', 'nounset', and 'pipefail'.
# 2. Capability to source common utility functions and configurations, ensuring environmental consistency.
# 3. Comprehensive logging tools, offering clear operational insights.
# 4. Support for creating, managing, and interacting with Linux systemd services.
# 5. Mechanisms to verify the successful running of the service.
#
# Usage:
# 1. Direct Script Execution:
# This will start the OpenIM CronTask directly through a background process.
# Example: ./openim-crontask.sh openim::crontask::start
#
# 2. Controlling through Functions for systemctl operations:
# Specific operations like installation, uninstallation, and status check can be executed by passing the respective function name as an argument to the script.
# Example: ./openim-crontask.sh openim::crontask::install
#
# Note: Ensure that the appropriate permissions and environmental variables are set prior to script execution.
#
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
SERVER_NAME="openim-crontask"
function openim::crontask::start() {
rm -rf "$TMP_LOG_FILE"
openim::log::info "Start OpenIM Cron, binary root: ${SERVER_NAME}"
openim::log::status "Start OpenIM Cron, path: ${OPENIM_CRONTASK_BINARY}"
openim::log::status "start cron_task process, path: ${OPENIM_CRONTASK_BINARY}"
#nohup ${OPENIM_CRONTASK_BINARY} -c ${OPENIM_PUSH_CONFIG} >> ${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE" >&2) &
cmd="${OPENIM_CRONTASK_BINARY} -c ${OPENIM_PUSH_CONFIG}"
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >> "${LOG_FILE}" 2>&1 &
return 0
}
###################################### Linux Systemd ######################################
SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service"
# Print the necessary information after installation
function openim::crontask::info() {
cat << EOF
openim-crontask listen on: ${OPENIM_CRONTASK_HOST}
EOF
}
# install openim-crontask
function openim::crontask::install() {
pushd "${OPENIM_ROOT}"
# 1. Build openim-crontask
make build BINS=${SERVER_NAME}
openim::common::sudo "cp -r ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/${SERVER_NAME}/${SERVER_NAME}"
# 2. Generate and install the openim-crontask configuration file (openim-crontask.yaml)
openim::log::status "${SERVER_NAME} config file: ${OPENIM_CONFIG_DIR}/config.yaml"
# 3. Create and install the ${SERVER_NAME} systemd unit file
echo ${LINUX_PASSWORD} | sudo -S bash -c \
"SERVER_NAME=${SERVER_NAME} ./scripts/genconfig.sh ${ENV_FILE} deployments/templates/openim.service > ${SYSTEM_FILE_PATH}"
openim::log::status "${SERVER_NAME} systemd file: ${SYSTEM_FILE_PATH}"
# 4. Start the openim-crontask service
openim::common::sudo "systemctl daemon-reload"
openim::common::sudo "systemctl restart ${SERVER_NAME}"
openim::common::sudo "systemctl enable ${SERVER_NAME}"
openim::crontask::status || return 1
openim::crontask::info
openim::log::info "install ${SERVER_NAME} successfully"
popd
}
# Unload
function openim::crontask::uninstall() {
set +o errexit
openim::common::sudo "systemctl stop ${SERVER_NAME}"
openim::common::sudo "systemctl disable ${SERVER_NAME}"
openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
openim::common::sudo "rm -f /etc/systemd/system/${SERVER_NAME}.service"
openim::log::info "uninstall ${SERVER_NAME} successfully"
}
# Status Check
function openim::crontask::status() {
# Check the running status of the ${SERVER_NAME}. If active (running) is displayed, the ${SERVER_NAME} is started successfully.
if systemctl is-active --quiet "${SERVER_NAME}"; then
openim::log::info "${SERVER_NAME} is running successfully."
else
openim::log::error "${SERVER_NAME} failed to start, maybe not installed properly"
return 1
fi
}
if [[ "$*" =~ openim::crontask:: ]];then
eval $*
fi

@ -1,141 +0,0 @@
#!/usr/bin/env bash
# Copyright © 2023 OpenIM. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Common utilities, variables and checks for all build scripts.
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
SERVER_NAME="openim-msggateway"
function openim::msggateway::start() {
rm -rf "$TMP_LOG_FILE"
openim::log::info "Start OpenIM Msggateway, binary root: ${SERVER_NAME}"
openim::log::status "Start OpenIM Msggateway, path: ${OPENIM_MSGGATEWAY_BINARY}"
# OpenIM message gateway service port
OPENIM_MESSAGE_GATEWAY_PORTS=$(openim::util::list-to-string ${OPENIM_MESSAGE_GATEWAY_PORT} )
read -a OPENIM_MSGGATEWAY_PORTS_ARRAY <<< ${OPENIM_MESSAGE_GATEWAY_PORTS}
openim::util::stop_services_on_ports ${OPENIM_MSGGATEWAY_PORTS_ARRAY[*]}
# OpenIM WS port
OPENIM_WS_PORTS=$(openim::util::list-to-string ${OPENIM_WS_PORT} )
read -a OPENIM_WS_PORTS_ARRAY <<< ${OPENIM_WS_PORTS}
# Message Gateway Prometheus port of the service
MSG_GATEWAY_PROM_PORTS=$(openim::util::list-to-string ${MSG_GATEWAY_PROM_PORT} )
read -a MSG_GATEWAY_PROM_PORTS_ARRAY <<< ${MSG_GATEWAY_PROM_PORTS}
openim::log::status "OpenIM Mssage Getway ports: ${OPENIM_MESSAGE_GATEWAY_PORTS[*]}"
openim::log::status "OpenIM WS ports: ${OPENIM_WS_PORTS[*]}"
openim::log::status "OpenIM Prometheus ports: ${MSG_GATEWAY_PROM_PORTS[*]}"
openim::log::status "OpenIM Msggateway config path: ${OPENIM_MSGGATEWAY_CONFIG}"
if [ ${#OPENIM_MSGGATEWAY_PORTS_ARRAY[@]} -ne ${#OPENIM_WS_PORTS_ARRAY[@]} ]; then
openim::log::error_exit "ws_ports does not match push_rpc_ports or prome_ports in quantity!!!"
fi
for ((i = 0; i < ${#OPENIM_WS_PORTS_ARRAY[@]}; i++)); do
openim::log::info "start push process, port: ${OPENIM_MSGGATEWAY_PORTS_ARRAY[$i]}, prometheus port: ${MSG_GATEWAY_PROM_PORTS_ARRAY[$i]}"
PROMETHEUS_PORT_OPTION=""
if [[ -n "${MSG_GATEWAY_PROM_PORTS_ARRAY[$i]}" ]]; then
PROMETHEUS_PORT_OPTION="--prometheus_port ${MSG_GATEWAY_PROM_PORTS_ARRAY[$i]}"
fi
cmd="${OPENIM_MSGGATEWAY_BINARY} --port ${OPENIM_MSGGATEWAY_PORTS_ARRAY[$i]} --ws_port ${OPENIM_WS_PORTS_ARRAY[$i]} $PROMETHEUS_PORT_OPTION -c ${OPENIM_MSGGATEWAY_CONFIG}"
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >> "${LOG_FILE}" 2>&1 &
# nohup ${OPENIM_MSGGATEWAY_BINARY} --port ${OPENIM_MSGGATEWAY_PORTS_ARRAY[$i]} --ws_port ${OPENIM_WS_PORTS_ARRAY[$i]} $PROMETHEUS_PORT_OPTION -c ${OPENIM_MSGGATEWAY_CONFIG} >> ${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE" >&2) &
done
return 0
}
###################################### Linux Systemd ######################################
SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service"
# Print the necessary information after installation
function openim::msggateway::info() {
cat << EOF
openim-msggateway listen on: ${OPENIM_MSGGATEWAY_HOST}:${OPENIM_MESSAGE_GATEWAY_PORT}
EOF
}
# install openim-msggateway
function openim::msggateway::install() {
pushd "${OPENIM_ROOT}"
# 1. Build openim-msggateway
make build BINS=${SERVER_NAME}
openim::common::sudo "cp -r ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
# 2. Generate and install the openim-msggateway configuration file (openim-msggateway.yaml)
# nono
# 3. Create and install the ${SERVER_NAME} systemd unit file
echo ${LINUX_PASSWORD} | sudo -S bash -c \
"SERVER_NAME=${SERVER_NAME} ./scripts/genconfig.sh ${ENV_FILE} deployments/templates/openim.service > ${SYSTEM_FILE_PATH}"
openim::log::status "${SERVER_NAME} systemd file: ${SYSTEM_FILE_PATH}"
# 4. Start the openim-msggateway service
openim::common::sudo "systemctl daemon-reload"
openim::common::sudo "systemctl restart ${SERVER_NAME}"
openim::common::sudo "systemctl enable ${SERVER_NAME}"
openim::msggateway::status || return 1
openim::msggateway::info
openim::log::info "install ${SERVER_NAME} successfully"
popd
}
# Unload
function openim::msggateway::uninstall() {
set +o errexit
openim::common::sudo "systemctl stop ${SERVER_NAME}"
openim::common::sudo "systemctl disable ${SERVER_NAME}"
openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
openim::common::sudo "rm -f /etc/systemd/system/${SERVER_NAME}.service"
openim::log::info "uninstall ${SERVER_NAME} successfully"
}
# Status Check
function openim::msggateway::status() {
# Check the running status of the ${SERVER_NAME}. If active (running) is displayed, the ${SERVER_NAME} is started successfully.
systemctl status ${SERVER_NAME}|grep -q 'active' || {
openim::log::error "${SERVER_NAME} failed to start, maybe not installed properly"
return 1
}
# The listening port is hardcode in the configuration file
if echo | telnet ${OPENIM_MSGGATEWAY_HOST} ${OPENIM_MESSAGE_GATEWAY_PORT} 2>&1|grep refused &>/dev/null;then
openim::log::error "cannot access health check port, ${SERVER_NAME} maybe not startup"
return 1
fi
}
if [[ "$*" =~ openim::msggateway:: ]];then
eval $*
fi

@ -1,186 +0,0 @@
#!/usr/bin/env bash
# Copyright © 2023 OpenIM. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Use:
# ./scripts/install/openim-msgtransfer.sh openim::msgtransfer::start
# Common utilities, variables and checks for all build scripts.
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
SERVER_NAME="openim-msgtransfer"
function openim::msgtransfer::start() {
rm -rf "$TMP_LOG_FILE"
openim::log::info "Start OpenIM Msggateway, binary root: ${SERVER_NAME}"
openim::log::status "Start OpenIM Msggateway, path: ${OPENIM_MSGTRANSFER_BINARY}"
# Message Transfer Prometheus port list
MSG_TRANSFER_PROM_PORTS=(openim::util::list-to-string ${MSG_TRANSFER_PROM_PORT} )
openim::log::status "OpenIM Prometheus ports: ${MSG_TRANSFER_PROM_PORTS[*]}"
openim::log::status "OpenIM Msggateway config path: ${OPENIM_MSGTRANSFER_CONFIG}"
openim::log::info "openim maggateway num: ${OPENIM_MSGGATEWAY_NUM}"
if [ "${OPENIM_MSGGATEWAY_NUM}" -lt 1 ]; then
opeim::log::error "OPENIM_MSGGATEWAY_NUM must be greater than 0"
fi
if [ ${OPENIM_MSGGATEWAY_NUM} -ne $((${#MSG_TRANSFER_PROM_PORTS[@]} - 1)) ]; then
openim::log::error "OPENIM_MSGGATEWAY_NUM must be equal to the number of MSG_TRANSFER_PROM_PORTS"
fi
for (( i=0; i<$OPENIM_MSGGATEWAY_NUM; i++ )) do
openim::log::info "prometheus port: ${MSG_TRANSFER_PROM_PORTS[$i]}"
PROMETHEUS_PORT_OPTION=""
if [[ -n "${MSG_TRANSFER_PROM_PORTS[$i+1]}" ]]; then
PROMETHEUS_MSG_TRANSFER_PORT="${MSG_TRANSFER_PROM_PORTS[$i+1]%,}"
openim::util::stop_services_on_ports ${PROMETHEUS_MSG_TRANSFER_PORT}
PROMETHEUS_PORT_OPTION="--prometheus_port ${PROMETHEUS_MSG_TRANSFER_PORT}"
fi
cmd="${OPENIM_MSGTRANSFER_BINARY} ${PROMETHEUS_PORT_OPTION} -c ${OPENIM_MSGTRANSFER_CONFIG} -n ${i}"
#nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >/dev/null &
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >> "${LOG_FILE}" 2>&1 &
#nohup ${OPENIM_MSGTRANSFER_BINARY} ${PROMETHEUS_PORT_OPTION} -c ${OPENIM_MSGTRANSFER_CONFIG} -n ${i} >> ${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE" >&2) &
done
return 0
}
function openim::msgtransfer::check() {
PIDS=$(pgrep -f "${OPENIM_OUTPUT_HOSTBIN}/openim-msgtransfer")
if [ -z "$PIDS" ]; then
NUM_PROCESSES=0
else
NUM_PROCESSES=$(echo "$PIDS" | wc -l)
fi
if [ "$NUM_PROCESSES" -eq "$OPENIM_MSGGATEWAY_NUM" ]; then
for PID in $PIDS; do
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
ps -p $PID -o pid,cmd
elif [[ "$OSTYPE" == "darwin"* ]]; then
ps -p $PID -o pid,comm
else
openim::log::error "Unsupported OS type: $OSTYPE"
fi
done
else
openim::log::error "Expected $OPENIM_MSGGATEWAY_NUM OpenIM msgtransfer processes, but found $NUM_PROCESSES msgtransfer processes running"
return 1
fi
return 0
}
function openim::msgtransfer::check_for_stop() {
PIDS=$(pgrep -f "${OPENIM_OUTPUT_HOSTBIN}/openim-msgtransfer") || PIDS="0"
if [ "$PIDS" = "0" ]; then
return 0
fi
NUM_PROCESSES=$(echo "$PIDS" | wc -l | xargs)
if [ "$NUM_PROCESSES" -gt 0 ]; then
openim::log::error "Found $NUM_PROCESSES processes for $OPENIM_OUTPUT_HOSTBIN/openim-msgtransfer"
for PID in $PIDS; do
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
echo -e "\033[31m$(ps -p $PID -o pid,cmd)\033[0m"
elif [[ "$OSTYPE" == "darwin"* ]]; then
echo -e "\033[31m$(ps -p $PID -o pid,comm)\033[0m"
else
openim::log::error "Unsupported OS type: $OSTYPE"
fi
done
openim::log::error "Processes have not been stopped properly."
else
openim::log::success "All openim-msgtransfer processes have been stopped properly."
fi
return 0
}
###################################### Linux Systemd ######################################
SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service"
# Print the necessary information after installation
function openim::msgtransfer::info() {
cat << EOF
openim-msgtransfer listen on: ${OPENIM_MSGTRANSFER_HOST}
EOF
}
# install openim-msgtransfer
function openim::msgtransfer::install() {
pushd "${OPENIM_ROOT}"
# 1. Build openim-msgtransfer
make build BINS=${SERVER_NAME}
openim::common::sudo "cp -r ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/${SERVER_NAME}/${SERVER_NAME}"
openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/bin/${SERVER_NAME}"
# 2. Generate and install the openim-msgtransfer configuration file (openim-msgtransfer.yaml)
# nono
# 3. Create and install the ${SERVER_NAME} systemd unit file
echo ${LINUX_PASSWORD} | sudo -S bash -c \
"SERVER_NAME=${SERVER_NAME} ./scripts/genconfig.sh ${ENV_FILE} deployments/templates/openim.service > ${SYSTEM_FILE_PATH}"
openim::log::status "${SERVER_NAME} systemd file: ${SYSTEM_FILE_PATH}"
# 4. Start the openim-msgtransfer service
openim::common::sudo "systemctl daemon-reload"
openim::common::sudo "systemctl restart ${SERVER_NAME}"
openim::common::sudo "systemctl enable ${SERVER_NAME}"
openim::msgtransfer::status || return 1
openim::msgtransfer::info
openim::log::info "install ${SERVER_NAME} successfully"
popd
}
# Unload
function openim::msgtransfer::uninstall() {
set +o errexit
openim::common::sudo "systemctl stop ${SERVER_NAME}"
openim::common::sudo "systemctl disable ${SERVER_NAME}"
openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
openim::common::sudo "rm -f /etc/systemd/system/${SERVER_NAME}.service"
openim::log::info "uninstall ${SERVER_NAME} successfully"
}
# Status Check
function openim::msgtransfer::status() {
# Check the running status of the ${SERVER_NAME}. If active (running) is displayed, the ${SERVER_NAME} is started successfully.
if systemctl is-active --quiet "${SERVER_NAME}"; then
openim::log::info "${SERVER_NAME} is running successfully."
else
openim::log::error "${SERVER_NAME} failed to start, maybe not installed properly"
return 1
fi
}
if [[ "$*" =~ openim::msgtransfer:: ]];then
eval $*
fi

@ -1,150 +0,0 @@
#!/usr/bin/env bash
# Copyright © 2023 OpenIM. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# OpenIM Push Control Script
#
# Description:
# This script provides a control interface for the OpenIM Push service within a Linux environment. It supports two installation methods: installation via function calls to systemctl, and direct installation through background processes.
#
# Features:
# 1. Robust error handling leveraging Bash built-ins such as 'errexit', 'nounset', and 'pipefail'.
# 2. Capability to source common utility functions and configurations, ensuring environmental consistency.
# 3. Comprehensive logging tools, offering clear operational insights.
# 4. Support for creating, managing, and interacting with Linux systemd services.
# 5. Mechanisms to verify the successful running of the service.
#
# Usage:
# 1. Direct Script Execution:
# This will start the OpenIM push directly through a background process.
# Example: ./openim-push.sh
#
# 2. Controlling through Functions for systemctl operations:
# Specific operations like installation, uninstallation, and status check can be executed by passing the respective function name as an argument to the script.
# Example: ./openim-push.sh openim::push::install
#
# ENVIRONMENT VARIABLES:
# export OPENIM_PUSH_BINARY="8080 8081 8082"
# export OPENIM_PUSH_PORT="9090 9091 9092"
#
# Note: Ensure that the appropriate permissions and environmental variables are set prior to script execution.
#
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
SERVER_NAME="openim-push"
function openim::push::start() {
rm -rf "$TMP_LOG_FILE"
openim::log::status "Start OpenIM Push, binary root: ${SERVER_NAME}"
openim::log::info "Start OpenIM Push, path: ${OPENIM_PUSH_BINARY}"
openim::log::status "prepare start push process, path: ${OPENIM_PUSH_BINARY}"
openim::log::status "prepare start push process, port: ${OPENIM_PUSH_PORT}, prometheus port: ${PUSH_PROM_PORT}"
OPENIM_PUSH_PORTS_ARRAY=$(openim::util::list-to-string ${OPENIM_PUSH_PORT} )
PUSH_PROM_PORTS_ARRAY=$(openim::util::list-to-string ${PUSH_PROM_PORT} )
openim::log::status "push port list: ${OPENIM_PUSH_PORTS_ARRAY[@]}"
openim::log::status "prometheus port list: ${PUSH_PROM_PORTS_ARRAY[@]}"
if [ ${#OPENIM_PUSH_PORTS_ARRAY[@]} -ne ${#PUSH_PROM_PORTS_ARRAY[@]} ]; then
openim::log::error "The length of the two port lists is different!"
fi
for (( i=0; i<${#OPENIM_PUSH_PORTS_ARRAY[@]}; i++ )); do
openim::log::info "start push process, port: ${OPENIM_PUSH_PORTS_ARRAY[$i]}, prometheus port: ${PUSH_PROM_PORTS_ARRAY[$i]}"
cmd="${OPENIM_PUSH_BINARY} --port ${OPENIM_PUSH_PORTS_ARRAY[$i]} -c ${OPENIM_PUSH_CONFIG} --prometheus_port ${PUSH_PROM_PORTS_ARRAY[$i]}"
#nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >/dev/null &
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >> "${LOG_FILE}" 2>&1 &
#nohup ${OPENIM_PUSH_BINARY} --port ${OPENIM_PUSH_PORTS_ARRAY[$i]} -c ${OPENIM_PUSH_CONFIG} --prometheus_port ${PUSH_PROM_PORTS_ARRAY[$i]} >> ${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE" >&2) &
done
return 0
}
###################################### Linux Systemd ######################################
SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service"
# Print the necessary information after installation
function openim::push::info() {
cat << EOF
openim-push listen on: ${OPENIM_PUSH_HOST}:${OPENIM_PUSH_PORT}
EOF
}
# install openim-push
function openim::push::install() {
pushd "${OPENIM_ROOT}"
# 1. Build openim-push
make build BINS=${SERVER_NAME}
openim::common::sudo "cp -r ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
openim::log::status "${SERVER_NAME} binary: ${OPENIM_INSTALL_DIR}/${SERVER_NAME}/${SERVER_NAME}"
# 2. Generate and install the openim-push configuration file (config)
openim::log::status "${SERVER_NAME} config file: ${OPENIM_CONFIG_DIR}/config.yaml"
# 3. Create and install the ${SERVER_NAME} systemd unit file
echo ${LINUX_PASSWORD} | sudo -S bash -c \
"SERVER_NAME=${SERVER_NAME} ./scripts/genconfig.sh ${ENV_FILE} deployments/templates/openim.service > ${SYSTEM_FILE_PATH}"
openim::log::status "${SERVER_NAME} systemd file: ${SYSTEM_FILE_PATH}"
# 4. Start the openim-push service
openim::common::sudo "systemctl daemon-reload"
openim::common::sudo "systemctl restart ${SERVER_NAME}"
openim::common::sudo "systemctl enable ${SERVER_NAME}"
openim::push::status || return 1
openim::push::info
openim::log::info "install ${SERVER_NAME} successfully"
popd
}
# Unload
function openim::push::uninstall() {
set +o errexit
openim::common::sudo "systemctl stop ${SERVER_NAME}"
openim::common::sudo "systemctl disable ${SERVER_NAME}"
openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
openim::common::sudo "rm -f /etc/systemd/system/${SERVER_NAME}.service"
openim::log::info "uninstall ${SERVER_NAME} successfully"
}
# Status Check
function openim::push::status() {
# Check the running status of the ${SERVER_NAME}. If active (running) is displayed, the ${SERVER_NAME} is started successfully.
systemctl status ${SERVER_NAME}|grep -q 'active' || {
openim::log::error "${SERVER_NAME} failed to start, maybe not installed properly"
return 1
}
# The listening port is hardcode in the configuration file
if echo | telnet ${OPENIM_MSGGATEWAY_HOST} ${OPENIM_PUSH_PORT} 2>&1|grep refused &>/dev/null;then # Assuming a different port for push
openim::log::error "cannot access health check port, ${SERVER_NAME} maybe not startup"
return 1
fi
}
if [[ "$*" =~ openim::push:: ]];then
eval $*
fi

@ -1,254 +0,0 @@
#!/usr/bin/env bash
# Copyright © 2023 OpenIM. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# OpenIM RPC Service Control Script
#
# Description:
# This script provides a control interface for the OpenIM RPC service within a Linux environment. It offers functionalities to start multiple RPC services, each denoted by their respective names under openim::rpc::service_name.
#
# Features:
# 1. Robust error handling using Bash built-ins like 'errexit', 'nounset', and 'pipefail'.
# 2. The capability to source common utility functions and configurations to ensure uniform environmental settings.
# 3. Comprehensive logging functionalities, providing a detailed understanding of operational processes.
# 4. Provision for declaring and managing a set of RPC services, each associated with its unique name and corresponding ports.
# 5. The ability to define and associate Prometheus ports for service monitoring purposes.
# 6. Functionalities to start each RPC service, along with its designated ports, in a sequence.
#
# Usage:
# 1. Direct Script Execution:
# This initiates all the RPC services declared under the function openim::rpc::service_name.
# Example: ./openim-rpc-{rpc-name}.sh openim::rpc::start
# 2. Controlling through Functions for systemctl operations:
# Specific operations like installation, uninstallation, and status check can be executed by passing the respective function name as an argument to the script.
# Example: ./openim-rpc-{rpc-name}.sh openim::rpc::install
#
# Note: Before executing this script, ensure that the necessary permissions are granted and relevant environmental variables are set.
#
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
SERVER_NAME="openim-rpc"
readonly OPENIM_RPC_CONFIG="${OPENIM_ROOT}"/config
openim::rpc::service_name() {
local targets=(
openim-rpc-user
openim-rpc-friend
openim-rpc-msg
openim-rpc-group
openim-rpc-auth
openim-rpc-conversation
openim-rpc-third
)
echo "${targets[@]}"
}
IFS=" " read -ra OPENIM_RPC_SERVICE_TARGETS <<< "$(openim::rpc::service_name)"
readonly OPENIM_RPC_SERVICE_TARGETS
readonly OPENIM_RPC_SERVICE_LISTARIES=("${OPENIM_RPC_SERVICE_TARGETS[@]##*/}")
OPENIM_ALL_RPC_FULL_PATH=()
for target in openim::rpc::service_name; do
OPENIM_ALL_RPC_FULL_PATH+=("${OPENIM_OUTPUT_HOSTBIN}/${target}")
done
readonly OPENIM_ALL_RPC_FULL_PATH
# Make sure the environment is only called via common to avoid too much nesting
openim::rpc::service_port() {
local targets=(
${OPENIM_USER_PORT} # User service 10110
${OPENIM_FRIEND_PORT} # Friend service 10120
${OPENIM_MESSAGE_PORT} # Message service 10130
# ${OPENIM_MESSAGE_GATEWAY_PORT} # Message gateway 10140
${OPENIM_GROUP_PORT} # Group service 10150
${OPENIM_AUTH_PORT} # Authorization service 10160
# ${OPENIM_PUSH_PORT} # Push service 10170
${OPENIM_CONVERSATION_PORT} # Conversation service 10180
${OPENIM_THIRD_PORT} # Third-party service 10190
)
echo "${targets[@]}"
}
IFS=" " read -ra OPENIM_RPC_PORT_TARGETS <<< "$(openim::rpc::service_port)"
readonly OPENIM_RPC_PORT_TARGETS
readonly OPENIM_RPC_PORT_LISTARIES=("${OPENIM_RPC_PORT_TARGETS[@]##*/}")
openim::rpc::prometheus_port() {
# Declare an array to hold all the Prometheus ports for different services
local targets=(
${USER_PROM_PORT} # Prometheus port for user service
${FRIEND_PROM_PORT} # Prometheus port for friend service
${MESSAGE_PROM_PORT} # Prometheus port for message service
${GROUP_PROM_PORT} # Prometheus port for group service
${AUTH_PROM_PORT} # Prometheus port for authentication service
${CONVERSATION_PROM_PORT} # Prometheus port for conversation service
${THIRD_PROM_PORT} # Prometheus port for third-party integrations service
)
# Print the list of ports
echo "${targets[@]}"
}
IFS=" " read -ra OPENIM_RPC_PROM_PORT_TARGETS <<< "$(openim::rpc::prometheus_port)"
readonly OPENIM_RPC_PROM_PORT_TARGETS
readonly OPENIM_RPC_PROM_PORT_LISTARIES=("${OPENIM_RPC_PROM_PORT_TARGETS[@]##*/}")
function openim::rpc::start() {
rm -rf "$TMP_LOG_FILE"
echo "OPENIM_RPC_SERVICE_LISTARIES: ${OPENIM_RPC_SERVICE_LISTARIES[@]}"
echo "OPENIM_RPC_PROM_PORT_LISTARIES: ${OPENIM_RPC_PROM_PORT_LISTARIES[@]}"
echo "OPENIM_RPC_PORT_LISTARIES: ${OPENIM_RPC_PORT_LISTARIES[@]}"
openim::log::info "Starting ${SERVER_NAME} ..."
printf "+------------------------+-------+-----------------+\n"
printf "| Service Name | Port | Prometheus Port |\n"
printf "+------------------------+-------+-----------------+\n"
length=${#OPENIM_RPC_SERVICE_LISTARIES[@]}
for ((i=0; i<$length; i++)); do
printf "| %-22s | %-5s | %-15s |\n" "${OPENIM_RPC_SERVICE_LISTARIES[$i]}" "${OPENIM_RPC_PORT_LISTARIES[$i]}" "${OPENIM_RPC_PROM_PORT_LISTARIES[$i]}"
printf "+------------------------+-------+-----------------+\n"
done
# start all rpc services
for ((i = 0; i < ${#OPENIM_RPC_SERVICE_LISTARIES[*]}; i++)); do
openim::log::info "OpenIM ${OPENIM_RPC_SERVICE_LISTARIES[$i]} config path: ${OPENIM_RPC_CONFIG}"
# Get the service and Prometheus ports.
OPENIM_RPC_SERVICE_PORTS=( $(openim::util::list-to-string ${OPENIM_RPC_PORT_LISTARIES[$i]}) )
read -a OPENIM_RPC_SERVICE_PORTS_ARRAY <<< ${OPENIM_RPC_SERVICE_PORTS}
OPENIM_RPC_PROM_PORTS=( $(openim::util::list-to-string ${OPENIM_RPC_PROM_PORT_LISTARIES[$i]}) )
read -a OPENIM_RPC_PROM_PORTS_ARRAY <<< ${OPENIM_RPC_PROM_PORTS}
for ((j = 0; j < ${#OPENIM_RPC_SERVICE_PORTS_ARRAY[@]}; j++)); do
openim::log::info "Starting ${OPENIM_RPC_SERVICE_LISTARIES[$i]} service, port: ${OPENIM_RPC_SERVICE_PORTS[j]}, prometheus port: ${OPENIM_RPC_PROM_PORTS[j]}, binary root: ${OPENIM_OUTPUT_HOSTBIN}/${OPENIM_RPC_SERVICE_LISTARIES[$i]}"
result=$(openim::rpc::start_service "${OPENIM_RPC_SERVICE_LISTARIES[$i]}" "${OPENIM_RPC_SERVICE_PORTS[j]}" "${OPENIM_RPC_PROM_PORTS[j]}")
if [[ $? -ne 0 ]]; then
openim::log::error "start ${SERVER_NAME} failed"
else
openim::log::info "$result"
fi
done
done
return 0
}
function openim::rpc::start_service() {
local binary_name="$1"
local service_port="$2"
local prometheus_port="$3"
local cmd="${OPENIM_OUTPUT_HOSTBIN}/${binary_name} --port ${service_port} -c ${OPENIM_RPC_CONFIG}"
if [ -n "${prometheus_port}" ]; then
printf "Specifying prometheus port: %s\n" "${prometheus_port}"
cmd="${cmd} --prometheus_port ${prometheus_port}"
fi
#nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE" >&2) &
#nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >/dev/null &
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >> "${LOG_FILE}" 2>&1 &
return 0
}
###################################### Linux Systemd ######################################
declare -A SYSTEM_FILE_PATHS
for service in "${OPENIM_RPC_SERVICE_LISTARIES[@]}"; do
SYSTEM_FILE_PATHS["$service"]="/etc/systemd/system/${service}.service"
done
# Print the necessary information after installation
function openim::rpc::info() {
for service in "${OPENIM_RPC_SERVICE_LISTARIES[@]}"; do
echo "${service} listen on: ${OPENIM_RPC_PORT_LISTARIES[@]}"
done
}
# install openim-rpc
function openim::rpc::install() {
pushd "${OPENIM_ROOT}"
# 1. Build openim-rpc
for service in "${OPENIM_RPC_SERVICE_LISTARIES[@]}"; do
make build BINS=${service}
openim::common::sudo "cp -r ${OPENIM_OUTPUT_HOSTBIN}/${service} ${OPENIM_INSTALL_DIR}/${service}"
openim::log::status "${service} binary: ${OPENIM_INSTALL_DIR}/${service}/${service}"
done
# 2. Generate and install the openim-rpc configuration file (config)
openim::log::status "openim-rpc config file: ${OPENIM_CONFIG_DIR}/config.yaml"
# 3. Create and install the systemd unit files
for service in "${OPENIM_RPC_SERVICE_LISTARIES[@]}"; do
echo ${LINUX_PASSWORD} | sudo -S bash -c \
"SERVER_NAME=${service} ./scripts/genconfig.sh ${ENV_FILE} deployments/templates/openim.service > ${SYSTEM_FILE_PATHS[$service]}"
openim::log::status "${service} systemd file: ${SYSTEM_FILE_PATHS[$service]}"
done
# 4. Start the openim-rpc services
openim::common::sudo "systemctl daemon-reload"
for service in "${OPENIM_RPC_SERVICE_LISTARIES[@]}"; do
openim::common::sudo "systemctl restart ${service}"
openim::common::sudo "systemctl enable ${service}"
done
openim::rpc::status || return 1
openim::rpc::info
openim::log::info "install openim-rpc successfully"
popd
}
# Unload
function openim::rpc::uninstall() {
set +o errexit
for service in "${OPENIM_RPC_SERVICE_LISTARIES[@]}"; do
openim::common::sudo "systemctl stop ${service}"
openim::common::sudo "systemctl disable ${service}"
openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/${service}"
openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${service}.yaml"
openim::common::sudo "rm -f ${SYSTEM_FILE_PATHS[$service]}"
done
openim::log::info "uninstall openim-rpc successfully"
}
# Status Check
function openim::rpc::status() {
for service in "${OPENIM_RPC_SERVICE_LISTARIES[@]}"; do
# Check the running status of the ${service}. If active (running) is displayed, the ${service} is started successfully.
systemctl status ${service}|grep -q 'active' || {
openim::log::error "${service} failed to start, maybe not installed properly"
return 1
}
# The listening port is hardcoded in the configuration file
if echo | telnet ${OPENIM_MSGGATEWAY_HOST} ${OPENIM_RPC_PORT_LISTARIES[@]} 2>&1|grep refused &>/dev/null;then
openim::log::error "cannot access health check port, ${service} maybe not startup"
return 1
fi
done
}
if [[ "$*" =~ openim::rpc:: ]];then
eval $*
fi

@ -1,179 +0,0 @@
#!/usr/bin/env bash
# Copyright © 2023 OpenIM. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# OpenIM Tools Control Script
#
# Description:
# This script is responsible for managing the lifecycle of OpenIM tools, which include starting, stopping,
# and handling pre and post operations. It's designed to be modular and extensible, ensuring that the
# individual operations can be managed separately, and integrated seamlessly with Linux systemd.
#
# Features:
# 1. Robust error handling using Bash built-ins like 'errexit', 'nounset', and 'pipefail'.
# 2. The capability to source common utility functions and configurations to ensure uniform environmental settings.
# 3. Comprehensive logging functionalities, providing a detailed understanding of operational processes.
# 4. Provision for declaring and managing a set of OpenIM tools, each associated with its unique name and corresponding ports.
# 5. The ability to define and associate Prometheus ports for service monitoring purposes.
# 6. Functionalities to start each OpenIM tool, along with its designated ports, in a sequence.
#
# Usage:
# 1. Direct Script Execution:
# This initiates all the OpenIM tools declared under the function openim::tools::service_name.
# Example: ./openim-tools.sh openim::tools::start
# 2. Controlling through Functions for systemctl operations:
# Specific operations like installation, uninstallation, and status check can be executed by passing the respective function name as an argument to the script.
# Example: ./openim-tools.sh openim::tools::install
#
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
SERVER_NAME="openim-tools"
openim::tools::start_name() {
local targets=(
imctl
)
echo "${targets[@]}"
}
IFS=" " read -ra OPENIM_TOOLS_NAME_TARGETS <<< "$(openim::tools::start_name)"
readonly OPENIM_TOOLS_NAME_TARGETS
readonly OPENIM_TOOLS_NAME_LISTARIES=("${OPENIM_TOOLS_NAME_TARGETS[@]##*/}")
openim::tools::pre_start_name() {
local targets=(
ncpu
component
)
echo "${targets[@]}"
}
IFS=" " read -ra OPENIM_TOOLS_PRE_START_NAME_TARGETS <<< "$(openim::tools::pre_start_name)"
readonly OPENIM_TOOLS_PRE_START_NAME_TARGETS
readonly OPENIM_TOOLS_PRE_START_NAME_LISTARIES=("${OPENIM_TOOLS_PRE_START_NAME_TARGETS[@]##*/}")
openim::tools::post_start_name() {
local targets=(
infra
versionchecker
)
echo "${targets[@]}"
}
IFS=" " read -ra OPENIM_TOOLS_POST_START_NAME_TARGETS <<< "$(openim::tools::post_start_name)"
readonly OPENIM_TOOLS_POST_START_NAME_TARGETS
readonly OPENIM_TOOLS_POST_START_NAME_LISTARIES=("${OPENIM_TOOLS_POST_START_NAME_TARGETS[@]##*/}")
function openim::tools::start_service() {
local binary_name="$1"
local config="$2"
local service_port="$3"
local prometheus_port="$4"
local cmd="${OPENIM_OUTPUT_HOSTBIN_TOOLS}/${binary_name}"
#openim::log::info "Starting PATH: ${OPENIM_OUTPUT_HOSTBIN_TOOLS}/${binary_name}..."
if [ -n "${config}" ]; then
# printf "Specifying config: %s\n" "${config}"
cmd="${cmd} -c ${config}/config.yaml"
fi
if [ -n "${service_port}" ]; then
#printf "Specifying service port: %s\n" "${service_port}"
cmd="${cmd} --port ${service_port}"
fi
if [ -n "${prometheus_port}" ]; then
#printf "Specifying prometheus port: %s\n" "${prometheus_port}"
cmd="${cmd} --prometheus_port ${prometheus_port}"
fi
#openim::log::status "Starting binary ${binary_name}..."
# openim::log::info "cmd: $cmd"
${cmd}
local status=$?
if [ $status -eq 0 ]; then
openim::log::colorless "Service ${binary_name} started successfully."
return 0
else
openim::log::error "Failed to start service ${binary_name}."
return 1
fi
}
function openim::tools::start() {
openim::log::info "Starting OpenIM Tools..."
for tool in "${OPENIM_TOOLS_NAME_LISTARIES[@]}"; do
openim::log::colorless "Starting tool ${tool}..."
# openim::tools::start_service ${tool}
#sleep 0.2
done
}
function openim::tools::pre-start() {
#openim::log::info "Preparing to start OpenIM Tools..."
for tool in "${OPENIM_TOOLS_PRE_START_NAME_LISTARIES[@]}"; do
openim::log::colorless "Starting tool: ${tool}"
if ! openim::tools::start_service ${tool} ${OPNEIM_CONFIG}; then
openim::log::error "Failed to start ${tool}, aborting..."
return 1
fi
done
#openim::log::info "All tools started successfully."
}
function openim::tools::post-start() {
#openim::log::info "Post-start actions for OpenIM Tools..."
for tool in "${OPENIM_TOOLS_POST_START_NAME_LISTARIES[@]}"; do
openim::log::colorless "Starting tool: ${tool}"
openim::tools::start_service ${tool}
done
}
function openim::tools::stop() {
openim::log::info "Stopping OpenIM Tools..."
for tool in "${OPENIM_TOOLS_NAME_LISTARIES[@]}"; do
openim::log::info "Stopping ${tool}..."
# Similarly, place the actual command to stop the tool here.
echo "Stopping service for ${tool}"
sleep 0.2
done
}
function openim::tools::pre-stop() {
openim::log::info "Preparing to stop OpenIM Tools..."
for tool in "${OPENIM_TOOLS_PRE_START_NAME_LISTARIES[@]}"; do
openim::log::info "Setting up pre-stop for ${tool}..."
echo "Pre-stop actions for ${tool}"
sleep 0.2
done
}
function openim::tools::post-stop() {
openim::log::info "Post-stop actions for OpenIM Tools..."
for tool in "${OPENIM_TOOLS_POST_START_NAME_LISTARIES[@]}"; do
openim::log::info "Executing post-stop for ${tool}..."
echo "Post-stop cleanup for ${tool}"
sleep 0.2
done
}
if [[ "$*" =~ openim::tools:: ]];then
eval $*
fi

File diff suppressed because it is too large Load Diff

@ -1,271 +0,0 @@
#!/usr/bin/env bash
# Copyright © 2023 OpenIM. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Controls verbosity of the script output and logging.
OPENIM_VERBOSE="${OPENIM_VERBOSE:-5}"
# Enable logging by default. Set to false to disable.
ENABLE_LOGGING="${ENABLE_LOGGING:-true}"
# If OPENIM_OUTPUT is not set, set it to the default value
if [ -z "${OPENIM_OUTPUT+x}" ]; then
OPENIM_OUTPUT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../_output" && pwd -P)"
fi
# Set the log file path
LOG_FILE="${OPENIM_OUTPUT}/logs/openim-$(date '+%Y%m%d').log"
STDERR_LOG_FILE="${OPENIM_OUTPUT}/logs/openim-error-$(date '+%Y%m%d').log"
TMP_LOG_FILE="${OPENIM_OUTPUT}/logs/openim-tmp-$(date '+%Y%m%d').log"
DOCKER_LOG_FILE="${OPENIM_OUTPUT}/logs/openim-docker.log"
if [[ ! -d "${OPENIM_OUTPUT}/logs" ]]; then
mkdir -p "${OPENIM_OUTPUT}/logs"
touch "$LOG_FILE"
touch "$STDERR_LOG_FILE"
touch "$TMP_LOG_FILE"
fi
if [[ ! -f "$DOCKER_LOG_FILE" ]]; then
touch "$DOCKER_LOG_FILE"
fi
# Define the logging function
function echo_log() {
if $ENABLE_LOGGING; then
echo -e "$@" | tee -a "${LOG_FILE}"
else
echo -e "$@"
fi
}
# MAX_LOG_SIZE=10485760 # 10MB
# Clear logs from 5 days ago
# find $OPENIM_OUTPUT_LOGS -type f -name "*.log" -mtime +5 -exec rm -f {} \;
# Handler for when we exit automatically on an error.
# Borrowed from https://gist.github.com/ahendrix/7030300
openim::log::errexit() {
local err="${PIPESTATUS[*]}"
# If the shell we are in doesn't have errexit set (common in subshells) then
# don't dump stacks.
set +o | grep -qe "-o errexit" || return
set +o xtrace
local code="${1:-1}"
# Print out the stack trace described by $function_stack
if [ ${#FUNCNAME[@]} -gt 2 ]
then
openim::log::error "Call tree:"
for ((i=1;i<${#FUNCNAME[@]}-1;i++))
do
openim::log::error " ${i}: ${BASH_SOURCE[${i}+1]}:${BASH_LINENO[${i}]} ${FUNCNAME[${i}]}(...)"
done
fi
openim::log::error_exit "Error in ${BASH_SOURCE[1]}:${BASH_LINENO[0]}. '${BASH_COMMAND}' exited with status ${err}" "${1:-1}" 1
}
openim::log::install_errexit() {
# trap ERR to provide an error handler whenever a command exits nonzero this
# is a more verbose version of
# trap 'openim::log::errexit' ERR
# setting errtrace allows our ERR trap handler to be propagated to functions,
# expansions and subshells
#set -o errtrace
return 0
}
# Print out the stack trace
#
# Args:
# $1 The number of stack frames to skip when printing.
openim::log::stack() {
local stack_skip=${1:-0}
stack_skip=$((stack_skip + 1))
if [[ ${#FUNCNAME[@]} -gt ${stack_skip} ]]; then
echo_log "Call stack:" >&2
local i
for ((i=1 ; i <= ${#FUNCNAME[@]} - stack_skip ; i++))
do
local frame_no=$((i - 1 + stack_skip))
local source_file=${BASH_SOURCE[${frame_no}]}
local source_lineno=${BASH_LINENO[$((frame_no - 1))]}
local funcname=${FUNCNAME[${frame_no}]}
echo_log " ${i}: ${source_file}:${source_lineno} ${funcname}(...)" >&2
done
fi
}
# Log an error and exit.
# Args:
# $1 Message to log with the error
# $2 The error code to return
# $3 The number of stack frames to skip when printing.
openim::log::error_exit() {
local message="${1:-}"
local code="${2:-1}"
local stack_skip="${3:-0}"
stack_skip=$((stack_skip + 1))
if [[ ${OPENIM_VERBOSE} -ge 4 ]]; then
local source_file=${BASH_SOURCE[${stack_skip}]}
local source_line=${BASH_LINENO[$((stack_skip - 1))]}
echo_log -e "${COLOR_RED}!!! Error in ${source_file}:${source_line} ${COLOR_SUFFIX}" >&2
[[ -z ${1-} ]] || {
echo_log " ${1}" >&2
}
openim::log::stack ${stack_skip}
echo_log "Exiting with status ${code}" >&2
fi
exit "${code}"
}
# Log an error but keep going. Don't dump the stack or exit.
openim::log::error() {
# Define red color
red='\033[0;31m'
# No color (reset)
nc='\033[0m' # No Color
timestamp=$(date +"[%Y-%m-%d %H:%M:%S %Z]")
# Apply red color for error message
echo_log "${red}!!! ${timestamp} ${1-}${nc}" >&2
shift
for message; do
# Apply red color for subsequent lines of the error message
echo_log "${red} ${message}${nc}" >&2
done
}
# Print an usage message to stderr. The arguments are printed directly.
openim::log::usage() {
echo_log >&2
local message
for message; do
echo_log "${message}" >&2
done
echo_log >&2
}
openim::log::usage_from_stdin() {
local messages=()
while read -r line; do
messages+=("${line}")
done
openim::log::usage "${messages[@]}"
}
# Print out some info that isn't a top level status line
openim::log::info() {
local V="${V:-0}"
if [[ ${OPENIM_VERBOSE} < ${V} ]]; then
return
fi
for message; do
echo_log "${message}"
done
}
# Just like openim::log::info, but no \n, so you can make a progress bar
openim::log::progress() {
for message; do
echo_log -e -n "${message}"
done
}
# Print out some info that isn't a top level status line
openim::log::info_from_stdin() {
local messages=()
while read -r line; do
messages+=("${line}")
done
openim::log::info "${messages[@]}"
}
# Print a status line. Formatted to show up in a stream of output.
openim::log::status() {
local V="${V:-0}"
if [[ ${OPENIM_VERBOSE} < ${V} ]]; then
return
fi
local COLOR_BLUE="\033[0;34m"
local COLOR_RESET="\033[0m"
local timestamp=$(date +"[%Y-%m-%d %H:%M:%S %Z]")
echo_log() {
echo -e "$@"
}
echo_log "${COLOR_BLUE}${timestamp} ${1}${COLOR_RESET}"
shift
for message; do
echo_log "${COLOR_BLUE}${message}${COLOR_RESET}"
done
}
openim::log::success() {
local V="${V:-0}"
if [[ ${OPENIM_VERBOSE} < ${V} ]]; then
return
fi
local timestamp=$(date +"%m%d %H:%M:%S")
local reset_color='\033[0m'
echo_log -e "${COLOR_GREEN}[success ${timestamp}]${COLOR_SUFFIX}==> ${COLOR_GREEN}$@${reset_color}"
}
function openim::log::test_log() {
echo_log "test log"
openim::log::info "openim::log::info"
openim::log::progress "openim::log::progress"
openim::log::status "openim::log::status"
openim::log::success "openim::log::success"
openim::log::error "openim::log::error"
openim::log::error_exit "openim::log::error_exit"
}
# openim::log::test_log
function openim::log::print_blue() {
echo -e "\033[0;36m$1\033[0m"
}
openim::log::colorless() {
local V="${V:-0}"
if [[ ${OPENIM_VERBOSE} < ${V} ]]; then
return
fi
timestamp=$(date +"[%Y-%m-%d %H:%M:%S %Z]")
echo_log -e "${timestamp} ${1} "
}

@ -1,58 +0,0 @@
# Copyright © 2023 OpenIMSDK.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
# OpenIM Makefile Versions used
#
# Define the latest version for each tool to ensure consistent versioning across installations
GOLANGCI_LINT_VERSION ?= latest
GOIMPORTS_VERSION ?= latest
ADDLICENSE_VERSION ?= latest
DEEPCOPY_GEN_VERSION ?= latest
CONVERSION_GEN_VERSION ?= latest
GINKGO_VERSION ?= v1.16.2
GO_GITLINT_VERSION ?= latest
GO_JUNIT_REPORT_VERSION ?= latest
GOTESTS_VERSION ?= latest
SWAGGER_VERSION ?= latest
KUBE_SCORE_VERSION ?= latest
KUBECONFORM_VERSION ?= latest
GSEMVER_VERSION ?= latest
GIT_CHGLOG_VERSION ?= latest
KO_VERSION ?= latest
GITHUB_RELEASE_VERSION ?= latest
COSCLI_VERSION ?= v0.19.0-beta
MINIO_VERSION ?= latest
DELVE_VERSION ?= latest
AIR_VERSION ?= latest
GOLINES_VERSION ?= latest
GO_MOD_OUTDATED_VERSION ?= latest
CFSSL_VERSION ?= latest
DEPTH_VERSION ?= latest
GO_CALLVIS_VERSION ?= latest
MISSPELL_VERSION ?= latest
GOTHANKS_VERSION ?= latest
RICHGO_VERSION ?= latest
RTS_VERSION ?= latest
TYPECHECK_VERSION ?= latest
COMMENT_LANG_DETECTOR_VERSION ?= latest
STANDARDIZER_VERSION ?= latest
GO_TESTS_VERSION ?= v1.6.0
GO_APIDIFF_VERSION ?= v0.8.2
KAFKACTL_VERSION ?= latest
GOTESTSUM_VERSION ?= latest
WIRE_VERSION ?= latest
# WIRE_VERSION ?= $(call get_go_version,github.com/google/wire)
MOCKGEN_VERSION ?= $(call get_go_version,github.com/golang/mock)
PROTOC_GEN_GO_VERSION ?= $(call get_go_version,github.com/golang/protobuf/protoc-gen-go)

@ -1,196 +0,0 @@
# Copyright © 2023 OpenIMSDK.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
# Makefile helper functions for common tasks
#
SHELL := /bin/bash
GO:=go
DIRS=$(shell ls)
DEBUG ?= 0
GIT_TAG := $(shell git describe --exact-match --tags --abbrev=0 2> /dev/null || echo untagged)
GIT_COMMIT ?= $(shell git rev-parse --short HEAD || echo "0.0.0")
BUILD_DATE ?=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') # Blank error: date '+%FT %T %z':"buildDate":"2023-03-31T 20:05:43 +0800"
# include the common makefile
COMMON_SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
SRC = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
# ROOT_DIR: root directory of the code base
ifeq ($(origin ROOT_DIR),undefined)
ROOT_DIR := $(abspath $(shell cd $(COMMON_SELF_DIR)/../.. && pwd -P))
endif
# OUTPUT_DIR: The directory where the build output is stored.
ifeq ($(origin OUTPUT_DIR),undefined)
OUTPUT_DIR := $(ROOT_DIR)/_output
$(shell mkdir -p $(OUTPUT_DIR))
endif
# BIN_DIR: Directory where executable files are stored.
ifeq ($(origin BIN_DIR),undefined)
BIN_DIR := $(OUTPUT_DIR)/bin
$(shell mkdir -p $(BIN_DIR))
endif
# BIN_TOOLS_DIR: Directory where executable files are stored.
ifeq ($(origin BIN_TOOLS_DIR),undefined)
BIN_TOOLS_DIR := $(BIN_DIR)/tools
$(shell mkdir -p $(BIN_TOOLS_DIR))
endif
# LOGS_DIR: Directory where log files are stored.
ifeq ($(origin LOGS_DIR),undefined)
LOGS_DIR := $(OUTPUT_DIR)/logs
$(shell mkdir -p $(LOGS_DIR))
endif
# TOOLS_DIR: The directory where tools are stored for build and testing.
ifeq ($(origin TOOLS_DIR),undefined)
TOOLS_DIR := $(OUTPUT_DIR)/tools
$(shell mkdir -p $(TOOLS_DIR))
endif
# TMP_DIR: directory where temporary files are stored.
ifeq ($(origin TMP_DIR),undefined)
TMP_DIR := $(OUTPUT_DIR)/tmp
$(shell mkdir -p $(TMP_DIR))
endif
ifeq ($(origin VERSION), undefined)
# VERSION := $(shell git describe --tags --always --match='v*')
# git describe --tags --always --match="v*" --dirty
# VERSION := $(shell git describe --tags --always --match="v*" --dirty | sed 's/-/./g') #v2.3.3.631.g00abdc9b.dirty
VERSION := $(shell git describe --tags --always --match='v*')
# v2.3.3: git tag
endif
# Helper function to get dependency version from go.mod
get_gomod_version = $(shell go list -m $1 | awk '{print $$2}')
define go_install
$(info ===========> Installing $(1)@$(2))
$(GO) install $(1)@$(2)
endef
# Check if the tree is dirty. default to dirty(maybe u should commit?)
GIT_TREE_STATE:="dirty"
ifeq (, $(shell git status --porcelain 2>/dev/null))
GIT_TREE_STATE="clean"
endif
GIT_COMMIT:=$(shell git rev-parse HEAD)
# Minimum test coverage
# can u use make cover COVERAGE=90
ifeq ($(origin COVERAGE),undefined)
COVERAGE := 60
endif
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
# The OS must be linux when building docker images
# PLATFORMS ?= linux_amd64 linux_arm64
# The OS can be linux/windows/darwin when building binaries
PLATFORMS ?= linux_s390x linux_mips64 linux_mips64le darwin_amd64 darwin_arm64 windows_amd64 linux_amd64 linux_arm64 linux_ppc64le # wasip1_wasm
# set a specific PLATFORM, defaults to the host platform
ifeq ($(origin PLATFORM), undefined)
ifeq ($(origin GOARCH), undefined)
GOARCH := $(shell go env GOARCH)
endif
# Determine the host OS
GOOS := $(shell go env GOOS)
PLATFORM := $(GOOS)_$(GOARCH)
# Use the host OS and GOARCH as the default when building images
IMAGE_PLAT := $(PLATFORM)
else
# Parse the PLATFORM variable
GOOS := $(word 1, $(subst _, ,$(PLATFORM)))
GOARCH := $(word 2, $(subst _, ,$(PLATFORM)))
IMAGE_PLAT := $(PLATFORM)
endif
# Protobuf file storage path
APIROOT=$(ROOT_DIR)/pkg/proto
# Linux command settings
# TODO: Whether you need to join utils?
FIND := find . ! -path './utils/*' ! -path './vendor/*' ! -path './third_party/*' ! -path './components/*' ! -path './logs/*'
XARGS := xargs -r --no-run-if-empty
# Linux command settings-CODE DIRS Copyright
CODE_DIRS := $(ROOT_DIR)/pkg $(ROOT_DIR)/cmd $(ROOT_DIR)/config $(ROOT_DIR)/internal $(ROOT_DIR)/scripts $(ROOT_DIR)/test $(ROOT_DIR)/.github $(ROOT_DIR)/build $(ROOT_DIR)/tools $(ROOT_DIR)/deployments
FINDS := find $(CODE_DIRS)
# Makefile settings: Select different behaviors by determining whether V option is set
ifndef V
MAKEFLAGS += --no-print-directory
endif
# COMMA: Concatenate multiple strings to form a list of strings
COMMA := ,
# SPACE: Used to separate strings
SPACE :=
# SPACE: Replace multiple consecutive Spaces with a single space
SPACE +=
# ==============================================================================
# Makefile helper functions for common tasks
# Help information for the makefile package
define makehelp
@printf "\n\033[1mUsage: make <TARGETS> <OPTIONS> ...\033[0m\n\n\\033[1mTargets:\\033[0m\n\n"
@sed -n 's/^##//p' $< | awk -F':' '{printf "\033[36m%-28s\033[0m %s\n", $$1, $$2}' | sed -e 's/^/ /'
@printf "\n\033[1m$$USAGE_OPTIONS\033[0m\n"
endef
# Here are some examples of builds
define MAKEFILE_EXAMPLE
# make build BINS=openim-api Only a single openim-api binary is built.
# make -j (nproc) all Run tidy gen add-copyright format lint cover build concurrently.
# make gen Generate all necessary files.
# make release Build release binaries for all platforms.
# make verify-copyright Verify the license headers for all files.
# make install-deepcopy-gen Install deepcopy-gen tools if the license is missing.
# make build BINS=openim-api V=1 DEBUG=1 Build debug binaries for only openim-api.
# make multiarch -j PLATFORMS="linux_arm64 linux_amd64" V=1 Build binaries for both platforms.
# make image
endef
export MAKEFILE_EXAMPLE
# Define all help functions @printf "\n\033[1mCurrent openim-api version information: $(shell openim-api version):\033[0m\n\n"
define makeallhelp
@printf "\n\033[1mMake example:\033[0m\n\n"
$(call MAKEFILE_EXAMPLE)
@printf "\n\033[1mAriables:\033[0m\n\n"
@echo " DEBUG: $(DEBUG)"
@echo " BINS: $(BINS)"
@echo " PLATFORMS: $(PLATFORMS)"
@echo " V: $(V)"
endef
# Help information for other makefile packages
CUT_OFF?="---------------------------------------------------------------------------------"
HELP_NAME:=$(shell basename $(MAKEFILE_LIST))
define smallhelp
@sed -n 's/^##//p' $< | awk -F':' '{printf "\033[36m%-35s\033[0m %s\n", $$1, $$2}' | sed -e 's/^/ /'
@echo $(CUT_OFF)
endef

@ -1,63 +0,0 @@
# Copyright © 2023 OpenIMSDK.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ==============================================================================
# wget https://github.com/google/addlicense/releases/download/v1.0.0/addlicense_1.0.0_Linux_x86_64.tar.gz
# Makefile helper functions for copyright
#
LICENSE_TEMPLATE ?= $(ROOT_DIR)/scripts/template/LICENSE_TEMPLATES
## copyright.verify: Validate boilerplate headers for assign files
.PHONY: copyright.verify
copyright.verify: tools.verify.addlicense
@echo "===========> Validate boilerplate headers for assign files starting in the $(ROOT_DIR) directory"
@$(TOOLS_DIR)/addlicense -v -check -ignore **/test/** -ignore **pb** -f $(LICENSE_TEMPLATE) $(CODE_DIRS)
@echo "===========> End of boilerplate headers check..."
## copyright.add: Add the boilerplate headers for all files
.PHONY: copyright.add
copyright.add: tools.verify.addlicense
@echo "===========> Adding $(LICENSE_TEMPLATE) the boilerplate headers for all files"
@$(TOOLS_DIR)/addlicense -y $(shell date +"%Y") -ignore **pb** -v -c "OpenIM." -f $(LICENSE_TEMPLATE) $(CODE_DIRS)
@echo "===========> End the copyright is added..."
# Addlicense Flags:
# -c string
# copyright holder (default "Google LLC")
# -check
# check only mode: verify presence of license headers and exit with non-zero code if missing
# -f string
# license file
# -ignore value
# file patterns to ignore, for example: -ignore **/*.go -ignore vendor/**
# -l string
# license type: apache, bsd, mit, mpl (default "apache")
# -s Include SPDX identifier in license header. Set -s=only to only include SPDX identifier.
# -skip value
# [deprecated: see -ignore] file extensions to skip, for example: -skip rb -skip go
# -v verbose mode: print the name of the files that are modified or were skipped
# -y string
# copyright year(s) (default "2023")
## copyright.advertise: Advertise the license of the project
.PHONY: copyright.advertise
copyright.advertise:
@chmod +x $(ROOT_DIR)/scripts/advertise.sh
@$(ROOT_DIR)/scripts/advertise.sh
## copyright.help: Show copyright help
.PHONY: copyright.help
copyright.help: scripts/make-rules/copyright.mk
$(call smallhelp)

@ -1,41 +0,0 @@
# Copyright © 2023 OpenIMSDK.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
# Makefile helper functions for dependencies
#
.PHONY: dependencies.run
dependencies.run: dependencies.packages dependencies.tools
.PHONY: dependencies.packages
dependencies.packages:
@$(GO) mod tidy
.PHONY: dependencies.tools
dependencies.tools: dependencies.tools.blocker dependencies.tools.critical
.PHONY: dependencies.tools.blocker
dependencies.tools.blocker: go.build.verify $(addprefix tools.verify., $(BLOCKER_TOOLS))
.PHONY: dependencies.tools.critical
dependencies.tools.critical: $(addprefix tools.verify., $(CRITICAL_TOOLS))
.PHONY: dependencies.tools.trivial
dependencies.tools.trivial: $(addprefix tools.verify., $(TRIVIAL_TOOLS))
## dependencies.help: Print help for dependencies targets
.PHONY: dependencies.help
dependencies.help: scripts/make-rules/dependencies.mk
$(call smallhelp)

@ -1,100 +0,0 @@
# Copyright © 2023 OpenIMSDK.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
# Makefile helper functions for generate necessary files and docs
# https://cloud.redhat.com/blog/kubernetes-deep-dive-code-generation-customresources
# ! The stock of code generated by `make gen` should be idempotent
#
# Questions about go mod instead of go path: https://github.com/kubernetes/kubernetes/issues/117181
# ==============================================================================
# Makefile helper functions for generate necessary files
#
## gen.init: Initialize openim server project ✨
.PHONY: gen.init
gen.init:
@echo "===========> Initializing openim server project"
@${ROOT_DIR}/scripts/init-config.sh
## gen.init-githooks: Initialize git hooks ✨
.PHONY: gen.init-githooks
gen.init-githooks:
@echo "===========> Initializing git hooks"
@${ROOT_DIR}/scripts/init-githooks.sh
## gen.run: Generate necessary files and docs ✨
.PHONY: gen.run
#gen.run: gen.errcode gen.docgo
gen.run: gen.clean gen.errcode gen.docgo.doc
## gen.errcode: Generate necessary files and docs ✨
.PHONY: gen.errcode
gen.errcode: gen.errcode.code gen.errcode.doc
## gen.errcode.code: Generate openim error code go source files ✨
.PHONY: gen.errcode.code
gen.errcode.code: tools.verify.codegen
@echo "===========> Generating openim error code go source files"
@codegen -type=int ${ROOT_DIR}/internal/pkg/code
## gen.errcode.doc: Generate openim error code markdown documentation ✨
.PHONY: gen.errcode.doc
gen.errcode.doc: tools.verify.codegen
@echo "===========> Generating error code markdown documentation"
@codegen -type=int -doc \
-output ${ROOT_DIR}/docs/guide/zh-CN/api/error_code_generated.md ${ROOT_DIR}/internal/pkg/code
## gen.docgo: Generate missing doc.go for go packages ✨
.PHONY: gen.ca.%
gen.ca.%:
$(eval CA := $(word 1,$(subst ., ,$*)))
@echo "===========> Generating CA files for $(CA)"
@${ROOT_DIR}/scripts/gencerts.sh generate-openim-cert $(OUTPUT_DIR)/cert $(CA)
## gen.ca: Generate CA files for all certificates ✨
.PHONY: gen.ca
gen.ca: $(addprefix gen.ca., $(CERTIFICATES))
## gen.docgo: Generate missing doc.go for go packages ✨
.PHONY: gen.docgo.doc
gen.docgo.doc:
@echo "===========> Generating missing doc.go for go packages"
@${ROOT_DIR}/scripts/gendoc.sh
## gen.docgo.check: Check if there are untracked doc.go files ✨
.PHONY: gen.docgo.check
gen.docgo.check: gen.docgo.doc
@n="$$(git ls-files --others '*/doc.go' | wc -l)"; \
if test "$$n" -gt 0; then \
git ls-files --others '*/doc.go' | sed -e 's/^/ /'; \
echo "$@: untracked doc.go file(s) exist in working directory" >&2 ; \
false ; \
fi
## gen.docgo.add: Add untracked doc.go files to git index ✨
.PHONY: gen.docgo.add
gen.docgo.add:
@git ls-files --others '*/doc.go' | $(XARGS) -- git add
## gen.docgo: Generate missing doc.go for go packages ✨
.PHONY: gen.clean
gen.clean:
@rm -rf ./api/client/{clientset,informers,listers}
@$(FIND) -type f -name '*_generated.go' -delete
## gen.help: show help for gen
.PHONY: gen.help
gen.help: scripts/make-rules/gen.m
$(call smallhelp)

@ -1,272 +0,0 @@
# Copyright © 2023 OpenIMSDK.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
# Build management helpers. These functions help to set, save and load the
#
GO := go
GO_MINIMUM_VERSION ?= 1.19
GO_LDFLAGS += -X $(VERSION_PACKAGE).gitVersion=$(GIT_TAG) \
-X $(VERSION_PACKAGE).gitCommit=$(GIT_COMMIT) \
-X $(VERSION_PACKAGE).gitTreeState=$(GIT_TREE_STATE) \
-X $(VERSION_PACKAGE).buildDate=$(BUILD_DATE) \
-s -w # -s -w deletes debugging information and symbol tables
ifeq ($(DEBUG), 1)
GO_BUILD_FLAGS += -gcflags "all=-N -l"
GO_LDFLAGS=
endif
GO_BUILD_FLAGS += -ldflags "$(GO_LDFLAGS)"
ifeq ($(GOOS),windows)
GO_OUT_EXT := .exe
endif
ifeq ($(ROOT_PACKAGE),)
$(error the variable ROOT_PACKAGE must be set prior to including golang.mk, ->/Makefile)
endif
GOPATH ?= $(shell go env GOPATH)
ifeq ($(origin GOBIN), undefined)
GOBIN := $(GOPATH)/bin
endif
# COMMANDS is Specify all files under ${ROOT_DIR}/cmd/ and ${ROOT_DIR}/tools/ except those ending in.md
COMMANDS ?= $(filter-out %.md, $(wildcard ${ROOT_DIR}/cmd/* ${ROOT_DIR}/tools/* ${ROOT_DIR}/tools/data-conversion/chat/cmd/* ${ROOT_DIR}/tools/data-conversion/openim/cmd/* ${ROOT_DIR}/cmd/openim-rpc/*))
ifeq (${COMMANDS},)
$(error Could not determine COMMANDS, set ROOT_DIR or run in source dir)
endif
# BINS is the name of each file in ${COMMANDS}, excluding the directory path
# If there are no files in ${COMMANDS}, or if all files end in.md, ${BINS} will be empty
BINS ?= $(foreach cmd,${COMMANDS},$(notdir ${cmd}))
ifeq (${BINS},)
$(error Could not determine BINS, set ROOT_DIR or run in source dir)
endif
ifeq ($(OS),Windows_NT)
NULL :=
SPACE := $(NULL) $(NULL)
ROOT_DIR := $(subst $(SPACE),\$(SPACE),$(shell cd))
else
ROOT_DIR := $(shell pwd)
endif
ifeq ($(strip $(COMMANDS)),)
$(error Could not determine COMMANDS, set ROOT_DIR or run in source dir)
endif
ifeq ($(strip $(BINS)),)
$(error Could not determine BINS, set ROOT_DIR or run in source dir)
endif
# TODO: EXCLUDE_TESTS variable, which contains the name of the package to be excluded from the test
EXCLUDE_TESTS=github.com/openimsdk/open-im-server/test github.com/openimsdk/open-im-server/v3/pkg/log github.com/openimsdk/open-im-server/db github.com/openimsdk/open-im-server/scripts github.com/openimsdk/open-im-server/config
# ==============================================================================
# tree -L 1 cmd
# cmd
# ├── openim-sdk-core/ - main.go
# ├── openim-api
# ├── openim_cms_api
# ├── openim-crontask
# ├── openim_demo
# ├── openim-rpc-msg_gateway
# ├── openim-msgtransfer
# ├── openim-push
# ├── rpc/openim_admin_cms/ - main.go
# └── test/ - main.go
# COMMAND=openim
# PLATFORM=linux_amd64
# OS=linux
# ARCH=amd64
# BINS=openim-api openim_cms_api openim-crontask openim_demo openim-rpc-msg_gateway openim-msgtransfer openim-push
# BIN_DIR=/root/workspaces/OpenIM/_output/bin
# ==============================================================================
## go.build: Build binaries
.PHONY: go.build
go.build: go.build.verify $(addprefix go.build., $(addprefix $(PLATFORM)., $(BINS)))
@echo "===========> Building binary $(BINS) $(VERSION) for $(PLATFORM)"
## go.start: Start openim
.PHONY: go.start
go.start:
@echo "=========================> Starting OpenIM <========================="
@$(ROOT_DIR)/scripts/start-all.sh
## go.stop: Stop openim
.PHONY: go.stop
go.stop:
@echo "=========================> Stopping OpenIM <========================="
@$(ROOT_DIR)/scripts/stop-all.sh
## go.check: Check openim
.PHONY: go.check
go.check:
@echo "=========================> Checking OpenIM <========================="
@$(ROOT_DIR)/scripts/check-all.sh
## go.check-component: Check openim component
.PHONY: go.check-component
go.check-component:
@echo "=========================> Checking OpenIM component <========================="
@$(ROOT_DIR)/scripts/install/openim-tools.sh openim::tools::pre-start
## go.versionchecker: Design, detect some environment variables and versions
go.versionchecker:
@$(ROOT_DIR)/scripts/install/openim-tools.sh openim::tools::post-start
## go.build.verify: Verify that a suitable version of Go exists
.PHONY: go.build.verify
go.build.verify:
ifneq ($(shell $(GO) version|awk -v min=$(GO_MINIMUM_VERSION) '{gsub(/go/,"",$$3);if($$3 >= min){print 0}else{print 1}}'), 0)
$(error unsupported go version. Please install a go version which is greater than or equal to '$(GO_MINIMUM_VERSION)')
endif
## go.build.%: Build binaries for a specific platform
# CGO_ENABLED=0 https://wiki.musl-libc.org/functional-differences-from-glibc.html
.PHONY: go.build.%
go.build.%:
$(eval COMMAND := $(word 2,$(subst ., ,$*)))
$(eval PLATFORM := $(word 1,$(subst ., ,$*)))
$(eval OS := $(word 1,$(subst _, ,$(PLATFORM))))
$(eval ARCH := $(word 2,$(subst _, ,$(PLATFORM))))
@echo "=====> COMMAND=$(COMMAND)"
@echo "=====> PLATFORM=$(PLATFORM)"
@echo "===========> Building binary $(COMMAND) $(VERSION) for $(OS)_$(ARCH)"
@mkdir -p $(BIN_DIR)/platforms/$(OS)/$(ARCH)
@if [ "$(COMMAND)" == "openim-sdk-core" ]; then \
echo "===========> DEBUG: OpenIM-SDK-Core It is no longer supported for openim-server $(COMMAND)"; \
elif [ -d $(ROOT_DIR)/cmd/openim-rpc/$(COMMAND) ]; then \
CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o \
$(BIN_DIR)/platforms/$(OS)/$(ARCH)/$(COMMAND)$(GO_OUT_EXT) $(ROOT_DIR)/cmd/openim-rpc/$(COMMAND)/main.go; \
else \
if [ -f $(ROOT_DIR)/cmd/$(COMMAND)/main.go ]; then \
CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o \
$(BIN_DIR)/platforms/$(OS)/$(ARCH)/$(COMMAND)$(GO_OUT_EXT) $(ROOT_DIR)/cmd/$(COMMAND)/main.go; \
elif [ -f $(ROOT_DIR)/tools/$(COMMAND)/$(COMMAND).go ]; then \
CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o \
$(BIN_TOOLS_DIR)/$(OS)/$(ARCH)/$(COMMAND)$(GO_OUT_EXT) $(ROOT_DIR)/tools/$(COMMAND)/$(COMMAND).go; \
chmod +x $(BIN_TOOLS_DIR)/$(OS)/$(ARCH)/$(COMMAND)$(GO_OUT_EXT); \
elif [ -f $(ROOT_DIR)/tools/data-conversion/openim/cmd/$(COMMAND)/$(COMMAND).go ]; then \
CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o \
$(BIN_TOOLS_DIR)/$(OS)/$(ARCH)/$(COMMAND)$(GO_OUT_EXT) $(ROOT_DIR)/tools/data-conversion/openim/cmd/$(COMMAND)/$(COMMAND).go; \
chmod +x $(BIN_TOOLS_DIR)/$(OS)/$(ARCH)/$(COMMAND)$(GO_OUT_EXT); \
elif [ -f $(ROOT_DIR)/tools/data-conversion/chat/cmd/$(COMMAND)/$(COMMAND).go ]; then \
CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o \
$(BIN_TOOLS_DIR)/$(OS)/$(ARCH)/$(COMMAND)$(GO_OUT_EXT) $(ROOT_DIR)/tools/data-conversion/chat/cmd/$(COMMAND)/$(COMMAND).go; \
chmod +x $(BIN_TOOLS_DIR)/$(OS)/$(ARCH)/$(COMMAND)$(GO_OUT_EXT); \
fi \
fi
## go.install: Install deployment openim
.PHONY: go.install
go.install:
@echo "===========> Installing deployment openim"
@$(ROOT_DIR)/scripts/install-im-server.sh
## go.multiarch: Build multi-arch binaries
.PHONY: go.build.multiarch
go.build.multiarch: go.build.verify $(foreach p,$(PLATFORMS),$(addprefix go.build., $(addprefix $(p)., $(BINS))))
## go.lint: Run golangci to lint source codes
.PHONY: go.lint
go.lint: tools.verify.golangci-lint
@echo "===========> Run golangci to lint source codes"
@$(TOOLS_DIR)/golangci-lint run --color always -c $(ROOT_DIR)/.golangci.yml $(ROOT_DIR)/...
## go.test: Run unit test
.PHONY: go.test
go.test:
@$(GO) test ./...
## go.test.api: Run api test
.PHONY: go.test.api
go.test.api:
@echo "===========> Run api test"
@$(ROOT_DIR)/scripts/install/test.sh openim::test::test
## go.test.e2e: Run e2e test
.PHONY: go.test.e2e
go.test.e2e: tools.verify.ginkgo
@echo "===========> Run e2e test"
@$(TOOLS_DIR)/ginkgo -v $(ROOT_DIR)/test/e2e
## go.demo: Run demo
.PHONY: go.demo
go.demo:
@echo "===========> Run demo"
@$(ROOT_DIR)/scripts/demo.sh
## go.test.junit-report: Run unit test
.PHONY: go.test.junit-report
go.test.junit-report: tools.verify.go-junit-report
@touch $(TMP_DIR)/coverage.out
@echo "===========> Run unit test > $(TMP_DIR)/report.xml"
# @$(GO) test -v -coverprofile=$(TMP_DIR)/coverage.out 2>&1 $(GO_BUILD_FLAGS) ./... | $(TOOLS_DIR)/go-junit-report -set-exit-code > $(TMP_DIR)/report.xml
@$(GO) test -v -coverprofile=$(TMP_DIR)/coverage.out 2>&1 ./... | $(TOOLS_DIR)/go-junit-report -set-exit-code > $(TMP_DIR)/report.xml
@sed -i '/mock_.*.go/d' $(TMP_DIR)/coverage.out
@echo "===========> Test coverage of Go code is reported to $(TMP_DIR)/coverage.html by generating HTML"
@$(GO) tool cover -html=$(TMP_DIR)/coverage.out -o $(TMP_DIR)/coverage.html
## go.test.cover: Run unit test with coverage
.PHONY: go.test.cover
go.test.cover: go.test.junit-report
@$(GO) tool cover -func=$(TMP_DIR)/coverage.out | \
awk -v target=$(COVERAGE) -f $(ROOT_DIR)/scripts/coverage.awk
## go.format: Run unit test and format codes
.PHONY: go.format
go.format: tools.verify.golines tools.verify.goimports
@echo "===========> Formatting codes"
@$(FIND) -type f -name '*.go' -not -name '*pb*' | $(XARGS) gofmt -s -w
@$(FIND) -type f -name '*.go' -not -name '*pb*' | $(XARGS) $(TOOLS_DIR)/goimports -w -local $(ROOT_PACKAGE)
@$(FIND) -type f -name '*.go' -not -name '*pb*' | $(XARGS) $(TOOLS_DIR)/golines -w --max-len=200 --reformat-tags --shorten-comments --ignore-generated .
@$(GO) mod edit -fmt
## go.imports: task to automatically handle import packages in Go files using goimports tool
.PHONY: go.imports
go.imports: tools.verify.goimports
@$(TOOLS_DIR)/goimports -l -w $(SRC)
## go.verify: execute all verity scripts.
.PHONY: go.verify
go.verify: tools.verify.misspell
@echo "Starting verification..."
@scripts_list=$$(find $(ROOT_DIR)/scripts -type f -name 'verify-*' | sort); \
for script in $$scripts_list; do \
echo "Executing $$script..."; \
$$script || exit 1; \
echo "$$script completed successfully"; \
done
@echo "All verification scripts executed successfully."
## go.updates: Check for updates to go.mod dependencies
.PHONY: go.updates
go.updates: tools.verify.go-mod-outdated
@$(GO) list -u -m -json all | go-mod-outdated -update -direct
## go.clean: Clean all builds directories and files
.PHONY: go.clean
go.clean:
@echo "===========> Cleaning all builds tmp, bin, logs directories and files"
@-rm -vrf $(TMP_DIR) $(BIN_DIR) $(BIN_TOOLS_DIR) $(LOGS_DIR)
@echo "===========> End clean..."
## go.help: Show go tools help
.PHONY: go.help
go.help: scripts/make-rules/golang.mk
$(call smallhelp)

@ -1,183 +0,0 @@
# Copyright © 2023 OpenIMSDK.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
# Makefile helper functions for docker image
# ==============================================================================
# Path: scripts/make-rules/image.mk
# docker registry: registry.example.com/namespace/image:tag as: registry.hub.docker.com/cubxxw/<image-name>:<tag>
# https://docs.docker.com/build/building/multi-platform/
#
DOCKER := docker
# read: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/images.md
REGISTRY_PREFIX ?= registry.cn-hangzhou.aliyuncs.com/openimsdk
# REGISTRY_PREFIX ?= ghcr.io/openimsdk
BASE_IMAGE ?= ghcr.io/openim-sigs/openim-bash-image
IMAGE_PLAT ?= $(subst $(SPACE),$(COMMA),$(subst _,/,$(PLATFORMS)))
EXTRA_ARGS ?= --no-cache
_DOCKER_BUILD_EXTRA_ARGS :=
ifdef HTTP_PROXY
_DOCKER_BUILD_EXTRA_ARGS += --build-arg HTTP_PROXY=${HTTP_PROXY}
endif
ifneq ($(EXTRA_ARGS), )
_DOCKER_BUILD_EXTRA_ARGS += $(EXTRA_ARGS)
endif
# Determine image files by looking into build/images/*/Dockerfile
IMAGES_DIR ?= $(wildcard ${ROOT_DIR}/build/images/*)
# Determine images names by stripping out the dir names, and filter out the undesired directories
# IMAGES ?= $(filter-out Dockerfile,$(foreach image,${IMAGES_DIR},$(notdir ${image})))
IMAGES ?= $(filter-out Dockerfile openim-tools openim-rpc-extend-msg openim-rpc-encryption openim-cmdutils,$(foreach image,${IMAGES_DIR},$(notdir ${image})))
# IMAGES ?= $(filter-out Dockerfile openim-tools openim-cmdutils,$(foreach image,${IMAGES_DIR},$(notdir ${image}))) # !pro
ifeq (${IMAGES},)
$(error Could not determine IMAGES, set ROOT_DIR or run in source dir)
endif
# ==============================================================================
# Image targets
# ==============================================================================
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
# To properly provided solutions that supports more than one platform you should use this option.
## image.docker-buildx: Build and push docker image for the manager for cross-platform support
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
.PHONY: image.docker-buildx
image.docker-buildx:
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
- $(CONTAINER_TOOL) buildx create --name project-v3-builder
$(CONTAINER_TOOL) buildx use project-v3-builder
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMAGES} -f Dockerfile.cross .
- $(CONTAINER_TOOL) buildx rm project-v3-builder
rm Dockerfile.cross
## image.verify: Verify docker version
.PHONY: image.verify
image.verify:
@$(ROOT_DIR)/scripts/lib/util.sh openim::util::check_docker_and_compose_versions
## image.daemon.verify: Verify docker daemon experimental features
.PHONY: image.daemon.verify
image.daemon.verify:
@$(ROOT_DIR)/scripts/lib/util.sh openim::util::ensure_docker_daemon_connectivity
@$(ROOT_DIR)/scripts/lib/util.sh openim::util::ensure-docker-buildx
# If you wish built the manager image targeting other platforms you can use the --platform flag.
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
## image.build: Build docker images
.PHONY: image.build
image.build: image.verify $(addprefix image.build., $(addprefix $(PLATFORM)., $(IMAGES)))
.PHONY: image.build.multiarch
image.build.multiarch: image.verify $(foreach p,$(PLATFORMS),$(addprefix image.build., $(addprefix $(p)., $(IMAGES))))
## image.build.%: Build docker image for a specific platform
.PHONY: image.build.%
image.build.%: go.build.%
$(eval IMAGE := $(COMMAND))
$(eval IMAGE_PLAT := $(subst _,/,$(PLATFORM)))
$(eval ARCH := $(word 2,$(subst _, ,$(PLATFORM))))
@echo "===========> Building docker image $(IMAGE) $(VERSION) for $(IMAGE_PLAT)"
@mkdir -p $(TMP_DIR)/$(IMAGE)/$(PLATFORM)
@cat $(ROOT_DIR)/build/images/Dockerfile\
| sed "s#BASE_IMAGE#$(BASE_IMAGE)#g" \
| sed "s#BINARY_NAME#$(IMAGE)#g" >$(TMP_DIR)/$(IMAGE)/Dockerfile
@cp $(BIN_DIR)/platforms/$(IMAGE_PLAT)/$(IMAGE) $(TMP_DIR)/$(IMAGE)
$(eval BUILD_SUFFIX := $(_DOCKER_BUILD_EXTRA_ARGS) --pull -t $(REGISTRY_PREFIX)/$(IMAGE)-$(ARCH):$(VERSION) $(TMP_DIR)/$(IMAGE))
@echo $(DOCKER) build --platform $(IMAGE_PLAT) $(BUILD_SUFFIX)
@if [ $(shell $(GO) env GOARCH) != $(ARCH) ] ; then \
$(MAKE) image.daemon.verify ;\
$(DOCKER) build --platform $(IMAGE_PLAT) $(BUILD_SUFFIX) ; \
else \
$(DOCKER) build $(BUILD_SUFFIX) ; \
fi
@rm -rf $(TMP_DIR)/$(IMAGE)
# https://docs.docker.com/build/building/multi-platform/
# busybox image supports amd64, arm32v5, arm32v6, arm32v7, arm64v8, i386, ppc64le, and s390x
## image.buildx.%: Build docker images with buildx
.PHONY: image.buildx.%
image.buildx.%:
$(eval IMAGE := $(word 1,$(subst ., ,$*)))
echo "===========> Building docker image $(IMAGE) $(VERSION)"
$(DOCKER) buildx build -f $(ROOT_DIR)/Dockerfile --pull --no-cache --platform=$(PLATFORMS) --push . -t $(REGISTRY_PREFIX)/$(IMAGE)-$(ARCH):$(VERSION)
## image.push: Push docker images
.PHONY: image.push
image.push: image.verify go.build.verify $(addprefix image.push., $(addprefix $(IMAGE_PLAT)., $(IMAGES)))
## image.push.multiarch: Push docker images for all platforms
.PHONY: image.push.multiarch
image.push.multiarch: image.verify go.build.verify $(foreach p,$(PLATFORMS),$(addprefix image.push., $(addprefix $(p)., $(IMAGES))))
## image.push.%: Push docker image for a specific platform
.PHONY: image.push.%
image.push.%: image.build.%
@echo "===========> Pushing image $(IMAGE) $(VERSION) to $(REGISTRY_PREFIX)"
$(DOCKER) push $(REGISTRY_PREFIX)/$(IMAGE)-$(ARCH):$(VERSION)
## image.manifest.push: Push manifest list for multi-arch images
.PHONY: image.manifest.push
image.manifest.push: export DOCKER_CLI_EXPERIMENTAL := enabled
image.manifest.push: image.verify go.build.verify \
$(addprefix image.manifest.push., $(addprefix $(IMAGE_PLAT)., $(IMAGES)))
## image.manifest.push.%: Push manifest list for multi-arch images for a specific platform
.PHONY: image.manifest.push.%
image.manifest.push.%: image.push.% image.manifest.remove.%
@echo "===========> Pushing manifest $(IMAGE) $(VERSION) to $(REGISTRY_PREFIX) and then remove the local manifest list"
@$(DOCKER) manifest create $(REGISTRY_PREFIX)/$(IMAGE):$(VERSION) \
$(REGISTRY_PREFIX)/$(IMAGE)-$(ARCH):$(VERSION)
@$(DOCKER) manifest annotate $(REGISTRY_PREFIX)/$(IMAGE):$(VERSION) \
$(REGISTRY_PREFIX)/$(IMAGE)-$(ARCH):$(VERSION) \
--os $(OS) --arch ${ARCH}
@$(DOCKER) manifest push --purge $(REGISTRY_PREFIX)/$(IMAGE):$(VERSION)
# Docker cli has a bug: https://github.com/docker/cli/issues/954
# If you find your manifests were not updated,
# Please manually delete them in $HOME/.docker/manifests/
# and re-run.
## image.manifest.remove.%: Remove local manifest list
.PHONY: image.manifest.remove.%
image.manifest.remove.%:
@rm -rf ${HOME}/.docker/manifests/docker.io_$(REGISTRY_PREFIX)_$(IMAGE)-$(VERSION)
## image.manifest.push.multiarch: Push manifest list for multi-arch images for all platforms
.PHONY: image.manifest.push.multiarch
image.manifest.push.multiarch: image.push.multiarch $(addprefix image.manifest.push.multiarch., $(IMAGES))
## image.manifest.push.multiarch.%: Push manifest list for multi-arch images for all platforms for a specific image
.PHONY: image.manifest.push.multiarch.%
image.manifest.push.multiarch.%:
@echo "===========> Pushing manifest $* $(VERSION) to $(REGISTRY_PREFIX) and then remove the local manifest list"
REGISTRY_PREFIX=$(REGISTRY_PREFIX) PLATFORMS="$(PLATFORMS)" IMAGE=$* VERSION=$(VERSION) DOCKER_CLI_EXPERIMENTAL=enabled \
$(ROOT_DIR)/build/lib/create-manifest.sh
## image.help: Print help for image targets
.PHONY: image.help
image.help: scripts/make-rules/image.mk
$(call smallhelp)

@ -1,42 +0,0 @@
# Copyright © 2023 OpenIMSDK.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
# Makefile helper functions for release
# Versions are used after merging
#
## release.run: release the project
.PHONY: release.run
release.run: release.verify release.ensure-tag
@scripts/release.sh
## release.verify: Check if a tool is installed and install it
.PHONY: release.verify
release.verify: tools.verify.git-chglog tools.verify.github-release tools.verify.coscmd tools.verify.coscli
## release.tag: release the project
.PHONY: release.tag
release.tag: tools.verify.gsemver release.ensure-tag
@git push origin `git describe --tags --abbrev=0`
## release.ensure-tag: ensure tag
.PHONY: release.ensure-tag
release.ensure-tag: tools.verify.gsemver
@scripts/ensure-tag.sh
## release.help: Display help information about the release package
.PHONY: release.help
release.help: scripts/make-rules/release.mk
$(call smallhelp)

@ -1,19 +0,0 @@
# ==============================================================================
# Makefile helper functions for swagger
#
## swagger.run: Generate swagger document.
.PHONY: swagger.run
swagger.run: tools.verify.swagger
@echo "===========> Generating swagger API docs"
@$(TOOLS_DIR)/swagger generate spec --scan-models -w $(ROOT_DIR)/cmd/genswaggertypedocs -o $(ROOT_DIR)/api/swagger/swagger.yaml
## swagger.serve: Serve swagger spec and docs.
.PHONY: swagger.serve
swagger.serve: tools.verify.swagger
@$(TOOLS_DIR)/swagger serve -F=redoc --no-open --port 36666 $(ROOT_DIR)/api/swagger/swagger.yaml
## swagger.help: Display help information about the release package
.PHONY: swagger.help
swagger.help: scripts/make-rules/swagger.mk
$(call smallhelp)

@ -1,280 +0,0 @@
# Copyright © 2023 OpenIMSDK.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
# Makefile helper functions for tools(https://github.com/avelino/awesome-go) -> DIR: {TOOT_DIR}/tools | (go >= 1.19)
# Why download to the tools directory, thinking we might often switch Go versions using gvm.
#
# openim build use BUILD_TOOLS
BUILD_TOOLS ?= golangci-lint goimports addlicense deepcopy-gen conversion-gen ginkgo go-junit-report go-gitlint
# Code analysis tools
ANALYSIS_TOOLS = golangci-lint goimports golines go-callvis kube-score
# Code generation tools
GENERATION_TOOLS = deepcopy-gen conversion-gen protoc-gen-go cfssl rts codegen
# Testing tools
TEST_TOOLS = ginkgo go-junit-report gotests
# tenxun cos tools
COS_TOOLS = coscli coscmd
# Version control tools
VERSION_CONTROL_TOOLS = addlicense go-gitlint git-chglog github-release gsemver
# Utility tools
UTILITY_TOOLS = go-mod-outdated mockgen gothanks richgo kubeconform
# All tools
ALL_TOOLS ?= $(ANALYSIS_TOOLS) $(GENERATION_TOOLS) $(TEST_TOOLS) $(VERSION_CONTROL_TOOLS) $(UTILITY_TOOLS) $(COS_TOOLS)
## tools.install: Install a must tools
.PHONY: tools.install
tools.install: $(addprefix tools.verify., $(BUILD_TOOLS))
## tools.install-all: Install all tools
.PHONY: tools.install-all
tools.install-all: $(addprefix tools.install-all., $(ALL_TOOLS))
## tools.install.%: Install a single tool in $GOBIN/
.PHONY: tools.install.%
tools.install.%:
@echo "===========> Installing $,The default installation path is $(GOBIN)/$*"
@$(MAKE) install.$*
## tools.install-all.%: Parallelism install a single tool in ./tools/*
.PHONY: tools.install-all.%
tools.install-all.%:
@echo "===========> Installing $,The default installation path is $(TOOLS_DIR)/$*"
@$(MAKE) -j $(nproc) install.$*
## tools.verify.%: Check if a tool is installed and install it
.PHONY: tools.verify.%
tools.verify.%:
@echo "===========> Verifying $* is installed"
@if [ ! -f $(TOOLS_DIR)/$* ]; then GOBIN=$(TOOLS_DIR) $(MAKE) tools.install.$*; fi
@echo "===========> $* is install in $(TOOLS_DIR)/$*"
## install.golangci-lint: Install golangci-lint
.PHONY: install.golangci-lint
install.golangci-lint:
@$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
## install.goimports: Install goimports, used to format go source files
.PHONY: install.goimports
install.goimports:
@$(GO) install golang.org/x/tools/cmd/goimports@$(GOIMPORTS_VERSION)
## install.addlicense: Install addlicense, used to add license header to source files
.PHONY: install.addlicense
install.addlicense:
@$(GO) install github.com/google/addlicense@$(ADDLICENSE_VERSION)
## install.deepcopy-gen: Install deepcopy-gen, used to generate deep copy functions
.PHONY: install.deepcopy-gen
install.deepcopy-gen:
@$(GO) install k8s.io/code-generator/cmd/deepcopy-gen@$(DEEPCOPY_GEN_VERSION)
## install.conversion-gen: Install conversion-gen, used to generate conversion functions
.PHONY: install.conversion-gen
install.conversion-gen:
@$(GO) install k8s.io/code-generator/cmd/conversion-gen@$(CONVERSION_GEN_VERSION)
## install.ginkgo: Install ginkgo to run a single test or set of tests
.PHONY: install.ginkgo
install.ginkgo:
@$(GO) install github.com/onsi/ginkgo/ginkgo@$(GINKGO_VERSION)
## install.go-gitlint: Install go-gitlint, used to check git commit message
.PHONY: install.go-gitlint
install.go-gitlint:
@$(GO) install github.com/marmotedu/go-gitlint/cmd/go-gitlint@$(GO_GITLINT_VERSION)
## install.go-junit-report: Install go-junit-report, used to convert go test output to junit xml
.PHONY: install.go-junit-report
install.go-junit-report:
@$(GO) install github.com/jstemmer/go-junit-report@$(GO_JUNIT_REPORT_VERSION)
## install.gotests: Install gotests, used to generate go tests
.PHONY: install.gotests
install.gotests:
@$(GO) install github.com/cweill/gotests/gotests@$(GO_TESTS_VERSION)
## install.kafkactl: Install kafkactl command line tool.
.PHONY: install.kafkactl
install.kafkactl:
@$(GO) install github.com/deviceinsight/kafkactl@$(KAFKACTL_VERSION)
## install.go-apidiff: Install go-apidiff, used to check api changes
.PHONY: install.go-apidiff
install.go-apidiff:
@$(GO) install github.com/joelanford/go-apidiff@$(GO_APIDIFF_VERSION)
## install.swagger: Install swagger, used to generate swagger documentation
.PHONY: install.swagger
install.swagger:
@$(GO) install github.com/go-swagger/go-swagger/cmd/swagger@$(SWAGGER_VERSION)
# ==============================================================================
# Tools that might be used include go gvm
#
## install.gotestsum: Install gotestsum, used to run go tests
.PHONY: install.gotestsum
install.gotestsum:
@$(GO) install gotest.tools/gotestsum@$(GOTESTSUM_VERSION)
## install.kube-score: Install kube-score, used to check kubernetes yaml files
.PHONY: install.kube-score
install.kube-score:
@$(GO) install github.com/zegl/kube-score/cmd/kube-score@$(KUBE_SCORE_VERSION)
## install.kubeconform: Install kubeconform, used to check kubernetes yaml files
.PHONY: install.kubeconform
install.kubeconform:
@$(GO) install github.com/yannh/kubeconform/cmd/kubeconform@$(KUBECONFORM_VERSION)
## install.gsemver: Install gsemver, used to generate semver
.PHONY: install.gsemver
install.gsemver:
@$(GO) install github.com/arnaud-deprez/gsemver@$(GSEMVER_VERSION)
## install.git-chglog: Install git-chglog, used to generate changelog
.PHONY: install.git-chglog
install.git-chglog:
@$(GO) install github.com/git-chglog/git-chglog/cmd/git-chglog@$(GIT_CHGLOG_VERSION)
## install.ko: Install ko, used to build go program into container images
.PHONY: install.ko
install.ko:
@$(GO) install github.com/google/ko@$(KO_VERSION)
## install.github-release: Install github-release, used to create github release
.PHONY: install.github-release
install.github-release:
@$(GO) install github.com/github-release/github-release@$(GITHUB_RELEASE_VERSION)
## install.coscli: Install coscli, used to upload files to cos
# example: ./coscli cp/sync -r /home/off-line/docker-off-line/ cos://openim-1306374445/openim/image/amd/off-line/off-line/ -e cos.ap-guangzhou.myqcloud.com
# https://cloud.tencent.com/document/product/436/71763
# amd64
.PHONY: install.coscli
install.coscli:
@wget -q https://github.com/tencentyun/coscli/releases/download/$(COSCLI_VERSION)/coscli-linux -O ${TOOLS_DIR}/coscli
@chmod +x ${TOOLS_DIR}/coscli
## install.coscmd: Install coscmd, used to upload files to cos
.PHONY: install.coscmd
install.coscmd:
@if which pip &>/dev/null; then pip install coscmd; else pip3 install coscmd; fi
## install.minio: Install minio, used to upload files to minio
.PHONY: install.minio
install.minio:
@$(GO) install github.com/minio/minio@$(MINIO_VERSION)
## install.delve: Install delve, used to debug go program
.PHONY: install.delve
install.delve:
@$(GO) install github.com/go-delve/delve/cmd/dlv@$(DELVE_VERSION)
## install.air: Install air, used to hot reload go program
.PHONY: install.air
install.air:
@$(GO) install github.com/cosmtrek/air@$(AIR_VERSION)
## install.gvm: Install gvm, gvm is a Go version manager, built on top of the official go tool.
.PHONY: install.gvm
install.gvm:
@echo "===========> Installing gvm, The default installation path is ~/.gvm/scripts/gvm"
@bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
@source /root/.gvm/scripts/gvm
## install.golines: Install golines, used to format long lines
.PHONY: install.golines
install.golines:
@$(GO) install github.com/segmentio/golines@$(GOLINES_VERSION)
## install.go-mod-outdated: Install go-mod-outdated, used to check outdated dependencies
.PHONY: install.go-mod-outdated
install.go-mod-outdated:
@$(GO) install github.com/psampaz/go-mod-outdated@$(GO_MOD_OUTDATED_VERSION)
## install.mockgen: Install mockgen, used to generate mock functions
.PHONY: install.mockgen
install.mockgen:
@$(GO) install github.com/golang/mock/mockgen@$(MOCKGEN_VERSION)
## install.wire: Install wire, used to generate wire files
.PHONY: install.wire
install.wire:
@$(GO) install github.com/google/wire/cmd/wire@$(WIRE_VERSION)
## install.protoc-gen-go: Install protoc-gen-go, used to generate go source files from protobuf files
.PHONY: install.protoc-gen-go
install.protoc-gen-go:
@$(GO) install github.com/golang/protobuf/protoc-gen-go@$(PROTOC_GEN_GO_VERSION)
## install.cfssl: Install cfssl, used to generate certificates
.PHONY: install.cfssl
install.cfssl:
@$(ROOT_DIR)/scripts/install/install.sh openim::install::install_cfssl
## install.depth: Install depth, used to check dependency tree
.PHONY: install.depth
install.depth:
@$(GO) install github.com/KyleBanks/depth/cmd/depth@$(DEPTH_VERSION)
## install.go-callvis: Install go-callvis, used to visualize call graph
.PHONY: install.go-callvis
install.go-callvis:
@$(GO) install github.com/ofabry/go-callvis@$(GO_CALLVIS_VERSION)
## install.misspell: Install misspell
.PHONY: install.misspell
install.misspell:
@$(GO) install github.com/client9/misspell/cmd/misspell@$(MISSPELL_VERSION)
## install.gothanks: Install gothanks, used to thank go dependencies
.PHONY: install.gothanks
install.gothanks:
@$(GO) install github.com/psampaz/gothanks@$(GOTHANKS_VERSION)
## install.richgo: Install richgo
.PHONY: install.richgo
install.richgo:
@$(GO) install github.com/kyoh86/richgo@$(RICHGO_VERSION)
## install.rts: Install rts
.PHONY: install.rts
install.rts:
@$(GO) install github.com/galeone/rts/cmd/rts@$(RTS_VERSION)
# ================= kubecub openim tools =========================================
# https://github.com/kubecub
## install.typecheck: Install kubecub typecheck, checks for go code
.PHONY: install.typecheck
install.typecheck:
@$(GO) install github.com/kubecub/typecheck@$(TYPECHECK_VERSION)
## install.comment-lang-detector: Install kubecub comment-lang-detector, checks for go code comment language
.PHONY: install.comment-lang-detector
install.comment-lang-detector:
@$(GO) install github.com/kubecub/comment-lang-detector/cmd/cld@$(COMMENT_LANG_DETECTOR_VERSION)
## install.standardizer: Install kubecub standardizer, checks for go code standardization
.PHONY: install.standardizer
install.standardizer:
@$(GO) install github.com/kubecub/standardizer@$(STANDARDIZER_VERSION)
## tools.help: Display help information about the tools package
.PHONY: tools.help
tools.help: scripts/make-rules/tools.mk
$(call smallhelp)

@ -1,150 +0,0 @@
#!/usr/bin/env bash
# Copyright © 2023 OpenIM. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Description:
# This script automates the process of building and releasing OpenIM,
# including tasks like setting up the environment, verifying prerequisites,
# building commands, packaging tarballs, uploading tarballs, creating GitHub
# releases, and generating changelogs.
#
# Usage:
# ./scripts/release.sh [options]
# Options include:
# -h, --help : Show help message
# -se, --setup-env : Execute setup environment
# -vp, --verify-prereqs : Execute prerequisites verification
# -bc, --build-command : Execute build command
# -bi, --build-image : Execute build image (default: not executed)
# -pt, --package-tarballs : Execute package tarballs
# -ut, --upload-tarballs : Execute upload tarballs
# -gr, --github-release : Execute GitHub release
# -gc, --generate-changelog: Execute generate changelog
#
# This script can also be executed via the 'make release' command as an alternative.
#
# Dependencies:
# This script depends on external scripts found in the 'scripts' directory and
# assumes the presence of necessary tools and permissions for building and
# releasing software.
#
# Note:
# The script uses standard bash script practices with error handling,
# and it defaults to executing all steps if no specific option is provided.
#
# Build a OpenIM release. This will build the binaries, create the Docker
# images and other build artifacts.
# Build a OpenIM release. This script supports various flags for flexible execution control.
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/common.sh"
source "${OPENIM_ROOT}/scripts/lib/release.sh"
OPENIM_RELEASE_RUN_TESTS=${OPENIM_RELEASE_RUN_TESTS-y}
# Function to show help message
show_help() {
echo "Usage: $(basename $0) [options]"
echo "Options:"
echo " -h, --help Show this help message"
echo " -se, --setup-env Execute setup environment"
echo " -vp, --verify-prereqs Execute prerequisites verification"
echo " -bc, --build-command Execute build command"
echo " -bi, --build-image Execute build image (default: not executed)"
echo " -pt, --package-tarballs Execute package tarballs"
echo " -ut, --upload-tarballs Execute upload tarballs"
echo " -gr, --github-release Execute GitHub release"
echo " -gc, --generate-changelog Execute generate changelog"
}
# Initialize all actions to false
perform_setup_env=false
perform_verify_prereqs=false
perform_build_command=false
perform_build_image=false # New flag for build image
perform_package_tarballs=false
perform_upload_tarballs=false
perform_github_release=false
perform_generate_changelog=false
# Process command-line arguments
while getopts "hsevpbciptutgrgc-" opt; do
case "${opt}" in
h) show_help; exit 0 ;;
se) perform_setup_env=true ;;
vp) perform_verify_prereqs=true ;;
bc) perform_build_command=true ;;
bi) perform_build_image=true ;; # Handling new option
pt) perform_package_tarballs=true ;;
ut) perform_upload_tarballs=true ;;
gr) perform_github_release=true ;;
gc) perform_generate_changelog=true ;;
--) case "${OPTARG}" in
help) show_help; exit 0 ;;
setup-env) perform_setup_env=true ;;
verify-prereqs) perform_verify_prereqs=true ;;
build-command) perform_build_command=true ;;
build-image) perform_build_image=true ;; # Handling new long option
package-tarballs) perform_package_tarballs=true ;;
upload-tarballs) perform_upload_tarballs=true ;;
github-release) perform_github_release=true ;;
generate-changelog) perform_generate_changelog=true ;;
*) echo "Invalid option: --${OPTARG}"; show_help; exit 1 ;;
esac ;;
*) show_help; exit 1 ;;
esac
done
# Enable all actions by default if no options are provided
if [ "$#" -eq 0 ]; then
perform_setup_env=true
perform_verify_prereqs=true
perform_build_command=true
perform_package_tarballs=true
perform_upload_tarballs=true
perform_github_release=true
perform_generate_changelog=true
# TODO: Not enabling build_image by default
# perform_build_image=true
fi
# Function to perform actions
perform_action() {
local flag=$1
local message=$2
local command=$3
if [ "$flag" == true ]; then
openim::log::info "## $message..."
if ! eval "$command"; then
openim::log::errexit "Error in $message"
fi
fi
}
echo "Starting script execution..."
perform_action $perform_setup_env "Setting up environment" "openim::golang::setup_env"
perform_action $perform_verify_prereqs "Verifying prerequisites" "openim::build::verify_prereqs && openim::release::verify_prereqs"
perform_action $perform_build_command "Executing build command" "openim::build::build_command"
perform_action $perform_build_image "Building image" "openim::build::build_image"
perform_action $perform_package_tarballs "Packaging tarballs" "openim::release::package_tarballs"
perform_action $perform_upload_tarballs "Uploading tarballs" "openim::release::upload_tarballs"
perform_action $perform_github_release "Creating GitHub release" "openim::release::github_release"
perform_action $perform_generate_changelog "Generating changelog" "openim::release::generate_changelog"
openim::log::success "OpenIM Relase Script Execution Completed."

@ -1,109 +0,0 @@
#!/usr/bin/env bash
# Copyright © 2023 OpenIM. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#FIXME This script is the startup script for multiple servers.
#FIXME The full names of the shell scripts that need to be started are placed in the `need_to_start_server_shell` array.
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/install/common.sh"
# Function to execute the scripts.
function execute_start_scripts() {
for script_path in "${OPENIM_SERVER_SCRIPT_START_LIST[@]}"; do
# Extract the script name without extension for argument generation.
script_name_with_prefix=$(basename "$script_path" .sh)
# Remove the "openim-" prefix.
script_name=${script_name_with_prefix#openim-}
# Construct the argument based on the script name.
arg="openim::${script_name}::start"
# Check if the script file exists and is executable.
if [[ -x "$script_path" ]]; then
openim::log::colorless "Starting script: ${script_path##*/}" # Log the script name.
# Execute the script with the constructed argument.
result=$("$script_path" "$arg")
if [[ $? -ne 0 ]]; then
openim::log::error "Start script: ${script_path##*/} failed"
openim::log::error "$result"
return 1
fi
else
openim::log::errexit "Script ${script_path##*/} is missing or not executable."
return 1
fi
done
}
if openim::util::is_running_in_container; then
exec >> ${DOCKER_LOG_FILE} 2>&1
fi
openim::golang::check_openim_binaries
if [[ $? -ne 0 ]]; then
openim::log::error "OpenIM binaries are not found. Please run 'make build' to build binaries."
"${OPENIM_ROOT}"/scripts/build-all-service.sh
fi
"${OPENIM_ROOT}"/scripts/init-config.sh --skip
#openim::log::print_blue "Execute the following script in sequence: ${OPENIM_SERVER_SCRIPTARIES[@]}"
# TODO Prelaunch tools, simple for now, can abstract functions later
TOOLS_START_SCRIPTS_PATH=${START_SCRIPTS_PATH}/openim-tools.sh
openim::log::status "Start the pre-start tools:"
# if ! ${TOOLS_START_SCRIPTS_PATH} openim::tools::pre-start; then
# openim::log::error "Start the pre-start tools, aborting!"
# exit 1
# fi
openim::log::colorless "pre-start has been successfully completed!"
result=$("${OPENIM_ROOT}"/scripts/stop-all.sh)
if [[ $? -ne 0 ]]; then
openim::log::error "View the error logs from this startup. ${LOG_FILE} \n"
openim::log::error "Some programs have not exited; the start process is aborted .\n $result"
exit 1
fi
openim::log::status "Start the OpenIM startup scripts: "
execute_start_scripts
openim::log::status "OpenIM startup scripts have been successfully completed!"
sleep 2
result=$(. $(dirname ${BASH_SOURCE})/install/openim-msgtransfer.sh openim::msgtransfer::check)
if [[ $? -ne 0 ]]; then
openim::log::error "The OpenIM services may fail to start.\n $result"
exit 1
fi
result=$(openim::util::check_process_names ${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]})
if [[ $? -ne 0 ]]; then
openim::log::error "The OpenIM services may fail to start.\n $result"
exit 1
fi
openim::log::status "Start the post-start tools:"
# ${TOOLS_START_SCRIPTS_PATH} openim::tools::post-start
openim::log::status "post-start has been successfully completed!"
openim::util::find_ports_for_all_services ${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]}
openim::util::find_ports_for_all_services ${OPENIM_MSGTRANSFER_BINARY[@]}
openim::log::success "All OpenIM services have been successfully started!"

@ -1,60 +0,0 @@
#!/usr/bin/env bash
# Copyright © 2023 OpenIM. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This script is stop all openim service
#
# Usage: `scripts/stop.sh`.
# Encapsulated as: `make stop`.
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/install/common.sh"
openim::log::status "Begin to stop all openim service"
openim::log::status "Stop all processes in the path ${OPENIM_OUTPUT_HOSTBIN}"
openim::util::stop_services_with_name "${OPENIM_OUTPUT_HOSTBIN}"
# todo OPENIM_ALL_SERVICE_LIBRARIES
max_retries=15
attempt=0
while [[ $attempt -lt $max_retries ]]
do
result=$(openim::util::check_process_names_for_stop)
if [[ $? -ne 0 ]]; then
if [[ $attempt -ne 0 ]] ; then
echo "+++ cat openim log file >>> ${LOG_FILE} " $attempt
openim::log::error "stop process failed. continue waiting\n" "${result}"
fi
sleep 1
((attempt++))
else
openim::log::success " All openim processes to be stopped"
exit 0
fi
done
openim::log::error "openim processes stopped failed"
exit 1
Loading…
Cancel
Save