-
Notifications
You must be signed in to change notification settings - Fork 6
/
run-mulitconfig
executable file
·133 lines (114 loc) · 3.92 KB
/
run-mulitconfig
1
#!/bin/bashset -uusage(){cat << EOFusage: $0 optionsWARNING: Do not run this script on a working MySQL server. It will stop & start the service and putput lots of load on the server.WARNING: The -c (clean) option deletes binary logs and InnoDB logs and may result in data loss.This script runs through a directory containing one or more mysqld config files. For each file it goes through the following steps:- stops the server, - deletes the ib_logs and binlogs - restarts the server with the config file passed to --defaults-file- runs ./run-sysbench Once complete it shuts down MySQL and aggregates the sysbench results in a CSV file.OPTIONS: -i MySQL pid file (required) -d Config directory [./conf] -s MySQL socket [/tmp/mysql.sock] -u MySQL username [root] -p MySQL password -w ReadWrite mode (on/off) [on] -o Timeout for each sysbench run [60] -r Directory to print results to [./results] -t List of thread counts to iterate [4 8 16 32 64 128 256] -c Delete binlogs and ib_logfiles when complete (on/off) [off]EOF}pid=dir=./confsocket=/tmp/mysql.sockuser=rootpassword=readwrite=ontimeout=60resultsdir=./resultsthreads="8,16,32,64,128"clean=offparams=while getopts i:d:h:s:u:p:w:o:r:t:c: namedo case $name in i) pid="$OPTARG";; d) dir="$OPTARG";; s) socket="$OPTARG" params="$params -s $socket";; u) user="$OPTARG" params="$params -u $user";; p) password="$OPTARG" params="$params -p $password";; w) readwrite="$OPTARG" params="$params -w $readwrite";; o) timeout="$OPTARG" params="$params -o $timeout";; r) resultsdir="$OPTARG" params="$params -r $resultsdir";; t) threads="$OPTARG" params="$params -t $threads";; c) clean="$OPTARG";; ?) usage exit;; esacdoneif [[ -z $pid ]]then usage exit 1fi# Have we got any config files to process?for f in $( ls $dir ); do # Stop mysql if running if [ -e $pid ]; then printf "#### Shutting down MySQL \n" sudo kill $(sudo cat $pid) while [ -e $pid ]; do printf "#### Waiting for MySQL to end. \n" sleep 2 done printf "#### MySQL ended. \n" fi # Fire up MySQL with this config and then give it some time to warm up printf "#### Starting MySQL with $f \n" sudo mysqld_safe --defaults-file=$dir/$f & while [ ! -e $pid ]; do printf "#### Waiting for MySQL to start. \n" sleep 2 done printf "#### MySQL started. \n" # Run sysbench passing through some params printf "Running run-sysbench with $params \n" ./run-sysbench $params done# Aggregate the results into a results.csv file./aggregate-results -r $resultsdir > $resultsdir/results.csv# Stop mysql if runningif [ -e $pid ]; then printf "#### Shutting down MySQL \n" sudo kill $(sudo cat $pid) while [ -e $pid ]; do printf "#### Waiting for MySQL to end. \n" sleep 2 done printf "#### MySQL ended. \n" if [ "$clean" == "on" ]; then # Delete the bin log and innodb logs so they can be recreated sudo rm -f $(cat $dir/$f | grep innodb_log_group_home_dir | \ sed -e 's/innodb_log_group_home_dir//' -e 's/ //g' \ -e 's/=//')/ib_* sudo rm -f $(cat $dir/$f | grep log-bin | sed \ -e 's/log-bin//' -e 's/ //g' -e 's/=//')* fifiexit 1