Skip to content

Commit b795a5b

Browse files
committed
Don't add same conf files twice on re-runs
1 parent 0577f50 commit b795a5b

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

el_configurator.sh

+42-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Works with RHEL / AlmaLinux / RockyLinux / CentOS EL8 and EL9
55
# Works with Debian 12
66

7-
SCRIPT_BUILD="2025021401"
7+
SCRIPT_BUILD="2025030801"
88

99
BRAND_NAME=NetPerfect # Name which will be displayed in /etc/issue
1010
VIRT_BRAND_NAME=NetPerfect # Brand which will be used to detect virtual machines
@@ -163,6 +163,41 @@ check_internet() {
163163
return 1
164164
}
165165

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+
166201
## Script entry point
167202
POST_INSTALL_SCRIPT_GOOD=true
168203

@@ -493,7 +528,7 @@ EOF
493528
chmod +x /usr/local/bin/smartmon.sh 2>> "${LOG_FILE}" || log "Failed to chmod /usr/local/bin/smartmon.sh" "ERROR"
494529
log "Setting up smart script for prometheus task"
495530
[ ! -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"
497532

498533
# TODO Test this for Debian
499534
log "Setting up iTCO_wdt watchdog"
@@ -875,13 +910,13 @@ log "Setting up systemd watchdog"
875910
sed -i -e 's,^#RuntimeWatchdogSec=.*,RuntimeWatchdogSec=60s,' /etc/systemd/system.conf 2>> "${LOG_FILE}" || log "Failed to sed /etc/systemd/system.conf" "ERROR"
876911

877912
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"
880915

881916
# 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" " "
885920

886921
if [ "${ALLOW_SUDO}" == true ]; then
887922
# Patch sudoers file since noexec is set by default, which prevents sudo

0 commit comments

Comments
 (0)