fix: add openim scripts check and mac support ss comment

Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>
pull/1570/head
Xinwei Xiong (cubxxw) 2 years ago
parent b493ced1ef
commit cbf09cdafd

@ -200,8 +200,9 @@ API_OPENIM_PORT=10002
# ====================================== # ======================================
# Branch name for OpenIM chat. # Branch name for OpenIM chat.
# Default: CHAT_BRANCH=main # Default: CHAT_IMAGE_VERSION=main
CHAT_BRANCH=main # https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/version.md
CHAT_IMAGE_VERSION=main
# Address or hostname for the OpenIM chat service. # Address or hostname for the OpenIM chat service.
# Default: OPENIM_CHAT_ADDRESS=172.28.0.1 # Default: OPENIM_CHAT_ADDRESS=172.28.0.1
@ -221,8 +222,8 @@ OPENIM_CHAT_DATA_DIR=./openim-chat/main
# ====================================== # ======================================
# Branch name for OpenIM server. # Branch name for OpenIM server.
# Default: SERVER_BRANCH=main # Default: SERVER_IMAGE_VERSION=main
SERVER_BRANCH=main SERVER_IMAGE_VERSION=main
# Port for the OpenIM admin API. # Port for the OpenIM admin API.
# Default: OPENIM_ADMIN_API_PORT=10009 # Default: OPENIM_ADMIN_API_PORT=10009

@ -200,8 +200,8 @@ API_OPENIM_PORT=${API_OPENIM_PORT}
# ====================================== # ======================================
# Branch name for OpenIM chat. # Branch name for OpenIM chat.
# Default: CHAT_BRANCH=main # Default: CHAT_IMAGE_VERSION=main
CHAT_BRANCH=${CHAT_BRANCH} CHAT_IMAGE_VERSION=${CHAT_IMAGE_VERSION}
# Address or hostname for the OpenIM chat service. # Address or hostname for the OpenIM chat service.
# Default: OPENIM_CHAT_ADDRESS=172.28.0.1 # Default: OPENIM_CHAT_ADDRESS=172.28.0.1
@ -221,8 +221,8 @@ OPENIM_CHAT_DATA_DIR=${OPENIM_CHAT_DATA_DIR}
# ====================================== # ======================================
# Branch name for OpenIM server. # Branch name for OpenIM server.
# Default: SERVER_BRANCH=main # Default: SERVER_IMAGE_VERSION=main
SERVER_BRANCH=${SERVER_BRANCH} SERVER_IMAGE_VERSION=${SERVER_IMAGE_VERSION}
# Port for the OpenIM admin API. # Port for the OpenIM admin API.
# Default: OPENIM_ADMIN_API_PORT=10009 # Default: OPENIM_ADMIN_API_PORT=10009

