diff --git a/my-cnf-gen.sh b/my-cnf-gen.sh index aadad66..fa7a396 100755 --- a/my-cnf-gen.sh +++ b/my-cnf-gen.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -euo pipefail -MARIADB_MEMORY_PERCENT=25 +MARIADB_USAGE="${MARIADB_USAGE:-25}" MIN_BUFFER_POOL_MB=256 MAX_CONNECTIONS_MIN=80 MAX_CONNECTIONS_MAX=300 @@ -12,7 +12,7 @@ Usage: my-cnf-gen.sh [--output PATH] Generates a conservative MariaDB 10.6 my.cnf for DirectAdmin servers. -The InnoDB buffer pool is sized to about 25% RAM so other DA services +The InnoDB buffer pool is sized from MARIADB_USAGE percent of RAM so other DA services such as web, exim, dovecot, redis and spam filtering keep enough memory. EOF } @@ -87,7 +87,7 @@ calc_buffer_pool_mb() { local mem_mb="$1" local pool_mb - pool_mb=$((mem_mb * MARIADB_MEMORY_PERCENT / 100)) + pool_mb=$((mem_mb * MARIADB_USAGE / 100)) if (( pool_mb < MIN_BUFFER_POOL_MB )); then pool_mb="$MIN_BUFFER_POOL_MB" fi @@ -152,7 +152,7 @@ generate_config() { # Generated by my-cnf-gen.sh for MariaDB 10.6 and DirectAdmin stack hosts. # Detected RAM: ${mem_mb}M # Detected CPU cores: ${cores} -# MariaDB memory budget: ${MARIADB_MEMORY_PERCENT}% RAM +# MariaDB memory budget: ${MARIADB_USAGE}% RAM [client] port=3306 diff --git a/tests/quality_checks.sh b/tests/quality_checks.sh index a0cde74..a3ec1e5 100644 --- a/tests/quality_checks.sh +++ b/tests/quality_checks.sh @@ -203,7 +203,8 @@ assert_file_contains "$ROOT_DIR/my.cnf" 'query_cache_size=0' assert_file_not_contains "$ROOT_DIR/my.cnf" 'query-cache-type' assert_file_not_contains "$ROOT_DIR/my.cnf" 'query-cache-size' assert_file_not_contains "$ROOT_DIR/my.cnf" 'innodb_file_format' -assert_file_contains "$ROOT_DIR/my-cnf-gen.sh" 'MARIADB_MEMORY_PERCENT=25' +assert_file_contains "$ROOT_DIR/my-cnf-gen.sh" 'MARIADB_USAGE="\$\{MARIADB_USAGE:-25\}"' +assert_file_not_contains "$ROOT_DIR/my-cnf-gen.sh" 'MARIADB_MEMORY_PERCENT' assert_file_contains "$ROOT_DIR/my-cnf-gen.sh" 'MYSQL_GEN_MEM_MB' assert_file_contains "$ROOT_DIR/my-cnf-gen.sh" 'MYSQL_GEN_CPU_CORES' assert_file_contains "$ROOT_DIR/my-cnf-gen.sh" '/proc/meminfo' @@ -231,6 +232,8 @@ MYSQL_GEN_MEM_MB=8192 MYSQL_GEN_CPU_CORES=4 "$ROOT_DIR/my-cnf-gen.sh" --output " grep -qx 'innodb_buffer_pool_size=2G' "$generated_my_cnf" || fail "generated my.cnf should allocate 25% of 8G to InnoDB" grep -qx 'max_connections=80' "$generated_my_cnf" || fail "generated my.cnf should keep low-RAM max_connections conservative" grep -qx 'query_cache_size=0' "$generated_my_cnf" || fail "generated my.cnf should disable query cache" +MARIADB_USAGE=50 MYSQL_GEN_MEM_MB=8192 MYSQL_GEN_CPU_CORES=4 "$ROOT_DIR/my-cnf-gen.sh" --output "$generated_my_cnf" +grep -qx 'innodb_buffer_pool_size=4G' "$generated_my_cnf" || fail "MARIADB_USAGE override should change InnoDB allocation" kv_file="$tmp_dir/example.conf" printf 'ns1=old.example\nother=value\n' > "$kv_file"