diff --git a/scripts/admin_rpc_start.sh b/scripts/admin_rpc_start.sh index f6a638228..72adcda48 100755 --- a/scripts/admin_rpc_start.sh +++ b/scripts/admin_rpc_start.sh @@ -42,7 +42,7 @@ sleep 1 cd ${push_binary_root} for ((i = 0; i < ${#rpc_ports[@]}; i++)); do - nohup ./${push_name} -port ${rpc_ports[$i]} -prometheus_port ${prome_ports[$i]} >>../logs/openIM.log 2>&1 & + nohup ./${push_name} -port ${rpc_ports[$i]} -prometheus_port ${prome_ports[$i]} >>../logs/openim_$(date '+%Y%m%d').log 2>&1 & done sleep 3 @@ -61,5 +61,5 @@ if [ $check -ge 1 ]; then echo -e ${SKY_BLUE_PREFIX}"PID: "${COLOR_SUFFIX}${YELLOW_PREFIX}${newPid}${COLOR_SUFFIX} echo -e ${SKY_BLUE_PREFIX}"LISTENING_PORT: "${COLOR_SUFFIX}${YELLOW_PREFIX}${allPorts}${COLOR_SUFFIX} else - echo -e ${YELLOW_PREFIX}${push_name}${COLOR_SUFFIX}${RED_PREFIX}"SERVICE START ERROR, PLEASE CHECK openIM.log"${COLOR_SUFFIX} + echo -e ${YELLOW_PREFIX}${push_name}${COLOR_SUFFIX}${RED_PREFIX}"SERVICE START ERROR, PLEASE CHECK openim_$(date '+%Y%m%d').log"${COLOR_SUFFIX} fi diff --git a/scripts/build_all_service.sh b/scripts/build_all_service.sh index 054cd3fab..b78889aca 100755 --- a/scripts/build_all_service.sh +++ b/scripts/build_all_service.sh @@ -40,7 +40,11 @@ echo -e "${BOLD_PREFIX}_________________________________________________________ bin_dir="$BIN_DIR" -logs_dir="$OPENIM_ROOT/logs" +logs_dir="$OPENIM_ROOT/_output/logs" + +if [ ! -d $logs_dir ]; then + mkdir -p $logs_dir +fi echo "==> bin_dir=$bin_dir" echo "==> logs_dir=$logs_dir" diff --git a/scripts/check_all.sh b/scripts/check_all.sh index 656789bb3..cb1ac16b7 100755 --- a/scripts/check_all.sh +++ b/scripts/check_all.sh @@ -29,7 +29,7 @@ fi mkdir -p ${SCRIPTS_ROOT}/../logs # 如果没有设置 PRINT_SCREEN 标记,那么进行日志重定向 if [ -z "$PRINT_SCREEN" ]; then - exec >> ${SCRIPTS_ROOT}/../logs/openIM.log 2>&1 + exec >> ${SCRIPTS_ROOT}/../logs/openim_$(date '+%Y%m%d').log 2>&1 fi #Include shell font styles and some basic information @@ -50,50 +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 + # Detect the operating system + case "$(uname)" in + "Linux") + # Use grep with Perl-compatible regex for Linux + grep -oP "${key}: \[\s*\K[^\]]+" "$config_yaml" | xargs ;; - "openImAdminApiPort") - new_service_name="admin-api" - new_service_port=$openImAdminApiPort + "Darwin") + # Use sed for macOS + sed -nE "/${key}: \[ */{s///; s/\].*//; p;}" "$config_yaml" | tr -d '[]' | xargs ;; - "openImAdminPort") - new_service_name="admin-rpc" - new_service_port=$openImAdminPort + *) + echo "Unsupported operating system" + exit 1 ;; - "openImChatPort") - new_service_name="chat-rpc" - new_service_port=$openImChatPort + esac +} + +# Extract port numbers from the YAML configuration +declare -A service_ports=( + ["openImChatApiPort"]="chat-api" + ["openImAdminApiPort"]="admin-api" + ["openImAdminPort"]="admin-rpc" + ["openImChatPort"]="chat-rpc" +) + +for i in "${!service_ports[@]}"; do + service_port=$(extract_yaml_value "$i") + new_service_name=${service_ports[$i]} + + # Check for empty port value + if [ -z "$service_port" ]; then + echo "No port value found for $i" + continue + 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 "Invalid service name: $i" - exit -1 + echo "Unsupported operating system" + exit 1 ;; esac - port=$(ss -tunlp | grep "$new_service_name" | awk '{print $5}' | awk -F '[:]' '{print $NF}') - if [[ "$port" != "$new_service_port" ]]; then - echo -e "${YELLOW_PREFIX}${i}${COLOR_SUFFIX}${RED_PREFIX} service does not start normally, not initiated port is ${COLOR_SUFFIX}${YELLOW_PREFIX}${new_service_port}${COLOR_SUFFIX}" - echo -e "${RED_PREFIX}please check ${SCRIPTS_ROOT}/../logs/openIM.log ${COLOR_SUFFIX}" + 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/chat_$(date '+%Y%m%d').log ${COLOR_SUFFIX}" exit -1 - else - echo -e "${new_service_port}${GREEN_PREFIX} port has been listening, belongs service is ${i}${COLOR_SUFFIX}" fi done - diff --git a/scripts/docker_start_all.sh b/scripts/docker_start_all.sh index f6f497285..a3a9a5315 100755 --- a/scripts/docker_start_all.sh +++ b/scripts/docker_start_all.sh @@ -100,7 +100,7 @@ for ((i = 0; i < ${#service_filenames[*]}; i++)); do cmd="$bin_dir/$service_name -port $port --config_folder_path $config_path" fi echo "$cmd" - nohup $cmd >> "${logs_dir}/openIM.log" 2>&1 & + nohup $cmd >> "${logs_dir}/openim_$(date '+%Y%m%d').log" 2>&1 & sleep 1 done done @@ -108,4 +108,4 @@ done sleep 50 ${OPENIM_ROOT}/scripts/check_all.sh -tail -f ${logs_dir}/openIM.log +tail -f ${logs_dir}/openim_$(date '+%Y%m%d').log 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..de321114e 100755 --- a/scripts/start_all.sh +++ b/scripts/start_all.sh @@ -36,11 +36,27 @@ echo -e "${YELLOW_PREFIX}=======>pwd=$PWD${COLOR_SUFFIX}" # fi bin_dir="$BIN_DIR" -logs_dir="$SCRIPTS_ROOT/../logs" +logs_dir="$SCRIPTS_ROOT/../_output/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 @@ -103,7 +119,7 @@ for ((i = 0; i < ${#service_filename[*]}; i++)); do cmd="$bin_dir/${service_filename[$i]} -port ${service_ports[$j]} --config_folder_path ${config_path}" fi echo $cmd - nohup $cmd >>${logs_dir}/openIM.log 2>&1 & + nohup $cmd >>${logs_dir}/openim_$(date '+%Y%m%d').log 2>&1 & sleep 1 # pid="netstat -ntlp|grep $j |awk '{printf \$7}'|cut -d/ -f1" # echo -e "${GREEN_PREFIX}${service_filename[$i]} start success,port number:${service_ports[$j]} pid:$(eval $pid)$COLOR_SUFFIX"