@ -104,18 +104,18 @@ Docker deployment offers a slightly more intricate template. Within the [openim-
Configuration file modifications can be made by specifying corresponding environment variables, for instance: Configuration file modifications can be made by specifying corresponding environment variables, for instance:
```bash ```bash
export CHAT_BRANCH="main" export CHAT_IMAGE_VERSION="main"
export SERVER_BRANCH="main" export SERVER_IMAGE_VERSION="main"
``` ```
These variables are stored within the [`environment.sh`](https://github.com/OpenIMSDK/openim-docker/blob/main/scripts/install/environment.sh) configuration: These variables are stored within the [`environment.sh`](https://github.com/OpenIMSDK/openim-docker/blob/main/scripts/install/environment.sh) configuration:
```bash ```bash
readonly CHAT_BRANCH=${CHAT_BRANCH:-'main'} readonly CHAT_IMAGE_VERSION=${CHAT_IMAGE_VERSION:-'main'}
readonly SERVER_BRANCH=${SERVER_BRANCH:-'main'} readonly SERVER_IMAGE_VERSION=${SERVER_IMAGE_VERSION:-'main'}
``` ```
Setting a variable, e.g., `export CHAT_BRANCH="release-v1.3"`, will prioritize `CHAT_BRANCH="release-v1.3"` as the variable value. Ultimately, the chosen image version is determined, and rendering is achieved through `make init` (or `./scripts/init-config.sh`). Setting a variable, e.g., `export CHAT_IMAGE_VERSION="release-v1.3"`, will prioritize `CHAT_IMAGE_VERSION="release-v1.3"` as the variable value. Ultimately, the chosen image version is determined, and rendering is achieved through `make init` (or `./scripts/init-config.sh`).
> Note: Direct modifications to the `config.yaml` file are also permissible without utilizing `make init`. > Note: Direct modifications to the `config.yaml` file are also permissible without utilizing `make init`.

@ -33,9 +33,8 @@ openim::log::info "\n# Begin to check all openim service"
# OpenIM status # OpenIM status
# Elegant printing function # Elegant printing function
print_services_and_ports() { print_services_and_ports() {
# 获取数组 local -n service_names=$1
declare -g service_names=("${!1}") local -n service_ports=$2
declare -g service_ports=("${!2}")
echo "+-------------------------+----------+" echo "+-------------------------+----------+"
echo "| Service Name | Port |" echo "| Service Name | Port |"
@ -48,7 +47,6 @@ print_services_and_ports() {
echo "+-------------------------+----------+" echo "+-------------------------+----------+"
} }
# Print out services and their ports # Print out services and their ports
print_services_and_ports OPENIM_SERVER_NAME_TARGETS OPENIM_SERVER_PORT_TARGETS print_services_and_ports OPENIM_SERVER_NAME_TARGETS OPENIM_SERVER_PORT_TARGETS

@ -66,8 +66,8 @@ def "ENV_FILE" ""${OPENIM_ROOT}"/scripts/install/environment.sh"
###################### Docker compose ################### ###################### Docker compose ###################
# OPENIM AND CHAT # OPENIM AND CHAT
def "CHAT_BRANCH" "main" def "CHAT_IMAGE_VERSION" "main"
def "SERVER_BRANCH" "main" def "SERVER_IMAGE_VERSION" "main"
# Choose the appropriate image address, the default is GITHUB image, # Choose the appropriate image address, the default is GITHUB image,
# you can choose docker hub, for Chinese users can choose Ali Cloud # you can choose docker hub, for Chinese users can choose Ali Cloud
@ -139,7 +139,7 @@ readonly API_OPENIM_PORT=${API_OPENIM_PORT:-'10002'}
def "API_LISTEN_IP" "0.0.0.0" # API的监听IP def "API_LISTEN_IP" "0.0.0.0" # API的监听IP
###################### openim-chat 配置信息 ###################### ###################### openim-chat 配置信息 ######################
def "OPENIM_CHAT_DATA_DIR" "./openim-chat/${CHAT_BRANCH}" def "OPENIM_CHAT_DATA_DIR" "./openim-chat/${CHAT_IMAGE_VERSION}"
def "OPENIM_CHAT_ADDRESS" "${DOCKER_BRIDGE_GATEWAY}" # OpenIM服务地址 def "OPENIM_CHAT_ADDRESS" "${DOCKER_BRIDGE_GATEWAY}" # OpenIM服务地址
def "OPENIM_CHAT_API_PORT" "10008" # OpenIM API端口 def "OPENIM_CHAT_API_PORT" "10008" # OpenIM API端口
def "CHAT_API_LISTEN_IP" "" # OpenIM API的监听IP def "CHAT_API_LISTEN_IP" "" # OpenIM API的监听IP

@ -302,8 +302,12 @@ openim::util::check_ports() {
# Iterate over each given port. # Iterate over each given port.
for port in "$@"; do for port in "$@"; do
# Use the `ss` command to find process information related to the given port. # Use the `ss` command to find process information related to the given port.
local info=$(ss -ltnp | grep ":$port" || true) if command -v ss > /dev/null 2>&1; then
info=$(ss -ltnp | grep ":$port" || true)
else
info=$(netstat -ltnp | grep ":$port" || true)
fi
# If there's no process information, it means the process associated with the port is not running. # If there's no process information, it means the process associated with the port is not running.
if [[ -z $info ]]; then if [[ -z $info ]]; then
not_started+=($port) not_started+=($port)
@ -364,6 +368,18 @@ openim::util::check_ports() {
# openim::util::check_process_names nginx mysql redis # openim::util::check_process_names nginx mysql redis
# The function returns a status of 1 if any of the processes is not running. # The function returns a status of 1 if any of the processes is not running.
openim::util::check_process_names() { openim::util::check_process_names() {
# Function to get the port of a process
get_port() {
local pid=$1
if command -v ss > /dev/null 2>&1; then
# used ss comment
ss -ltnp 2>/dev/null | grep $pid | awk '{print $4}' | cut -d ':' -f2
else
# used netstat comment replace ss
netstat -ltnp 2>/dev/null | grep $pid | awk '{print $4}' | sed 's/.*://'
fi
}
# Arrays to collect details of processes # Arrays to collect details of processes
local not_started=() local not_started=()
local started=() local started=()
@ -382,7 +398,7 @@ openim::util::check_process_names() {
for pid in "${pids[@]}"; do for pid in "${pids[@]}"; do
local command=$(ps -p $pid -o cmd=) local command=$(ps -p $pid -o cmd=)
local start_time=$(ps -p $pid -o lstart=) local start_time=$(ps -p $pid -o lstart=)
local port=$(ss -ltnp 2>/dev/null | grep $pid | awk '{print $4}' | cut -d ':' -f2) local port=$(get_port $pid)
# Check if port information was found for the PID # Check if port information was found for the PID
if [[ -z $port ]]; then if [[ -z $port ]]; then
@ -419,6 +435,7 @@ openim::util::check_process_names() {
return 0 return 0
fi fi
} }
# openim::util::check_process_names docker-pr # openim::util::check_process_names docker-pr
# The `openim::util::stop_services_on_ports` function stops services running on specified ports. # The `openim::util::stop_services_on_ports` function stops services running on specified ports.

Loading…
Cancel
Save