From a3f96760b4d5610cccc938216a80239a1a6d8738 Mon Sep 17 00:00:00 2001 From: "Xinwei Xiong(cubxxw-openim)" <3293172751nss@gmail.com> Date: Fri, 4 Aug 2023 11:54:30 +0800 Subject: [PATCH] fix: scripts path Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> --- Dockerfile | 17 +++++++---------- cmd/rpc/admin-rpc/Makefile | 2 +- cmd/rpc/chat-rpc/Makefile | 2 +- pkg/common/config/version | 2 +- scripts/admin_rpc_start.sh | 10 +++++----- scripts/build_all_service.sh | 2 +- scripts/build_docker.sh | 6 ++++++ scripts/docker_start_all.sh | 27 +++++++++++++++++++++------ scripts/path_info.sh | 16 ++++++---------- scripts/start_all.sh | 21 ++++++++++++--------- scripts/stop_all.sh | 2 +- scripts/style_info.sh | 0 12 files changed, 62 insertions(+), 45 deletions(-) mode change 100644 => 100755 scripts/path_info.sh mode change 100644 => 100755 scripts/style_info.sh diff --git a/Dockerfile b/Dockerfile index 29aeb5dba..d1e03ee71 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,22 +29,19 @@ ENV GOPROXY=$GOPROXY COPY go.mod go.sum ./ RUN go mod download -COPY . . +# Copy all files to the container +ADD . . -# Compile the source code -RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o /openim/openim-chat/bin/admin-rpc ./cmd/rpc/admin-rpc -RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o /openim/openim-chat/bin/admin-api ./cmd/api/admin-api -RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o /openim/openim-chat/bin/chat-rpc ./cmd/rpc/chat-rpc -RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o /openim/openim-chat/bin/chat-api ./cmd/api/chat-api +RUN /bin/sh -c "make clean" +RUN /bin/sh -c "make build" # Build the runtime stage FROM ghcr.io/openim-sigs/openim-bash-image:v1.3.0 -# Set fixed project path -WORKDIR /openim/openim-chat +WORKDIR ${CHAT_WORKDIR} -COPY --from=builder ${OPENIM_CHAT_BINDIR} /openim/openim-chat/bin +COPY --from=builder /openim/openim-chat/_output/bin/platforms /openim/openim-chat/_output/bin/platforms COPY --from=builder ${OPENIM_CHAT_CMDDIR} /openim/openim-chat/scripts COPY --from=builder ${OPENIM_CHAT_CONFIG_NAME} /openim/openim-chat/config/config.yaml -CMD ["bash","-c","${OPENIM_CHAT_CMDDIR}/docker_start_all.sh"] \ No newline at end of file +CMD ${OPENIM_CHAT_CMDDIR}/docker_start_all.sh \ No newline at end of file diff --git a/cmd/rpc/admin-rpc/Makefile b/cmd/rpc/admin-rpc/Makefile index a38cb4457..f4ff0f59e 100644 --- a/cmd/rpc/admin-rpc/Makefile +++ b/cmd/rpc/admin-rpc/Makefile @@ -1,6 +1,6 @@ .PHONY: all build run gotool install clean help -BINARY_NAME=open_im_admin +BINARY_NAME=admin-rpc BIN_DIR=../../../bin/ all: gotool build diff --git a/cmd/rpc/chat-rpc/Makefile b/cmd/rpc/chat-rpc/Makefile index ab6334a62..9368c60a3 100644 --- a/cmd/rpc/chat-rpc/Makefile +++ b/cmd/rpc/chat-rpc/Makefile @@ -1,6 +1,6 @@ .PHONY: all build run gotool install clean help -BINARY_NAME=open_im_chat +BINARY_NAME=chat-rpc BIN_DIR=../../../bin/ all: gotool build diff --git a/pkg/common/config/version b/pkg/common/config/version index 1c5ae5820..3a285c2be 100644 --- a/pkg/common/config/version +++ b/pkg/common/config/version @@ -1 +1 @@ -v3.0.0 \ No newline at end of file +v3.1.0 \ No newline at end of file diff --git a/scripts/admin_rpc_start.sh b/scripts/admin_rpc_start.sh index 3afdeb0f7..89f7e2fef 100755 --- a/scripts/admin_rpc_start.sh +++ b/scripts/admin_rpc_start.sh @@ -15,7 +15,7 @@ #Include shell font styles and some basic information SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) -OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. +OPENIM_ROOT=$(dirname "${SCRIPTS_ROOT}")/.. source $OPENIM_ROOT/scripts/style_info.sh source $OPENIM_ROOT/scripts/path_info.sh @@ -30,9 +30,9 @@ prome_ports=($ports_array) #Check if the service exists #If it is exists,kill this process -check=$(ps aux | grep -w ./${push_name} | grep -v grep | wc -l) +check=$(ps | grep -w ./${push_name} | grep -v grep | wc -l) if [ $check -ge 1 ]; then - oldPid=$(ps aux | grep -w ./${push_name} | grep -v grep | awk '{print $2}') + oldPid=$(ps | grep -w ./${push_name} | grep -v grep | awk '{print $2}') kill -9 $oldPid fi #Waiting port recycling @@ -45,9 +45,9 @@ done sleep 3 #Check launched service process -check=$(ps aux | grep -w ./${push_name} | grep -v grep | wc -l) +check=$(ps | grep -w ./${push_name} | grep -v grep | wc -l) if [ $check -ge 1 ]; then - newPid=$(ps aux | grep -w ./${push_name} | grep -v grep | awk '{print $2}') + newPid=$(ps | grep -w ./${push_name} | grep -v grep | awk '{print $2}') ports=$(netstat -netulp | grep -w ${newPid} | awk '{print $4}' | awk -F '[:]' '{print $NF}') allPorts="" diff --git a/scripts/build_all_service.sh b/scripts/build_all_service.sh index fd6ad6dcd..2b80fbab7 100755 --- a/scripts/build_all_service.sh +++ b/scripts/build_all_service.sh @@ -50,7 +50,7 @@ if [ ! -d $sdk_db_dir ]; then mkdir -p $sdk_db_dir fi -cd $OPENIM_ROOT +cd $SCRIPTS_ROOT/.. # CPU core number cpu_count=$(lscpu | grep -e '^CPU(s):' | awk '{print $2}') diff --git a/scripts/build_docker.sh b/scripts/build_docker.sh index a11ce5abe..1772d8d01 100755 --- a/scripts/build_docker.sh +++ b/scripts/build_docker.sh @@ -11,6 +11,12 @@ # 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. + +#Include shell font styles and some basic information +SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +OPENIM_ROOT=$(dirname "${SCRIPTS_ROOT}")/.. + + IMAGE_VERSION=v1.1.0 image=openim/openim_chat:$IMAGE_VERSION diff --git a/scripts/docker_start_all.sh b/scripts/docker_start_all.sh index aacfa6498..d9e77a91c 100755 --- a/scripts/docker_start_all.sh +++ b/scripts/docker_start_all.sh @@ -13,13 +13,28 @@ # See the License for the specific language governing permissions and # limitations under the License. +#Include shell font styles and some basic information SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) -OPENIM_ROOT=$(dirname "${SCRIPTS_ROOT}")/.. +OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. ${SCRIPTS_ROOT}/start_all.sh -i=1 -while ((i == 1)) -do - sleep 5 -done \ No newline at end of file +#fixme The 10 second delay to start the project is for the docker-compose one-click to start openIM when the infrastructure dependencies are not started + +sleep 10 +time=`date +"%Y-%m-%d %H:%M:%S"` +echo "==========================================================">>$OPENIM_ROOT/logs/openIM.log 2>&1 & +echo "==========================================================">>$OPENIM_ROOT/logs/openIM.log 2>&1 & +echo "==========================================================">>$OPENIM_ROOT/logs/openIM.log 2>&1 & +echo "==========server start time:${time}===========">>$OPENIM_ROOT/logs/openIM.log 2>&1 & +echo "==========================================================">>$OPENIM_ROOT/logs/openIM.log 2>&1 & +echo "==========================================================">>$OPENIM_ROOT/logs/openIM.log 2>&1 & +echo "==========================================================">>$OPENIM_ROOT/logs/openIM.log 2>&1 & +for i in ${need_to_start_server_shell[*]}; do + $i +done + +sleep 15 + +#fixme prevents the openIM service exit after execution in the docker container +tail -f /dev/null diff --git a/scripts/path_info.sh b/scripts/path_info.sh old mode 100644 new mode 100755 index f99f84495..4e5b3be9c --- a/scripts/path_info.sh +++ b/scripts/path_info.sh @@ -2,11 +2,9 @@ #Don't put the space between "=" -OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. +#Include shell font styles and some basic information SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) - -demo_server_name="chat-api" -demo_server_binary_root="${OPENIM_ROOT}/bin/" +OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. # Determine the architecture and version architecture=$(uname -m) @@ -40,14 +38,14 @@ fi echo -e "${BLUE_PREFIX}================> Architecture: $architecture${COLOR_SUFFIX}" # Set the BIN_DIR based on the architecture and version -BIN_DIR=${supported_architectures["$version-$architecture"]} +BIN_DIR=${SCRIPTS_ROOT}/../${supported_architectures["$version-$architecture"]} echo -e "${BLUE_PREFIX}================> BIN_DIR: $OPENIM_ROOT/$BIN_DIR${COLOR_SUFFIX}" #Global configuration file default dir -config_path="$SCRIPTS_ROOT/../config/config.yaml" +config_path="$OPENIM_ROOT/config/config.yaml" configfile_path="$OPENIM_ROOT/config" -log_path="$SCRIPTS_ROOT/../log" +log_path="$OPENIM_ROOT/log" #servicefile dir path service_source_root=( @@ -60,10 +58,8 @@ service_source_root=( ) #service filename service_names=( - #api service filename chat-api admin-api - #rpc service filename - admin-rpc chat-rpc + admin-rpc ) diff --git a/scripts/start_all.sh b/scripts/start_all.sh index 5fb21e4a9..66d6befec 100755 --- a/scripts/start_all.sh +++ b/scripts/start_all.sh @@ -13,8 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. +#Include shell font styles and some basic information SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +OPENIM_ROOT=$(dirname "${SCRIPTS_ROOT}")/.. source $SCRIPTS_ROOT/style_info.sh source $SCRIPTS_ROOT/path_info.sh @@ -24,12 +25,13 @@ echo -e "${YELLOW_PREFIX}=======>SCRIPTS_ROOT=$SCRIPTS_ROOT${COLOR_SUFFIX}" echo -e "${YELLOW_PREFIX}=======>OPENIM_ROOT=$OPENIM_ROOT${COLOR_SUFFIX}" echo -e "${YELLOW_PREFIX}=======>pwd=$PWD${COLOR_SUFFIX}" -if [ ! -d "${OPENIM_ROOT}/_output/bin/platforms" ]; then - # exec build_all_service.sh - "${SCRIPTS_ROOT}/build_all_service.sh" -fi +# if [ ! -d "${OPENIM_ROOT}/_output/bin/platforms" ]; then +# cd $OPENIM_ROOT +# # exec build_all_service.sh +# "${SCRIPTS_ROOT}/build_all_service.sh" +# fi -bin_dir="$SCRIPTS_ROOT/../bin" +bin_dir="$BIN_DIR" logs_dir="$SCRIPTS_ROOT/../logs" sdk_db_dir="$SCRIPTS_ROOT/../sdk/db/" @@ -42,8 +44,8 @@ service_filename=( chat-api admin-api #rpc - open_im_admin - open_im_chat + admin-rpc + chat-rpc ) #service config port name @@ -63,7 +65,7 @@ cd $SCRIPTS_ROOT for ((i = 0; i < ${#service_filename[*]}; i++)); do #Check whether the service exists - service_name="ps -aux |grep -w ${service_filename[$i]} |grep -v grep" + service_name="ps |grep -w ${service_filename[$i]} |grep -v grep" count="${service_name}| wc -l" if [ $(eval ${count}) -gt 0 ]; then @@ -75,6 +77,7 @@ for ((i = 0; i < ${#service_filename[*]}; i++)); do sleep 0.5 fi cd $SCRIPTS_ROOT + #Get the rpc port in the configuration file portList=$(cat $config_path | grep ${service_port_name[$i]} | awk -F '[:]' '{print $NF}') list_to_string ${portList} diff --git a/scripts/stop_all.sh b/scripts/stop_all.sh index 692ced96e..c1b03b755 100755 --- a/scripts/stop_all.sh +++ b/scripts/stop_all.sh @@ -24,7 +24,7 @@ cd "$SCRIPTS_ROOT" for i in ${service_names[*]}; do #Check whether the service exists - name="ps -aux |grep -w $i |grep -v grep" + name="ps -T |grep -w $i |grep -v grep" count="${name}| wc -l" if [ $(eval ${count}) -gt 0 ]; then pid="${name}| awk '{print \$2}'" diff --git a/scripts/style_info.sh b/scripts/style_info.sh old mode 100644 new mode 100755