Skip to content

Commit

Permalink
feat: supoort openim-chat source code deployment in mac (openimsdk#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
cubxxw committed Jan 22, 2024
1 parent 95646f9 commit 177d507
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 46 deletions.
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand All @@ -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
Expand Down
93 changes: 52 additions & 41 deletions scripts/check_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

3 changes: 1 addition & 2 deletions scripts/path_info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
16 changes: 16 additions & 0 deletions scripts/start_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 177d507

Please sign in to comment.