#! /bin/bash . /usr/src/k_framework/main.sh # ---- VARS ----- VERSION="1.0.3" SCRIPT_NAME="MySQL Check" MYSQLD_SYSTEMD_CUSTOM="/etc/systemd/system/mysqld.service.d/custom.conf" MYSQL_CFG="/etc/my.cnf" k_start k_config_details k_service_check mysqld k_service_check_enabled mysqld if ! grep -B 999 -F '[mysqld_safe]' $MYSQL_CFG | grep -Fq 'log-error='; then report "log-error not set in $MYSQL_CFG [mysqld] section" 2 report " Fix bellow will restart MySQL and might affect calls" fix report " cp /etc/my.cnf /usr/local/${SYSTEM_CONFIG_DIR}/backups/my.cnf_$(date +\"%Y%m%d_%H%M%S\") && sed -i '/\[mysqld\]/a log-error=/var/log/mysqld.log' $MYSQL_CFG && systemctl restart mysqld" fix EXIT_CODE=1 else report "$MYSQL_CFG log-error OK" 0 fi if [[ -e /usr/bin/mysql ]] && /usr/bin/mysql --version | grep -Fq 'Ver 8'; then # PrivateTmp override check # https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html/using_systemd_unit_files_to_customize_and_optimize_your_system/assembly_working-with-systemd-unit-files_working-with-systemd#proc_modifying-existing-unit-files_assembly_working-with-systemd-unit-files if [[ -d /etc/systemd/system/mysqld.service.d/ ]] && [[ -e $MYSQLD_SYSTEMD_CUSTOM ]] && grep -Fq '[Service]' $MYSQLD_SYSTEMD_CUSTOM && grep -Fq "PrivateTmp=false" $MYSQLD_SYSTEMD_CUSTOM; then report "[mysqld] \"PrivateTmp=false\" in $MYSQLD_SYSTEMD_CUSTOM" 0 else report " [mysqld] no \"PrivateTmp=false\" in $MYSQLD_SYSTEMD_CUSTOM" 1 report " mkdir -p /etc/systemd/system/mysqld.service.d/" fix report " echo -e \"[Service]\\\nPrivateTmp=false\" > /etc/systemd/system/mysqld.service.d/custom.conf" fix report " systemctl daemon-reload" fix report " service mysqld restart" fix EXIT_CODE=1 fi if ! grep -Eq "information_schema_stats_expiry[[:space:]]*=[[:space:]]*0" /etc/my.cnf; then report "information_schema_stats_expiry not set in $MYSQL_CFG [mysqld] section" 2 report " Fix bellow will restart MySQL and might affect calls" fix report " cp /etc/my.cnf /usr/local/${SYSTEM_CONFIG_DIR}/backups/my.cnf_$(date +\"%Y%m%d_%H%M%S\") && sed -i '/\[mysqld\]/a information_schema_stats_expiry = 0' $MYSQL_CFG && systemctl restart mysqld" fix EXIT_CODE=1 fi fi k_exit $EXIT_CODE