fix: add kill by name in script

pull/1933/head
luhaoling 2 years ago
parent 8e4836f6f9
commit 6c22ccd545

@ -45,6 +45,11 @@ function openim::api::start() {
echo "++ OPENIM_API_PORT_LISTARIES: ${OPENIM_API_PORT_LISTARIES[@]}"
echo "++ OpenIM API config path: ${OPENIM_API_CONFIG}"
readonly OPENIM_API_SERVER_LIBRARIES=("${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME}")
openim::util::stop_services_with_name ${OPENIM_API_SERVER_LIBRARIES}
readonly OPENIM_API_SERVER_LIBRARIES
openim::util::stop_services_with_name ${OPENIM_RPC_SERVICE_LISTARIES[@]}
openim::log::info "Starting ${SERVER_NAME} ..."
printf "+------------------------+--------------+\n"
@ -52,13 +57,12 @@ function openim::api::start() {
printf "+------------------------+--------------+\n"
local length=${#OPENIM_API_SERVICE_LISTARIES[@]}
for ((i=0; i<length; i++)); do
printf "| %-22s | %6s |\n" "${OPENIM_API_SERVICE_LISTARIES[$i]}" "${OPENIM_API_PORT_LISTARIES[$i]}"
printf "+------------------------+--------------+\n"
# Stop services on the specified ports before starting new ones
openim::util::stop_services_on_ports "${OPENIM_API_PORT_LISTARIES[$i]}"
openim::util::stop_services_on_ports "${OPENIM_API_PROMETHEUS_PORT_LISTARIES[$i]}"
# openim::util::stop_services_on_ports "${OPENIM_API_PORT_LISTARIES[$i]}"
# openim::util::stop_services_on_ports "${OPENIM_API_PROMETHEUS_PORT_LISTARIES[$i]}"
openim::log::info "OpenIM ${OPENIM_API_SERVICE_LISTARIES[$i]} config path: ${OPENIM_API_CONFIG}"
# Start the service with Prometheus port if specified

@ -21,8 +21,6 @@ set -o pipefail
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
openim::util::set_max_fd 200000
SERVER_NAME="openim-msggateway"
function openim::msggateway::start() {

@ -30,10 +30,10 @@
# Usage:
# 1. Direct Script Execution:
# This initiates all the RPC services declared under the function openim::rpc::service_name.
# Example: ./openim-rpc-{rpc-name}.sh openim::rpc::start
# Example: ./openim-rpc.sh openim::rpc::start
# 2. Controlling through Functions for systemctl operations:
# Specific operations like installation, uninstallation, and status check can be executed by passing the respective function name as an argument to the script.
# Example: ./openim-rpc-{rpc-name}.sh openim::rpc::install
# Example: ./openim-rpc.sh openim::rpc::install
#
# Note: Before executing this script, ensure that the necessary permissions are granted and relevant environmental variables are set.
#
@ -64,6 +64,12 @@ IFS=" " read -ra OPENIM_RPC_SERVICE_TARGETS <<< "$(openim::rpc::service_name)"
readonly OPENIM_RPC_SERVICE_TARGETS
readonly OPENIM_RPC_SERVICE_LISTARIES=("${OPENIM_RPC_SERVICE_TARGETS[@]##*/}")
OPENIM_RPC_SERVICE_LIBRARIES=()
for target in "${OPENIM_RPC_SERVICE_TARGETS[@]}"; do
OPENIM_RPC_SERVICE_LIBRARIES+=("${OPENIM_OUTPUT_HOSTBIN}/${target}")
done
readonly OPENIM_RPC_SERVICE_LIBRARIES
# Make sure the environment is only called via common to avoid too much nesting
openim::rpc::service_port() {
local targets=(
@ -121,11 +127,10 @@ function openim::rpc::start() {
printf "+------------------------+-------+-----------------+\n"
done
openim::util::stop_services_with_name ${OPENIM_RPC_SERVICE_LIBRARIES[@]}
# start all rpc services
for ((i = 0; i < ${#OPENIM_RPC_SERVICE_LISTARIES[*]}; i++)); do
# openim::util::stop_services_with_name ${OPENIM_RPC_SERVICE_LISTARIES
openim::util::stop_services_on_ports ${OPENIM_RPC_PORT_LISTARIES[$i]}
openim::util::stop_services_on_ports ${OPENIM_RPC_PROM_PORT_LISTARIES[$i]}
openim::log::info "OpenIM ${OPENIM_RPC_SERVICE_LISTARIES[$i]} config path: ${OPENIM_RPC_CONFIG}"

@ -664,7 +664,7 @@ openim::util::stop_services_with_name() {
if [[ -n $pid ]]; then
# Try to stop the service by killing its process.
if kill -15 $pid 2>/dev/null; then
stopped_this_time=true
stopped_this_time=true jk
fi
fi
done

Loading…
Cancel
Save