Skip to content

Commit

Permalink
fix: reconstruct the script of 'make start' 'make stop' and 'make che…
Browse files Browse the repository at this point in the history
…ck' (openimsdk#1953)

* fix: del the error world

* fix: refactoring scripts

* fix: del nounset

* rm set error

* rm set error

* replace openim::log::info

* replace openim::log::info

* replace openim::log::info

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* fix: fix the error output format

* log

* fix: fix the error

* log

* log

* fix: fi the code error

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* fix: use printf replace the echo

---------

Co-authored-by: skiffer-git <[email protected]>
  • Loading branch information
luhaoling and skiffer-git authored Feb 27, 2024
1 parent 8e6c1d7 commit ac87758
Show file tree
Hide file tree
Showing 43 changed files with 513 additions and 281 deletions.
2 changes: 1 addition & 1 deletion cmd/openim-api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func run(port int, proPort int) error {
defer cancel()
select {
case <-sigs:
util.SIGUSR1Exit()
util.SIGTERMExit()
err := server.Shutdown(ctx)
if err != nil {
return errs.Wrap(err, "shutdown err")
Expand Down
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#

set -e
set -o pipefail


############################## OpenIM Github ##############################
# ... rest of the script ...
Expand Down
4 changes: 1 addition & 3 deletions internal/msggateway/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ func RunWsAndServer(rpcPort, wsPort, prometheusPort int) error {
netDone := make(chan error)
go func() {
err = hubServer.Start()
if err != nil {
netDone <- err
}
netDone <- err
}()
return hubServer.LongConnServer.Run(netDone)
}
6 changes: 2 additions & 4 deletions internal/msgtransfer/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,17 @@ func (m *MsgTransfer) Start(prometheusPort int) error {
signal.Notify(sigs, syscall.SIGTERM)
select {
case <-sigs:
util.SIGUSR1Exit()
util.SIGTERMExit()
// graceful close kafka client.
m.cancel()
m.historyCH.historyConsumerGroup.Close()
m.historyMongoCH.historyConsumerGroup.Close()

return nil
case <-netDone:
m.cancel()
m.historyCH.historyConsumerGroup.Close()
m.historyMongoCH.historyConsumerGroup.Close()
close(netDone)
return netErr
}

return nil
}
4 changes: 2 additions & 2 deletions pkg/common/startrpc/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func Start(
signal.Notify(sigs, syscall.SIGTERM)
select {
case <-sigs:
util.SIGUSR1Exit()
util.SIGTERMExit()
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
if err := gracefulStopWithCtx(ctx, srv.GracefulStop); err != nil {
Expand All @@ -152,7 +152,7 @@ func Start(
if err != nil {
return errs.Wrap(err, "shutdown err")
}
return errors.New("SIGTERM EXIT")
return nil
case <-netDone:
close(netDone)
return netErr
Expand Down
10 changes: 3 additions & 7 deletions pkg/util/genutil/genutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package genutil

import (
"errors"
"fmt"
"os"
"path/filepath"
Expand All @@ -42,15 +41,12 @@ func OutDir(path string) (string, error) {
}

func ExitWithError(err error) {
if errors.Is(err, errors.New("SIGTERM EXIT")) {
os.Exit(-1)
}
progName := filepath.Base(os.Args[0])
fmt.Fprintf(os.Stderr, "\n\n%s exit -1: \n%+v\n\n", progName, err)
fmt.Fprintf(os.Stderr, "%s exit -1: %+v\n", progName, err)
os.Exit(-1)
}

func SIGUSR1Exit() {
func SIGTERMExit() {
progName := filepath.Base(os.Args[0])
fmt.Printf("\n\n%s receive process terminal SIGTERM exit 0\n\n", progName)
fmt.Fprintf(os.Stderr, "Warning %s receive process terminal SIGTERM exit 0\n", progName)
}
2 changes: 1 addition & 1 deletion scripts/advertise.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.

set -e
set -o pipefail


. $(dirname ${BASH_SOURCE})/lib/init.sh

Expand Down
6 changes: 3 additions & 3 deletions scripts/build-all-service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
# Usage: `scripts/build-all-service.sh`.
# Example: `scripts/build-go.sh WHAT=cmd/kubelet`.

set -o errexit
set -o nounset
set -o pipefail




OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/lib/init.sh"
Expand Down
43 changes: 21 additions & 22 deletions scripts/check-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
# Encapsulated as: `make check`.
# READ: https://github.com/openimsdk/open-im-server/tree/main/scripts/install/environment.sh

set -o errexit
set -o nounset
set -o pipefail




OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/install/common.sh"
Expand Down Expand Up @@ -49,13 +49,6 @@ print_services_and_ports() {
echo "+-------------------------+----------+"
}

handle_error() {
echo "An error occurred. Printing ${STDERR_LOG_FILE} contents:"
cat "${STDERR_LOG_FILE}"
exit 1
}

trap handle_error ERR

# Assuming OPENIM_SERVER_NAME_TARGETS and OPENIM_SERVER_PORT_TARGETS are defined
# Similarly for OPENIM_DEPENDENCY_TARGETS and OPENIM_DEPENDENCY_PORT_TARGETS
Expand All @@ -71,7 +64,6 @@ echo "++ The port being checked: ${OPENIM_SERVER_PORT_LISTARIES[@]}"
openim::log::info "\n## Check all dependent service ports"
echo "++ The port being checked: ${OPENIM_DEPENDENCY_PORT_LISTARIES[@]}"

set +e

# Later, after discarding Docker, the Docker keyword is unreliable, and Kubepods is used
if grep -qE 'docker|kubepods' /proc/1/cgroup || [ -f /.dockerenv ]; then
Expand All @@ -85,22 +77,29 @@ if [[ $? -ne 0 ]]; then
openim::log::error_exit "The service does not start properly, please check the port, query variable definition!"
echo "+++ https://github.com/openimsdk/open-im-server/tree/main/scripts/install/environment.sh +++"
else
echo "++++ Check all dependent service ports successfully !"
openim::log::success "All components depended on by openim are running normally! "
fi

openim::log::info "\n## Check OpenIM service name"
. $(dirname ${BASH_SOURCE})/install/openim-msgtransfer.sh openim::msgtransfer::check

openim::log::info "\n## Check all OpenIM service ports"
echo "+++ The port being checked: ${OPENIM_SERVER_PORT_LISTARIES[@]}"
openim::util::check_ports ${OPENIM_SERVER_PORT_LISTARIES[@]}
openim::log::info "\n## Check openim service name:\n${OPENIM_OUTPUT_HOSTBIN}/openim-msgtransfer"
result=$(. $(dirname ${BASH_SOURCE})/install/openim-msgtransfer.sh openim::msgtransfer::check)
if [[ $? -ne 0 ]]; then
echo "+++ cat openim log file >>> ${LOG_FILE}"
openim::log::error_exit "The service does not start properly, please check the port, query variable definition!"
else
echo "++++ Check all openim service ports successfully !"
openim::log::error "check process failed.\n $result"
fi

set -e

trap - ERR
echo "Check openim service name:"
for item in "${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]}"; do
echo "$item"
done

result=$(openim::util::check_process_names ${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]})
if [[ $? -ne 0 ]]; then
echo "+++ cat openim log file >>> ${LOG_FILE}"
openim::log::error "check process failed.\n "
echo "$result"
else
openim::log::success "All openim services are running normally! "
fi

6 changes: 3 additions & 3 deletions scripts/cherry-pick.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
# checks them out to a branch named:
# automated-cherry-pick-of-<pr>-<target branch>-<timestamp>

set -o errexit
set -o nounset
set -o pipefail




OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/lib/init.sh"
Expand Down
6 changes: 3 additions & 3 deletions scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
# shellcheck disable=SC2034 # Variables sourced in other scripts.

# Common utilities, variables and checks for all build scripts.
set -o errexit
set +o nounset
set -o pipefail




# Unset CDPATH, having it set messes up with script import paths
unset CDPATH
Expand Down
6 changes: 3 additions & 3 deletions scripts/docker-start-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail




#fixme This scripts is the total startup scripts
#fixme The full name of the shell scripts that needs to be started is placed in the need_to_start_server_shell array
Expand Down
6 changes: 3 additions & 3 deletions scripts/gen-swagger-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

# Script to generate docs from the latest swagger spec.

set -o errexit
set -o nounset
set -o pipefail




# The root of the build/dist directory
OPENIM_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
Expand Down
6 changes: 3 additions & 3 deletions scripts/init-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

# This script automatically initializes various configuration files and can generate example files.

set -o errexit
set -o nounset
set -o pipefail




# Root directory of the OpenIM project
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
Expand Down
4 changes: 2 additions & 2 deletions scripts/init-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#FIXME This script is the startup script for multiple servers.
#FIXME The full names of the shell scripts that need to be started are placed in the `need_to_start_server_shell` array.

set -o nounset
set -o pipefail



OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd -P)
source "${OPENIM_ROOT}/scripts/install/common.sh"
Expand Down
6 changes: 3 additions & 3 deletions scripts/install-im-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
# Usage:
# SERVER_IMAGE_VERSION=latest IMAGE_REGISTRY=myregistry ./this_script.sh

set -o errexit
set -o nounset
set -o pipefail




OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/lib/init.sh"
Expand Down
22 changes: 19 additions & 3 deletions scripts/install/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@


# Common utilities, variables and checks for all build scripts.
set -o errexit
set +o nounset
set -o pipefail




# Sourced flag
COMMON_SOURCED=true
Expand Down Expand Up @@ -99,6 +99,22 @@ IFS=" " read -ra OPENIM_SERVER_PORT_TARGETS <<< "$(openim::common::service_port)
readonly OPENIM_SERVER_PORT_TARGETS
readonly OPENIM_SERVER_PORT_LISTARIES=("${OPENIM_SERVER_PORT_TARGETS[@]##*/}")


OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER=()

for target in "${OPENIM_SERVER_BINARIES_NO_TRANSFER[@]}"; do
OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER+=("${OPENIM_OUTPUT_HOSTBIN}/${target}")
done
readonly OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER



OPENIM_ALL_SERVICE_LIBRARIES=()
for target in "${OPENIM_SERVER_BINARIES_NO_CMDUTILS[@]}"; do
OPENIM_ALL_SERVICE_LIBRARIES+=("${OPENIM_OUTPUT_HOSTBIN}/${target}")
done
readonly OPENIM_ALL_SERVICE_LIBRARIES

openim::common::dependency_name() {
local targets=(
redis
Expand Down
6 changes: 3 additions & 3 deletions scripts/install/dependency.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

# This script will install the dependencies required for openim

set -o errexit
set +o nounset
set -o pipefail




OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
Expand Down
2 changes: 1 addition & 1 deletion scripts/install/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function openim::uninstall::uninstall_openim() {
openim::common::sudo "systemctl stop openim.target"
openim::common::sudo "systemctl disable openim.target"
openim::common::sudo "rm -f /etc/systemd/system/openim.target"
set -o errexit

openim::log::success "openim uninstall success"
}

Expand Down
Loading

0 comments on commit ac87758

Please sign in to comment.