From 810b1ccbb3f09099b82c51f381eaca0322c3fbdb Mon Sep 17 00:00:00 2001 From: "Xinwei Xiong(cubxxw-openim)" <3293172751nss@gmail.com> Date: Wed, 9 Aug 2023 22:08:29 +0800 Subject: [PATCH] feat: add makefile feature Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> --- Makefile | 16 +++++++++++++++- scripts/build_all_service.sh | 5 ----- scripts/make-rules/golang.mk | 24 ++++++++++++++++++------ scripts/push_start.sh | 8 ++++---- scripts/start_all.sh | 4 ---- 5 files changed, 37 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index 7ba608be5..78ea2a66a 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ ## all: Run tidy, gen, add-copyright, format, lint, cover, build ✨ .PHONY: all -all: tidy gen add-copyright format lint cover build +all: tidy gen add-copyright lint cover restart # ============================================================================== # Build set @@ -58,6 +58,20 @@ export USAGE_OPTIONS build: @$(MAKE) go.build +## start: Start openim ✨ +.PHONY: start +start: + @$(MAKE) go.start + +## stop: Stop openim ✨ +.PHONY: stop +stop: + @$(MAKE) go.stop + +## restart: Restart openim ✨ +.PHONY: restart +restart: clean stop build start + ## multiarch: Build binaries for multiple platforms. See option PLATFORMS. ✨ .PHONY: multiarch multiarch: diff --git a/scripts/build_all_service.sh b/scripts/build_all_service.sh index 1bff7be53..bdc800726 100755 --- a/scripts/build_all_service.sh +++ b/scripts/build_all_service.sh @@ -24,19 +24,14 @@ source $SCRIPTS_ROOT/lib/init.sh bin_dir="$BIN_DIR" logs_dir="$OPENIM_ROOT/logs" -sdk_db_dir="$OPENIM_ROOT/db/sdk/" echo "==> bin_dir=$bin_dir" echo "==> logs_dir=$logs_dir" -echo "==> sdk_db_dir=$sdk_db_dir" # Automatically created when there is no bin, logs folder if [ ! -d $logs_dir ]; then mkdir -p $logs_dir fi -if [ ! -d $sdk_db_dir ]; then - mkdir -p $sdk_db_dir -fi cd $OPENIM_ROOT diff --git a/scripts/make-rules/golang.mk b/scripts/make-rules/golang.mk index bba7cef45..339cbef6e 100644 --- a/scripts/make-rules/golang.mk +++ b/scripts/make-rules/golang.mk @@ -101,6 +101,24 @@ EXCLUDE_TESTS=github.com/OpenIMSDK/Open-IM-Server/test github.com/OpenIMSDK/Open go.build: go.build.verify $(addprefix go.build., $(addprefix $(PLATFORM)., $(BINS))) @echo "===========> Building binary $(BINS) $(VERSION) for $(PLATFORM)" +## go.start: Start openim +.PHONY: go.start +go.start: + @echo "===========> Starting openim" + @$(ROOT_DIR)/scripts/start_all.sh + +## go.stop: Stop openim +.PHONY: go.stop +go.stop: + @echo "===========> Stopping openim" + @$(ROOT_DIR)/scripts/stop_all.sh + +## go.check: Check openim +.PHONY: go.check +go.check: + @echo "===========> Checking openim" + @$(ROOT_DIR)/scripts/check_all.sh + ## go.build.verify: Verify that a suitable version of Go exists .PHONY: go.build.verify go.build.verify: @@ -143,12 +161,6 @@ go.install: @echo "===========> Installing deployment openim" @$(ROOT_DIR)/scripts/install_im_server.sh -## go.check: Check OpenIM deployment -.PHONY: go.check -go.check: - @echo "===========> Checking OpenIM deployment" - @$(ROOT_DIR)/scripts/check_all.sh - ## go.multiarch: Build multi-arch binaries .PHONY: go.build.multiarch go.build.multiarch: go.build.verify $(foreach p,$(PLATFORMS),$(addprefix go.build., $(addprefix $(p)., $(BINS)))) diff --git a/scripts/push_start.sh b/scripts/push_start.sh index 88eb8c198..e3cb45f07 100755 --- a/scripts/push_start.sh +++ b/scripts/push_start.sh @@ -43,9 +43,9 @@ prome_ports=($ports_array) #Check if the service exists #If it is exists,kill this process -check=$(ps | grep -w ./${push_name} | grep -v grep | wc -l) +check=$(ps -aux | grep -w ./${push_name} | grep -v grep | wc -l) if [ $check -ge 1 ]; then - oldPid=$(ps | grep -w ./${push_name} | grep -v grep | awk '{print $2}') + oldPid=$(ps -aux | grep -w ./${push_name} | grep -v grep | awk '{print $2}') kill -9 $oldPid fi #Waiting port recycling @@ -59,9 +59,9 @@ done sleep 3 #Check launched service process -check=$(ps | grep -w ./${push_name} | grep -v grep | wc -l) +check=$(ps -aux | grep -w ./${push_name} | grep -v grep | wc -l) if [ $check -ge 1 ]; then - newPid=$(ps | grep -w ./${push_name} | grep -v grep | awk '{print $2}') + newPid=$(ps -aux | 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/start_all.sh b/scripts/start_all.sh index 6df748e88..59f527ba4 100755 --- a/scripts/start_all.sh +++ b/scripts/start_all.sh @@ -46,10 +46,6 @@ if [ ! -d "$logs_dir" ]; then mkdir -p "$logs_dir" fi -if [ ! -d "$sdk_db_dir" ]; then - mkdir -p "$sdk_db_dir" -fi - # Print title echo -e "${BOLD_PREFIX}${BLUE_PREFIX}================> OpenIM Server Start${COLOR_SUFFIX}"