Skip to content

Commit 90e46b0

Browse files
authored
refactor: BBR configuration to use sysctl.d file (#591)
Signed-off-by: Pavel Pikta <pavel_pikta@epam.com>
1 parent c184ea5 commit 90e46b0

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

installTorrServerLinux.sh

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ readonly VERSION_PREFIX="MatriX"
4545
readonly BINARY_NAME_PREFIX="TorrServer-linux"
4646
readonly MIN_GLIBC_VERSION="2.32"
4747
readonly MIN_VERSION_REQUIRING_GLIBC=136
48+
readonly SYSCTL_BBR_FILE="/etc/sysctl.d/90-torrserver.conf"
4849

4950
# Color support
5051
declare -A colors=([black]=0 [red]=1 [green]=2 [yellow]=3 [blue]=4 [magenta]=5 [cyan]=6 [white]=7)
@@ -1037,23 +1038,20 @@ ensureBBRModuleAtBoot() {
10371038
return 0
10381039
}
10391040

1040-
# Check if BBR is configured in sysctl.conf
1041+
# Check if BBR is configured in sysctl.d file
10411042
isBBRConfiguredInFile() {
1042-
local sysctl_file="${1:-/etc/sysctl.conf}"
1043-
[[ -f "$sysctl_file" ]] && \
1044-
grep -q "^net.core.default_qdisc=fq" "$sysctl_file" 2>/dev/null && \
1045-
grep -q "^net.ipv4.tcp_congestion_control=bbr" "$sysctl_file" 2>/dev/null
1043+
[[ -f "$SYSCTL_BBR_FILE" ]] && \
1044+
grep -q "^net.core.default_qdisc=fq" "$SYSCTL_BBR_FILE" 2>/dev/null && \
1045+
grep -q "^net.ipv4.tcp_congestion_control=bbr" "$SYSCTL_BBR_FILE" 2>/dev/null
10461046
}
10471047

1048-
# Add BBR settings to sysctl.conf
1048+
# Add BBR settings to sysctl.d file
10491049
addBBRToSysctl() {
1050-
local sysctl_file="${1:-/etc/sysctl.conf}"
1051-
1052-
if ! grep -q "^net.core.default_qdisc=fq" "$sysctl_file" 2>/dev/null; then
1053-
echo "net.core.default_qdisc=fq" >> "$sysctl_file" 2>/dev/null || return 1
1050+
if ! grep -q "^net.core.default_qdisc=fq" "$SYSCTL_BBR_FILE" 2>/dev/null; then
1051+
echo "net.core.default_qdisc=fq" >> "$SYSCTL_BBR_FILE" 2>/dev/null || return 1
10541052
fi
1055-
if ! grep -q "^net.ipv4.tcp_congestion_control=bbr" "$sysctl_file" 2>/dev/null; then
1056-
echo "net.ipv4.tcp_congestion_control=bbr" >> "$sysctl_file" 2>/dev/null || return 1
1053+
if ! grep -q "^net.ipv4.tcp_congestion_control=bbr" "$SYSCTL_BBR_FILE" 2>/dev/null; then
1054+
echo "net.ipv4.tcp_congestion_control=bbr" >> "$SYSCTL_BBR_FILE" 2>/dev/null || return 1
10571055
fi
10581056
return 0
10591057
}
@@ -1077,9 +1075,7 @@ applyBBRSettings() {
10771075

10781076
# Ensure BBR is active (non-critical - always returns success)
10791077
ensureBBRActive() {
1080-
local sysctl_file="/etc/sysctl.conf"
1081-
1082-
! isBBRConfiguredInFile "$sysctl_file" && return 0
1078+
! isBBRConfiguredInFile && return 0
10831079
isBBRActive && return 0
10841080

10851081
if ! isBBRAvailable && ! loadBBRModule; then
@@ -1098,7 +1094,7 @@ ensureBBRActive() {
10981094
[[ $SILENT_MODE -eq 0 ]] && {
10991095
echo " - $(colorize yellow "$(msg bbr_activate_failed_cc "$current_cc")")"
11001096
echo " $(colorize yellow "$(msg bbr_no_optimization)")"
1101-
echo " $(colorize yellow "$(msg bbr_settings_will_apply "$sysctl_file")")"
1097+
echo " $(colorize yellow "$(msg bbr_settings_will_apply "$SYSCTL_BBR_FILE")")"
11021098
}
11031099
fi
11041100
return 0
@@ -1107,38 +1103,36 @@ ensureBBRActive() {
11071103
configureBBR() {
11081104
[[ $isBbr -ne 1 ]] && return 0
11091105

1110-
local sysctl_file="/etc/sysctl.conf"
1111-
11121106
# Check if BBR is available or can be loaded first
11131107
if ! isBBRAvailable && ! loadBBRModule; then
11141108
# BBR not available - check if it's already in config
1115-
if isBBRConfiguredInFile "$sysctl_file"; then
1109+
if isBBRConfiguredInFile; then
11161110
[[ $SILENT_MODE -eq 0 ]] && {
11171111
echo " - $(colorize yellow "$(msg bbr_configured_not_available)")"
11181112
echo " $(colorize yellow "$(msg bbr_requires_kernel)")"
1119-
echo " $(colorize yellow "$(msg bbr_settings_will_apply "$sysctl_file")")"
1113+
echo " $(colorize yellow "$(msg bbr_settings_will_apply "$SYSCTL_BBR_FILE")")"
11201114
echo " $(colorize yellow "$(msg bbr_no_optimization)")"
11211115
}
11221116
else
11231117
# Not in config and not available - don't add it
11241118
[[ $SILENT_MODE -eq 0 ]] && {
11251119
echo " - $(colorize yellow "$(msg bbr_not_available)")"
11261120
echo " $(colorize yellow "$(msg bbr_requires_kernel)")"
1127-
echo " $(colorize yellow "$(msg bbr_settings_not_added "$sysctl_file")")"
1121+
echo " $(colorize yellow "$(msg bbr_settings_not_added "$SYSCTL_BBR_FILE")")"
11281122
echo " $(colorize yellow "$(msg bbr_no_optimization)")"
11291123
}
11301124
fi
11311125
return 0
11321126
fi
11331127

11341128
# BBR is available - now configure it
1135-
if isBBRConfiguredInFile "$sysctl_file"; then
1129+
if isBBRConfiguredInFile; then
11361130
[[ $SILENT_MODE -eq 0 ]] && echo " - $(msg bbr_already_configured)"
11371131
else
1138-
! addBBRToSysctl "$sysctl_file" && {
1132+
! addBBRToSysctl && {
11391133
[[ $SILENT_MODE -eq 0 ]] && {
11401134
echo " - $(colorize yellow "$(msg bbr_config_failed)")"
1141-
echo " $(colorize yellow "$(msg bbr_write_failed "$sysctl_file")")"
1135+
echo " $(colorize yellow "$(msg bbr_write_failed "$SYSCTL_BBR_FILE")")"
11421136
echo " $(colorize yellow "$(msg bbr_no_optimization)")"
11431137
}
11441138
return 0
@@ -1158,7 +1152,7 @@ configureBBR() {
11581152
[[ $SILENT_MODE -eq 0 ]] && {
11591153
echo " - $(colorize yellow "$(msg bbr_config_failed)")"
11601154
echo " $(colorize yellow "$(msg bbr_current_values "$current_qdisc" "$current_cc")")"
1161-
echo " $(colorize yellow "$(msg bbr_settings_will_apply "$sysctl_file")")"
1155+
echo " $(colorize yellow "$(msg bbr_settings_will_apply "$SYSCTL_BBR_FILE")")"
11621156
echo " $(colorize yellow "$(msg bbr_no_optimization)")"
11631157
}
11641158
return 0

0 commit comments

Comments
 (0)