20
20
#
21
21
# Script to set the system up for running hammerdb.
22
22
#
23
- disks=none
24
- mountpoint=none
25
- db_type=none
26
- log_mount_point=" none "
23
+ disks=
24
+ mountpoint=
25
+ db_type=
26
+ log_mount_point=
27
27
28
28
install_mssql ()
29
29
{
@@ -32,50 +32,50 @@ install_mssql()
32
32
curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/msprod.repo
33
33
yum -y remove unixODBC-utf16 unixODBC-utf16-devel
34
34
ACCEPT_EULA=Y yum install -y mssql-tools unixODBC-devel
35
+ # shellcheck disable=SC2016
35
36
echo ' export PATH="$PATH:/opt/mssql-tools/bin"' >> ~ /.bash_profile
36
- cd /usr/local/HammerDB
37
+ cd /usr/local/HammerDB || fatal " Cannot cd /usr/local/hammerdb "
37
38
cp -R /tmp/hammerdb-tpcc/mssql/* .
38
39
39
40
40
- rm -rf ${mountpoint} /mssql_data/*
41
- mkdir -p ${mountpoint} /mssql_data
42
- chown -R mssql:mssql ${mountpoint} /mssql_data
43
- chown -R mssql:mssql /perf1/mssql_data
41
+ rm -rf " ${mountpoint} " /mssql_data/
42
+ mkdir -p " ${mountpoint} " /mssql_data
43
+ chown -R mssql:mssql " ${mountpoint} " /mssql_data
44
44
45
45
systemctl stop mssql-server
46
46
47
- cd /opt/mssql/bin/
47
+ cd /opt/mssql/bin/ || fatal " Cannot cd /opt/mssql/bin "
48
48
mkdir /var/opt/mssql/secrets/
49
49
50
50
MSSQL_SA_PASSWORD=" 100yard-"
51
51
export MSSQL_SA_PASSWORD
52
- export MSSQL_PID=" Evaluation"
52
+ export MSSQL_PID=" Evaluation"
53
53
54
54
rm -rf /var/opt/mssql
55
55
chmod 777 /var/opt
56
56
57
- echo 1 > input
58
- echo Yes >> input
59
- echo 100yard- >> input
60
- echo 100yard- >> input
61
-
62
- ./mssql-conf -n setup accept-eula < input
57
+ ./mssql-conf -n setup accept-eula << ' EOF '
58
+ 1
59
+ Yes
60
+ 100yard-
61
+ 100yard-
62
+ EOF
63
63
64
64
sleep 30
65
65
systemctl stop mssql-server
66
66
67
- cd /var/opt/mssql
68
- mv data ${mountpoint} /mssql_data
69
- ln -sf ${mountpoint} /mssql_data/data .
67
+ cd /var/opt/mssql || fatal " Cannot cd /var/opt/mssql "
68
+ mv data " ${mountpoint} " /mssql_data
69
+ ln -sf " ${mountpoint} " /mssql_data/data .
70
70
71
71
systemctl disable mssql-server.service
72
72
systemctl restart mssql-server.service
73
73
74
- cd /usr/local/HammerDB
74
+ cd /usr/local/HammerDB || fatal " Cannot cd /usr/local/hammerdb "
75
75
76
- ./createdb_mssql_mnt.sh -m ${mountpoint} > crdb.out 2>&1
76
+ ./createdb_mssql_mnt.sh -m " ${mountpoint} " > crdb.out 2>&1
77
77
78
- ./update_temp_mnt.sh -m ${mountpoint} > upd_tmp.out 2>&1
78
+ ./update_temp_mnt.sh -m " ${mountpoint} " > upd_tmp.out 2>&1
79
79
}
80
80
81
81
install_mariadb ()
@@ -92,33 +92,33 @@ install_mariadb()
92
92
#
93
93
# Configure things in and mount the appropriate item.
94
94
#
95
- cd /usr/local/HammerDB
95
+ cd /usr/local/HammerDB || fatal " Cannot cd /usr/local/hammerdb "
96
96
cp -R /tmp/hammerdb-tpcc/mariadb/* .
97
97
98
98
#
99
99
# Clean up any residual stuff and set up the directories
100
100
#
101
- rm -rf ${mountpoint} /mysql/* ${log_mount_point} /mysql/log
102
- mkdir -p ${mountpoint} /mysql/data
103
- chown -R mysql:mysql ${mountpoint} /mysql
104
- mkdir -p ${log_mount_point} /mysql/log
105
- chown -R mysql:mysql ${log_mount_point} /mysql
101
+ rm -rf " ${mountpoint} " /mysql/* " ${log_mount_point} " /mysql/log
102
+ mkdir -p " ${mountpoint} " /mysql/data
103
+ chown -R mysql:mysql " ${mountpoint} " /mysql
104
+ mkdir -p " ${log_mount_point} " /mysql/log
105
+ chown -R mysql:mysql " ${log_mount_point} " /mysql
106
106
107
107
108
- totmem=` cat /proc/meminfo | grep " MemTotal: " | awk ' {print $2}' `
108
+ totmem=$( grep MemTotal /proc/meminfo | awk ' {print $2}' )
109
109
#
110
110
# Updating the value of buffer_pool_size based on available memory
111
111
# Setting bufferpool to half of physical memory if memory is less than 128G else set to 64G
112
112
#
113
- totmem_BP=` expr $ totmem / 1024`
114
- totmem_BP=` expr $ totmem_BP / 2`
113
+ totmem_BP=$(( totmem / 1024 ))
114
+ totmem_BP=$(( totmem_BP / 2 ))
115
115
116
116
#
117
117
# Configure the mariadb config file with mountpoint and bufferpool
118
118
#
119
119
120
120
sed -i " s+^datadir=.*+datadir=${mountpoint} \/mysql\/data+" my.cnf
121
- if [ $ totmem_BP -lt 64000 ] ; then
121
+ if (( totmem_BP << 64000 )) ; then
122
122
sed -i " s/^innodb_buffer_pool_size=.*/innodb_buffer_pool_size=${totmem_BP} M/" my.cnf
123
123
else
124
124
sed -i " s/^innodb_buffer_pool_size=.*/innodb_buffer_pool_size=64000M/" my.cnf
@@ -148,35 +148,35 @@ install_postgres()
148
148
#
149
149
dnf -y install postgresql.x86_64 postgresql-contrib.x86_64 postgresql-server.x86_64 glibc-langpack-en libpq
150
150
151
- cd /usr/local/HammerDB
151
+ cd /usr/local/HammerDB || fatal " Cannot cd /usr/local/hammerdb "
152
152
cp -R /tmp/hammerdb-tpcc/postgres/* .
153
153
154
154
rm -rf /var/lib/pgsql/data
155
- rm -rf ${mountpoint} /postgres_data
155
+ rm -rf " ${mountpoint} " /postgres_data
156
156
157
- mkdir -p ${mountpoint} /postgres_data
158
- ln -sf ${mountpoint} /postgres_data /var/lib/pgsql/data
159
- chmod 700 ${mountpoint} /postgres_data
160
- chown -R postgres:postgres ${mountpoint} /postgres_data
161
- mkdir -p ${log_mount_point} /postgres_log
162
- chown -R mysql:mysql ${log_mount_point} /postgres_log
157
+ mkdir -p " ${mountpoint} " /postgres_data
158
+ ln -sf " ${mountpoint} " /postgres_data /var/lib/pgsql/data
159
+ chmod 700 " ${mountpoint} " /postgres_data
160
+ chown -R postgres:postgres " ${mountpoint} " /postgres_data
161
+ mkdir -p " ${log_mount_point} " /postgres_log
162
+ chown -R mysql:mysql " ${log_mount_point} " /postgres_log
163
163
164
164
postgresql-setup initdb
165
165
sleep 10
166
- mv /var/lib/pgsql/data/pg_wal ${log_mount_point} /postgres_log
167
- ln -sf ${log_mount_point} /postgres_log/pg_wal /var/lib/pgsql/data/pg_wal
166
+ mv /var/lib/pgsql/data/pg_wal " ${log_mount_point} " /postgres_log
167
+ ln -sf " ${log_mount_point} " /postgres_log/pg_wal /var/lib/pgsql/data/pg_wal
168
168
169
- totmem=` cat /proc/meminfo | grep " MemTotal: " | awk ' {print $2}' `
169
+ totmem=$( grep MemTotal /proc/meminfo | awk ' {print $2}' )
170
170
171
171
#
172
172
# Change shared_buffer size based on available memory
173
173
#
174
- totmem_MB=` expr $ totmem / 1024`
175
- totmem_BP=` expr $ totmem_MB / 2` # Buffer pool is half of physical memory
174
+ totmem_MB=$(( totmem / 1024 ))
175
+ totmem_BP=$(( totmem_MB / 2 )) # Buffer pool is half of physical memory
176
176
#
177
177
# IF total memory is more than 128G then bufferpool is set to 64G else set to half of physical memory
178
178
#
179
- if [ ${ totmem_BP} -lt 64000 ] ; then
179
+ if (( totmem_BP < 65000 )) ; then
180
180
sed -i " s/^shared_buffers =.*/shared_buffers = ${totmem_BP} MB/" postgresql.conf
181
181
else
182
182
sed -i " s/^shared_buffers =.*/shared_buffers = 64000MB/" postgresql.conf
@@ -194,7 +194,8 @@ install_postgres()
194
194
195
195
usage ()
196
196
{
197
- echo " Usage:
197
+ cat << 'EOF '
198
+ Usage:
198
199
./install-script [-h] [-d disk name] [-m mount point] [-t dbtype]
199
200
200
201
Usage:
@@ -207,51 +208,37 @@ usage()
207
208
Examples:
208
209
./install-script -d '/dev/sdb'
209
210
./install-script -d '/perf1'
210
- "
211
+ EOF
212
+ exit
213
+ }
214
+
215
+ fatal ()
216
+ {
217
+ echo " $* "
218
+ exit 1
211
219
}
212
220
213
221
#
214
222
# If we did not pass any arguments, flag it.
215
223
#
216
224
if [ $# -eq 0 ]; then
217
- usage;
218
- exit ;
225
+ usage
219
226
fi
220
227
221
- while [ $# -gt 0 ]
222
- do
223
- case $1 in
224
- -h)
225
- usage;
226
- exit ;
227
- ;;
228
- -d)
229
- disks=$2
230
- shift 2
231
- ;;
232
- -M)
233
- log_mount_point=$2
234
- shift 2
235
- ;;
236
- -m)
237
- mountpoint=$2
238
- shift 2
239
- ;;
240
- -t)
241
- db_type=$2
242
- shift 2
243
- ;;
244
- * )
245
- usage;
246
- exit ;
247
- ;;
228
+ while getopts ' hd:M:m:t:' opt ; do
229
+ case " $opt " in
230
+ d) disks=" $OPTARG " ;;
231
+ M) log_mount_point=" $OPTARG " ;;
232
+ m) mountpoint=" $OPTARG " ;;
233
+ t) db_type=" $OPTARG " ;;
234
+ h) usage ;;
235
+ * ) usage ;;
248
236
esac
249
237
done
250
238
251
- if [[ $db_type == " none " ]]; then
252
- echo You need to designate the db type.
239
+ if [[ -z " $db_type " ]]; then
240
+ echo " You need to designate the db type."
253
241
usage
254
- exit
255
242
fi
256
243
257
244
#
@@ -267,13 +254,14 @@ curl -k -o /tmp/hammerdb-tpcc.tar https://people.redhat.com/srao/Hammerdb-Kit/ha
267
254
#
268
255
# Install the hammerdb
269
256
#
270
- cd /tmp
257
+ cd /tmp || fatal " Cannot cd /tmp "
271
258
tar xf hammerdb-tpcc.tar
272
- cd /tmp/hammerdb-tpcc/Hammerdb
259
+ cd /tmp/hammerdb-tpcc/Hammerdb || fatal " Cannot cd to hammerdb package directory! "
273
260
unset DISPLAY
274
- echo " y" > input
275
- echo " /usr/local/HammerDB" >> input
276
- ./HammerDB-3.2-Linux-x86-64-Install < input
261
+ ./HammerDB-3.2-Linux-x86-64-Install << 'EOF '
262
+ y
263
+ /usr/local/HammerDB
264
+ EOF
277
265
278
266
#
279
267
# Shutdown all running instances
@@ -285,33 +273,30 @@ systemctl stop mariadb
285
273
#
286
274
# Create filestems and mount if required
287
275
#
288
- if [[ $mountpoint == * " none" * ]]; then
276
+ if [[ -z " $mountpoint " ]]; then
277
+ if [[ -z " $disks " ]] ; then
278
+ echo " Disk must be specified if -m is not used"
279
+ usage
280
+ fi
289
281
echo " using disk option"
290
282
umount /perf1
291
- mkfs.xfs -f ${disks}
283
+ mkfs.xfs -f " ${disks} "
292
284
mkdir -p /perf1
293
- mount ${disks} /perf1
285
+ mount " ${disks} " /perf1
294
286
mountpoint=" /perf1"
295
287
else
296
288
echo " using mountpoint option"
297
- echo ${mountpoint}
298
- fi
299
-
300
- if [[ $log_mount_point == " none" ]]; then
301
- log_mount_point=${mountpoint}
302
- fi
303
- if [[ $db_type == " mssql" ]]; then
304
- install_mssql
305
- exit
306
- fi
307
-
308
- if [[ $db_type == " mariadb" ]]; then
309
- install_mariadb
310
- exit
311
- fi
312
-
313
- if [[ $db_type == " postgres" ]]; then
314
- install_postgres
315
- exit
289
+ echo " ${mountpoint} "
316
290
fi
317
291
292
+ log_mount_point=${log_mount_point:- $mountpoint }
293
+ case " $db_type " in
294
+ mssql) install_mssql ;;
295
+ mariadb) install_mariadb ;;
296
+ postgres) install_postgres ;;
297
+ * ) echo " Unknown database $db_type specified" ; usage ;;
298
+ esac
299
+
300
+ # Local Variables:
301
+ # sh-indentation: 8
302
+ # End:
0 commit comments