From 177d507bcfe0406e9bd505082f52698edb3dc509 Mon Sep 17 00:00:00 2001 From: Xinwei Xiong <3293172751NSS@gmail.com> Date: Mon, 22 Jan 2024 14:52:16 +0800 Subject: [PATCH] feat: supoort openim-chat source code deployment in mac (#386) --- README.md | 25 ++++++++++-- scripts/check_all.sh | 93 +++++++++++++++++++++++++------------------- scripts/path_info.sh | 3 +- scripts/start_all.sh | 16 ++++++++ 4 files changed, 91 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index a30ed383f..e5999374c 100644 --- a/README.md +++ b/README.md @@ -57,13 +57,13 @@ make init Then go back to the chat directory, Installing Chat -**Start Mysql:** +**Starting MySQL:** -> The newer versions of OpenIM remove the Mysql component, which requires an additional Mysql installation if you want to deploy chat +> Recent OpenIM versions have discontinued the MySQL component, necessitating a separate MySQL installation for chat deployment. ```bash docker run -d \ - --name mysql4 \ + --name mysql \ -p 13306:3306 \ -p 3306:33060 \ -v "$(pwd)/components/mysql/data:/var/lib/mysql" \ @@ -73,6 +73,25 @@ docker run -d \ mysql:5.7 ``` +**MySQL Compatibility Note:** + +The MySQL version 5.7 primarily supports the linux/amd64 architecture. Users operating on Mac or other architectures, or those with specific version requirements for MySQL, can opt for the latest version of the open-source MariaDB. MariaDB is compatible with MySQL and can be a suitable alternative. + +```bash +docker run -d \ + --name mysql \ + -p 13306:3306 \ + -p 3306:33060 \ + -v "$(pwd)/components/mysql/data:/var/lib/mysql" \ + -v "/etc/localtime:/etc/localtime" \ + -e MYSQL_ROOT_PASSWORD="openIM123" \ + --restart always \ + mariadb:10.6 +``` + +If you want to use a local or remote database, edit the `config/config.yaml` section after the initial configuration + + **Install Chat:** ```bash diff --git a/scripts/check_all.sh b/scripts/check_all.sh index 3f2777007..d17977eb0 100755 --- a/scripts/check_all.sh +++ b/scripts/check_all.sh @@ -50,60 +50,71 @@ sleep 10 # Define the path to the configuration YAML file config_yaml="$OPENIM_ROOT/config/config.yaml" # Replace with the actual path to your YAML file - # Function to extract a value from the YAML file and remove any leading/trailing whitespace extract_yaml_value() { local key=$1 - grep -oP "${key}: \[\s*\K[^\]]+" "$config_yaml" | xargs -} -# Extract port numbers from the YAML configuration -openImChatApiPort=$(extract_yaml_value 'openImChatApiPort') -openImAdminApiPort=$(extract_yaml_value 'openImAdminApiPort') -openImAdminPort=$(extract_yaml_value 'openImAdminPort') -openImChatPort=$(extract_yaml_value 'openImChatPort') - -for i in "${service_port_name[@]}"; do - case $i in - "openImChatApiPort") - new_service_name="chat-api" - new_service_port=$openImChatApiPort - ;; - "openImAdminApiPort") - new_service_name="admin-api" - new_service_port=$openImAdminApiPort - ;; - "openImAdminPort") - new_service_name="admin-rpc" - new_service_port=$openImAdminPort + # Detect the operating system + case "$(uname)" in + "Linux") + # Use grep with Perl-compatible regex for Linux + grep -oP "${key}: \[\s*\K[^\]]+" "$config_yaml" | xargs ;; - "openImChatPort") - new_service_name="chat-rpc" - new_service_port=$openImChatPort + "Darwin") + # Use sed for macOS + sed -n "s/^${key}: \[\s*\([^]]*\).*$/\1/p" "$config_yaml" | xargs ;; *) - echo "Invalid service name: $i" - exit -1 + echo "Unsupported operating system" + exit 1 ;; esac +} +# Extract port numbers from the YAML configuration +declare -A service_ports=( + ["openImChatApiPort"]="chat-api" + ["openImAdminApiPort"]="admin-api" + ["openImAdminPort"]="admin-rpc" + ["openImChatPort"]="chat-rpc" +) - ports=$(ss -tunlp | grep "$new_service_name" | awk '{print $5}' | awk -F '[:]' '{print $NF}') +for i in "${!service_ports[@]}"; do + service_port=$(extract_yaml_value "$i") + new_service_name=${service_ports[$i]} -found_port=false -for port in $ports; do - if [[ "$port" == "$new_service_port" ]]; then - echo -e "${new_service_port}${GREEN_PREFIX} port has been listening, belongs service is ${i}${COLOR_SUFFIX}" - found_port=true - break + # Check for empty port value + if [ -z "$service_port" ]; then + echo "No port value found for $i" + continue fi -done -if [[ "$found_port" != true ]]; then - echo -e "${YELLOW_PREFIX}${i}${COLOR_SUFFIX}${RED_PREFIX} service does not start normally, expected port is ${COLOR_SUFFIX}${YELLOW_PREFIX}${new_service_port}${COLOR_SUFFIX}" - echo -e "${RED_PREFIX}please check ${SCRIPTS_ROOT}/../logs/openIM.log ${COLOR_SUFFIX}" - exit -1 -fi + # Determine command based on OS + case "$(uname)" in + "Linux") + ports=$(ss -tunlp | grep "$new_service_name" | awk '{print $5}' | awk -F '[:]' '{print $NF}') + ;; + "Darwin") + ports=$(lsof -i -P | grep LISTEN | grep "$new_service_name" | awk '{print $9}' | awk -F '[:]' '{print $2}') + ;; + *) + echo "Unsupported operating system" + exit 1 + ;; + esac + found_port=false + for port in $ports; do + if [[ "$port" == "$service_port" ]]; then + echo -e "${service_port}${GREEN_PREFIX} port has been listening, belongs service is ${new_service_name}${COLOR_SUFFIX}" + found_port=true + break + fi + done + + if [[ "$found_port" != true ]]; then + echo -e "${YELLOW_PREFIX}${new_service_name}${COLOR_SUFFIX}${RED_PREFIX} service does not start normally, expected port is ${COLOR_SUFFIX}${YELLOW_PREFIX}${service_port}${COLOR_SUFFIX}" + echo -e "${RED_PREFIX}please check ${SCRIPTS_ROOT}/../logs/openIM.log ${COLOR_SUFFIX}" + exit -1 + fi done - diff --git a/scripts/path_info.sh b/scripts/path_info.sh index 54c8f31cb..abbaf72ef 100755 --- a/scripts/path_info.sh +++ b/scripts/path_info.sh @@ -13,8 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. - - #Don't put the space between "=" #Include shell font styles and some basic information @@ -39,6 +37,7 @@ declare -A supported_architectures=( ["linux-ppc64le"]="_output/bin/platforms/linux/ppc64le" ["linux-s390x"]="_output/bin/platforms/linux/s390x" ["darwin-amd64"]="_output/bin/platforms/darwin/amd64" + ["darwin-arm64"]="_output/bin/platforms/darwin/arm64" ["windows-amd64"]="_output/bin/platforms/windows/amd64" ["linux-x86_64"]="_output/bin/platforms/linux/amd64" # Alias for linux-amd64 ["darwin-x86_64"]="_output/bin/platforms/darwin/amd64" # Alias for darwin-amd64 diff --git a/scripts/start_all.sh b/scripts/start_all.sh index 4c6c14abb..26588a435 100755 --- a/scripts/start_all.sh +++ b/scripts/start_all.sh @@ -41,6 +41,22 @@ logs_dir="$SCRIPTS_ROOT/../logs" echo -e "${YELLOW_PREFIX}=======>bin_dir=$bin_dir${COLOR_SUFFIX}" echo -e "${YELLOW_PREFIX}=======>logs_dir=$logs_dir${COLOR_SUFFIX}" +# Define the path to the configuration file +CONFIG_FILE="${OPENIM_ROOT}/config/config.yaml" + +# Check if the configuration file exists +if [ -f "$CONFIG_FILE" ]; then + # The file exists + echo "Configuration file already exists at $CONFIG_FILE." +else + echo "" + # The file does not exist + echo "Error: Configuration file does not exist." + echo "+++ You need to execute 'make init' to generate the configuration file and then modify the configuration items." + echo "" + exit 1 +fi + #service filename service_filename=( chat-api