Skip to content

Commit

Permalink
fix: Implement Enhanced File Descriptor Limit Handling in Shell Script (
Browse files Browse the repository at this point in the history
#1160)

Signed-off-by: Xinwei Xiong(cubxxw) <[email protected]>
  • Loading branch information
cubxxw authored Oct 8, 2023
1 parent daf5871 commit 8dd6a05
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
4 changes: 2 additions & 2 deletions scripts/install/openim-msggateway.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ set -o errexit
set +o nounset
set -o pipefail

ulimit -n 200000

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()
Expand Down
4 changes: 2 additions & 2 deletions scripts/install/openim-msgtransfer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ set -o errexit
set +o nounset
set -o pipefail

ulimit -n 200000

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-msgtransfer"

function openim::msgtransfer::start()
Expand Down
32 changes: 32 additions & 0 deletions scripts/lib/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,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:]')
Expand Down

0 comments on commit 8dd6a05

Please sign in to comment.