From 9d9e4d331f2d9485ddb0cce672878e59da80151c Mon Sep 17 00:00:00 2001 From: "Xinwei Xiong (cubxxw)" <3293172751nss@gmail.com> Date: Mon, 5 Feb 2024 20:54:37 +0800 Subject: [PATCH] feat: add openim deployment tactics Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com> --- cmd/openim-api/main.go | 1 + scripts/lib/util.sh | 43 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/cmd/openim-api/main.go b/cmd/openim-api/main.go index a45bcbdd8..bbb5eb968 100644 --- a/cmd/openim-api/main.go +++ b/cmd/openim-api/main.go @@ -43,6 +43,7 @@ import ( func main() { apiCmd := cmd.NewApiCmd() apiCmd.AddPortFlag() + apiCmd.AddPrometheusPortFlag() apiCmd.AddApi(run) if err := apiCmd.Execute(); err != nil { fmt.Fprintf(os.Stderr, "\n\nexit -1: \n%+v\n\n", err) diff --git a/scripts/lib/util.sh b/scripts/lib/util.sh index 18be305cd..7acb1fcdd 100755 --- a/scripts/lib/util.sh +++ b/scripts/lib/util.sh @@ -486,7 +486,7 @@ openim::util::stop_services_on_ports() { local pid=$(echo $line | awk '{print $2}') # Try to stop the service by killing its process. - if kill -9 $pid; then + if kill -10 $pid; then stopped+=($port) else not_stopped+=($port) @@ -561,7 +561,7 @@ openim::util::stop_services_with_name() { # If there's a Process ID, it means the service with the name is running. if [[ -n $pid ]]; then # Try to stop the service by killing its process. - if kill -9 $pid 2>/dev/null; then + if kill -10 $pid 2>/dev/null; then stopped_this_time=true fi fi @@ -1720,7 +1720,7 @@ openim::util::stop_services_on_ports() { local pid=$(echo $line | awk '{print $2}') # Try to stop the service by killing its process. - if kill -9 $pid; then + if kill -10 $pid; then stopped+=($port) else not_stopped+=($port) @@ -1795,7 +1795,7 @@ openim::util::stop_services_with_name() { # If there's a Process ID, it means the service with the name is running. if [[ -n $pid ]]; then # Try to stop the service by killing its process. - if kill -9 $pid 2>/dev/null; then + if kill -10 $pid 2>/dev/null; then stopped_this_time=true fi fi @@ -2570,7 +2570,6 @@ function openim::util::gencpu() { echo $cpu_count } - function openim::util::set_max_fd() { local desired_fd=$1 local max_fd_limit @@ -2751,6 +2750,38 @@ function openim::util::gencpu() { echo $cpu_count } +function openim::util::set_max_fd() { + local desired_fd=$1 + local max_fd_limit + + # Check if we're not on cygwin or darwin. + if [ "$(uname -s | tr '[:upper:]' '[:lower:]')" != "cygwin" ] && [ "$(uname -s | tr '[:upper:]' '[:lower:]')" != "darwin" ]; then + # Try to get the hard limit. + max_fd_limit=$(ulimit -H -n) + if [ $? -eq 0 ]; then + # If desired_fd is 'maximum' or 'max', set it to the hard limit. + if [ "$desired_fd" = "maximum" ] || [ "$desired_fd" = "max" ]; then + desired_fd="$max_fd_limit" + fi + + # Check if desired_fd is less than or equal to max_fd_limit. + if [ "$desired_fd" -le "$max_fd_limit" ]; then + ulimit -n "$desired_fd" + if [ $? -ne 0 ]; then + echo "Warning: Could not set maximum file descriptor limit to $desired_fd" + fi + else + echo "Warning: Desired file descriptor limit ($desired_fd) is greater than the hard limit ($max_fd_limit)" + fi + else + echo "Warning: Could not query the maximum file descriptor hard limit." + fi + else + echo "Warning: Not attempting to modify file descriptor limit on Cygwin or Darwin." + fi +} + + function openim::util::gen_os_arch() { # Get the current operating system and architecture OS=$(uname -s | tr '[:upper:]' '[:lower:]') @@ -2793,4 +2824,4 @@ function openim::util::gen_os_arch() { if [[ "$*" =~ openim::util:: ]];then eval $* -fi +fi \ No newline at end of file