|
4 | 4 | # Works with RHEL / AlmaLinux / RockyLinux / CentOS EL8 and EL9
|
5 | 5 | # Works with Debian 12
|
6 | 6 |
|
7 |
| -SCRIPT_BUILD="2025021401" |
| 7 | +SCRIPT_BUILD="2025030801" |
8 | 8 |
|
9 | 9 | BRAND_NAME=NetPerfect # Name which will be displayed in /etc/issue
|
10 | 10 | VIRT_BRAND_NAME=NetPerfect # Brand which will be used to detect virtual machines
|
@@ -163,6 +163,41 @@ check_internet() {
|
163 | 163 | return 1
|
164 | 164 | }
|
165 | 165 |
|
| 166 | +set_conf_value() { |
| 167 | + # Updates a line in a configuration file |
| 168 | + # name=value if separator = '=' |
| 169 | + # name value if separator = ' ' |
| 170 | + # name = value if separator = ' = ' |
| 171 | + file="${1}" |
| 172 | + name="${2}" |
| 173 | + value="${3}" |
| 174 | + separator="${4:-=}" |
| 175 | + # sed separator needs to be updated if '#' is used in name, separator or value |
| 176 | + sed_separator="${5:-#}" |
| 177 | + |
| 178 | + if [ -f "$file" ]; then |
| 179 | + if grep "^${name}=" "${file}" > /dev/null 2>&1; then |
| 180 | + # Using -i.tmp for BSD compat |
| 181 | + sed -i.tmp "s${separator}^${name}${xzz}.*${separator}${name}${xzz}${value}${separator}" "${file}" |
| 182 | + if [ $? -ne 0 ]; then |
| 183 | + log "Cannot update value [${name}] to [${value}] in file [${file}]." "ERROR" |
| 184 | + fi |
| 185 | + rm -f "$file.tmp" |
| 186 | + log "Set [${name}] to [${value}] in file [${file}]." "INFO" |
| 187 | + else |
| 188 | + echo "${name}${separator}${value}" >> "${file}" |
| 189 | + if [ $? -ne 0 ]; then |
| 190 | + log "Cannot create value [${name}] to [${value}] in file [${file}]." "ERROR" |
| 191 | + fi |
| 192 | + fi |
| 193 | + else |
| 194 | + echo "${name}${separator}${value}" > "${file}" |
| 195 | + if [ $? -ne 0 ]; then |
| 196 | + Logger "File [${file}] does not exist. Failed to create it with value [$name]" "ERROR" |
| 197 | + fi |
| 198 | + fi |
| 199 | +} |
| 200 | + |
166 | 201 | ## Script entry point
|
167 | 202 | POST_INSTALL_SCRIPT_GOOD=true
|
168 | 203 |
|
|
493 | 528 | chmod +x /usr/local/bin/smartmon.sh 2>> "${LOG_FILE}" || log "Failed to chmod /usr/local/bin/smartmon.sh" "ERROR"
|
494 | 529 | log "Setting up smart script for prometheus task"
|
495 | 530 | [ ! -d /var/lib/node_exporter/textfile_collector ] && mkdir -p /var/lib/node_exporter/textfile_collector
|
496 |
| - echo "*/5 * * * * root /bin/bash /usr/local/bin/smartmon.sh > /var/lib/node_exporter/textfile_collector/smart_metrics.prom" >> /etc/crontab |
| 531 | + echo "*/5 * * * * root /bin/bash /usr/local/bin/smartmon.sh > /var/lib/node_exporter/textfile_collector/smart_metrics.prom" > /etc/cond.d/smartmon_metrics 2>> "${LOG_FILE}" || log "Failed to add smartmon cron job" "ERROR" |
497 | 532 |
|
498 | 533 | # TODO Test this for Debian
|
499 | 534 | log "Setting up iTCO_wdt watchdog"
|
@@ -875,13 +910,13 @@ log "Setting up systemd watchdog"
|
875 | 910 | sed -i -e 's,^#RuntimeWatchdogSec=.*,RuntimeWatchdogSec=60s,' /etc/systemd/system.conf 2>> "${LOG_FILE}" || log "Failed to sed /etc/systemd/system.conf" "ERROR"
|
876 | 911 |
|
877 | 912 | log "Setup cake qdisc algorith and bbr congestion control"
|
878 |
| -echo net.core.default_qdisc=cake >> /etc/sysctl.d/99-sched.conf || log "Failed to write to /etc/sysctl.d/99-sched.conf" "ERROR" |
879 |
| -echo net.ipv4.tcp_congestion_control=bbr >> /etc/sysctl.d/99-sched.conf || log "Failed to write to /etc/sysctl.d/99-sched.conf" "ERROR" |
| 913 | +set_conf_value /etc/sysctl.d/99-sched.conf "net.core.default_qdisc" "cake" |
| 914 | +set_conf_value /etc/sysctl.d/99-sched.conf "net.ipv4.tcp_congestion_control" "bbr" |
880 | 915 |
|
881 | 916 | # Add ClientAlive to SSHD
|
882 |
| -echo "TCPKeepAlive no" >> /etc/ssh/sshd_config || log "Failed to tune sshd service" "ERROR" |
883 |
| -echo "ClientAliveInterval 120" >> /etc/ssh/sshd_config || log "Failed to tune sshd service" "ERROR" |
884 |
| -echo "ClientAliveCountMax 3" >> /etc/ssh/sshd_config || log "Failed to tune sshd service" "ERROR" |
| 917 | +set_conf_value /etc/ssh/sshd_config "TCPKeepAlive" "no" " " |
| 918 | +set_conf_value /etc/ssh/sshd_config "ClientAliveInterval" "120" " " |
| 919 | +set_conf_value /etc/ssh/sshd_config "ClientAliveCountMax" "3" " " |
885 | 920 |
|
886 | 921 | if [ "${ALLOW_SUDO}" == true ]; then
|
887 | 922 | # Patch sudoers file since noexec is set by default, which prevents sudo
|
|
0 commit comments