fix: Implement Enhanced File Descriptor Limit Handling in Shell Script (#1160)

Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com>
pull/1161/head
Xinwei Xiong 1 year ago committed by GitHub
parent daf58715ed
commit 8dd6a05d38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

@ -18,11 +18,11 @@ set -o errexit
set +o nounset set +o nounset
set -o pipefail set -o pipefail
ulimit -n 200000
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P) OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh [[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
openim::util::set_max_fd 200000
SERVER_NAME="openim-msgtransfer" SERVER_NAME="openim-msgtransfer"
function openim::msgtransfer::start() function openim::msgtransfer::start()

@ -1250,6 +1250,38 @@ function openim::util::gencpu() {
echo $cpu_count 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() { function openim::util::gen_os_arch() {
# Get the current operating system and architecture # Get the current operating system and architecture
OS=$(uname -s | tr '[:upper:]' '[:lower:]') OS=$(uname -s | tr '[:upper:]' '[:lower:]')

Loading…
Cancel
Save