|
@@ -37,14 +37,14 @@ BACKUP_INCLUDES_DATABASES="no"
|
37
|
37
|
function store_original_mariadb_password {
|
38
|
38
|
if [ ! -f /root/.mariadboriginal ]; then
|
39
|
39
|
echo $'Storing original mariadb password'
|
40
|
|
- ORIGINAL_MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
|
|
40
|
+ ORIGINAL_MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
|
41
|
41
|
# We can store this in plaintext because it will soon be of historical interest only
|
42
|
42
|
echo -n "$ORIGINAL_MARIADB_PASSWORD" > /root/.mariadboriginal
|
43
|
43
|
fi
|
44
|
44
|
}
|
45
|
45
|
|
46
|
46
|
function keep_database_running {
|
47
|
|
- if [ ! $(daemon_is_running mariadb) ]; then
|
|
47
|
+ if [ ! "$(daemon_is_running mariadb)" ]; then
|
48
|
48
|
systemctl start mariadb
|
49
|
49
|
fi
|
50
|
50
|
}
|
|
@@ -65,65 +65,65 @@ function backup_database_local {
|
65
|
65
|
|
66
|
66
|
backup_databases_script=/usr/bin/backupdatabases
|
67
|
67
|
if ! grep -q "# Check database daemon" /usr/bin/backupdatabases; then
|
68
|
|
- echo '' >> /usr/bin/backupdatabases
|
69
|
|
- echo '# Check database daemon is running' >> /usr/bin/backupdatabases
|
70
|
|
- echo 'if [ ! $(systemctl is-active mariadb >/dev/null 2>&1 && echo Running) ]; then' >> /usr/bin/backupdatabases
|
71
|
|
- echo ' systemctl start mariadb' >> /usr/bin/backupdatabases
|
72
|
|
- echo 'fi' >> /usr/bin/backupdatabases
|
73
|
|
- echo '' >> /usr/bin/backupdatabases
|
|
68
|
+ { echo '';
|
|
69
|
+ echo '# Check database daemon is running';
|
|
70
|
+ echo "if [ ! \$(systemctl is-active mariadb >/dev/null 2>&1 && echo Running) ]; then";
|
|
71
|
+ echo ' systemctl start mariadb';
|
|
72
|
+ echo 'fi';
|
|
73
|
+ echo ''; } >> /usr/bin/backupdatabases
|
74
|
74
|
fi
|
75
|
75
|
|
76
|
76
|
if ! grep -q "# Backup the ${database_name} database" $backup_databases_script; then
|
77
|
|
- echo "# Backup the ${database_name} database" >> $backup_databases_script
|
78
|
|
- echo "TEMPFILE=/root/${database_name}.sql" >> $backup_databases_script
|
79
|
|
- echo "DAILYFILE=/var/backups/${database_name}_daily.sql" >> $backup_databases_script
|
80
|
|
- echo "mysqldump --password=\"\$MYSQL_PASSWORD\" ${database_name} > \$TEMPFILE" >> $backup_databases_script
|
81
|
|
- echo 'FILESIZE=$(stat -c%s $TEMPFILE)' >> $backup_databases_script
|
82
|
|
- echo 'if [ "$FILESIZE" -eq "0" ]; then' >> $backup_databases_script
|
83
|
|
- echo ' if [ -f $DAILYFILE ]; then' >> $backup_databases_script
|
84
|
|
- echo ' cp $DAILYFILE $TEMPFILE' >> $backup_databases_script
|
85
|
|
- echo '' >> $backup_databases_script
|
86
|
|
- echo ' # try to restore yesterdays database' >> $backup_databases_script
|
87
|
|
- echo " mysql -u root --password=\"\$MYSQL_PASSWORD\" ${database_name} -o < \$DAILYFILE" >> $backup_databases_script
|
88
|
|
- echo '' >> $backup_databases_script
|
89
|
|
- echo ' # Send a warning email' >> $backup_databases_script
|
90
|
|
- echo " echo \"Unable to create a backup of the ${database_name} database. Attempted to restore from yesterdays backup\" | mail -s \"${database_name} backup\" \$EMAIL" >> $backup_databases_script
|
91
|
|
- echo ' else' >> $backup_databases_script
|
92
|
|
- echo ' # Send a warning email' >> $backup_databases_script
|
93
|
|
- echo " echo \"Unable to create a backup of the ${database_name} database.\" | mail -s \"${database_name} backup\" \$EMAIL" >> $backup_databases_script
|
94
|
|
- echo ' fi' >> $backup_databases_script
|
95
|
|
- echo 'else' >> $backup_databases_script
|
96
|
|
- echo ' chmod 600 $TEMPFILE' >> $backup_databases_script
|
97
|
|
- echo ' mv $TEMPFILE $DAILYFILE' >> $backup_databases_script
|
98
|
|
- echo '' >> $backup_databases_script
|
99
|
|
- echo ' # Make the backup readable only by root' >> $backup_databases_script
|
100
|
|
- echo ' chmod 600 $DAILYFILE' >> $backup_databases_script
|
101
|
|
- echo 'fi' >> $backup_databases_script
|
102
|
|
- echo "# End of ${database_name} database backup" >> $backup_databases_script
|
|
77
|
+ { echo "# Backup the ${database_name} database";
|
|
78
|
+ echo "TEMPFILE=/root/${database_name}.sql";
|
|
79
|
+ echo "DAILYFILE=/var/backups/${database_name}_daily.sql";
|
|
80
|
+ echo "mysqldump --password=\"\$MYSQL_PASSWORD\" ${database_name} > \$TEMPFILE";
|
|
81
|
+ echo "FILESIZE=\$(stat -c%s \$TEMPFILE)";
|
|
82
|
+ echo "if [ \"\$FILESIZE\" -eq \"0\" ]; then";
|
|
83
|
+ echo " if [ -f \$DAILYFILE ]; then";
|
|
84
|
+ echo " cp \$DAILYFILE \$TEMPFILE";
|
|
85
|
+ echo '';
|
|
86
|
+ echo ' # try to restore yesterdays database';
|
|
87
|
+ echo " mysql -u root --password=\"\$MYSQL_PASSWORD\" ${database_name} -o < \$DAILYFILE";
|
|
88
|
+ echo '';
|
|
89
|
+ echo ' # Send a warning email';
|
|
90
|
+ echo " echo \"Unable to create a backup of the ${database_name} database. Attempted to restore from yesterdays backup\" | mail -s \"${database_name} backup\" \$EMAIL";
|
|
91
|
+ echo ' else';
|
|
92
|
+ echo ' # Send a warning email';
|
|
93
|
+ echo " echo \"Unable to create a backup of the ${database_name} database.\" | mail -s \"${database_name} backup\" \$EMAIL";
|
|
94
|
+ echo ' fi';
|
|
95
|
+ echo 'else';
|
|
96
|
+ echo " chmod 600 \$TEMPFILE";
|
|
97
|
+ echo " mv \$TEMPFILE \$DAILYFILE";
|
|
98
|
+ echo '';
|
|
99
|
+ echo ' # Make the backup readable only by root';
|
|
100
|
+ echo " chmod 600 \$DAILYFILE";
|
|
101
|
+ echo 'fi';
|
|
102
|
+ echo "# End of ${database_name} database backup"; } >> $backup_databases_script
|
103
|
103
|
fi
|
104
|
104
|
|
105
|
105
|
weekly_backup_script=/etc/cron.weekly/backupdatabasesweekly
|
106
|
106
|
if ! grep -q "Backup ${database_name}" ${weekly_backup_script}; then
|
107
|
|
- echo "# Backup ${database_name}" >> ${weekly_backup_script}
|
108
|
|
- echo "if [ -f /var/backups/${database_name}_weekly.sql ]; then" >> ${weekly_backup_script}
|
109
|
|
- echo " cp -f /var/backups/${database_name}_weekly.sql /var/backups/${database_name}_2weekly.sql" >> ${weekly_backup_script}
|
110
|
|
- echo 'fi' >> ${weekly_backup_script}
|
111
|
|
- echo "if [ -f /var/backups/${database_name}_daily.sql ]; then" >> ${weekly_backup_script}
|
112
|
|
- echo " cp -f /var/backups/${database_name}_daily.sql /var/backups/${database_name}_weekly.sql" >> ${weekly_backup_script}
|
113
|
|
- echo 'fi' >> ${weekly_backup_script}
|
114
|
|
- echo "# End of backup for ${database_name}" >> ${weekly_backup_script}
|
|
107
|
+ { echo "# Backup ${database_name}";
|
|
108
|
+ echo "if [ -f /var/backups/${database_name}_weekly.sql ]; then";
|
|
109
|
+ echo " cp -f /var/backups/${database_name}_weekly.sql /var/backups/${database_name}_2weekly.sql";
|
|
110
|
+ echo 'fi';
|
|
111
|
+ echo "if [ -f /var/backups/${database_name}_daily.sql ]; then";
|
|
112
|
+ echo " cp -f /var/backups/${database_name}_daily.sql /var/backups/${database_name}_weekly.sql";
|
|
113
|
+ echo 'fi';
|
|
114
|
+ echo "# End of backup for ${database_name}"; } >> ${weekly_backup_script}
|
115
|
115
|
fi
|
116
|
116
|
|
117
|
117
|
monthly_backup_script=/etc/cron.monthly/backupdatabasesmonthly
|
118
|
118
|
if ! grep -q "Backup ${database_name}" ${monthly_backup_script}; then
|
119
|
|
- echo "# Backup ${database_name}" >> ${monthly_backup_script}
|
120
|
|
- echo "if [ -f /var/backups/${database_name}_monthly.sql ]; then" >> ${monthly_backup_script}
|
121
|
|
- echo " cp -f /var/backups/${database_name}_monthly.sql /var/backups/${database_name}_2monthly.sql" >> ${monthly_backup_script}
|
122
|
|
- echo 'fi' >> ${monthly_backup_script}
|
123
|
|
- echo "if [ -f /var/backups/${database_name}_weekly.sql ]; then" >> ${monthly_backup_script}
|
124
|
|
- echo " cp -f /var/backups/${database_name}_weekly.sql /var/backups/${database_name}_monthly.sql" >> ${monthly_backup_script}
|
125
|
|
- echo 'fi' >> ${monthly_backup_script}
|
126
|
|
- echo "# End of backup for ${database_name}" >> ${monthly_backup_script}
|
|
119
|
+ { echo "# Backup ${database_name}";
|
|
120
|
+ echo "if [ -f /var/backups/${database_name}_monthly.sql ]; then";
|
|
121
|
+ echo " cp -f /var/backups/${database_name}_monthly.sql /var/backups/${database_name}_2monthly.sql";
|
|
122
|
+ echo 'fi';
|
|
123
|
+ echo "if [ -f /var/backups/${database_name}_weekly.sql ]; then";
|
|
124
|
+ echo " cp -f /var/backups/${database_name}_weekly.sql /var/backups/${database_name}_monthly.sql";
|
|
125
|
+ echo 'fi';
|
|
126
|
+ echo "# End of backup for ${database_name}"; } >> ${monthly_backup_script}
|
127
|
127
|
fi
|
128
|
128
|
|
129
|
129
|
if ! grep -q "${database_name}" /etc/cron.hourly/repair; then
|
|
@@ -138,15 +138,15 @@ function get_mariadb_password {
|
138
|
138
|
DATABASE_PASSWORD_FILE=/root/dbpass
|
139
|
139
|
if [ -f $DATABASE_PASSWORD_FILE ]; then
|
140
|
140
|
MARIADB_PASSWORD=$(cat $DATABASE_PASSWORD_FILE)
|
141
|
|
- ${PROJECT_NAME}-pass -u root -a mariadb -p "$MARIADB_PASSWORD"
|
142
|
|
- stored_password=$(${PROJECT_NAME}-pass -u root -a mariadb)
|
|
141
|
+ "${PROJECT_NAME}-pass" -u root -a mariadb -p "$MARIADB_PASSWORD"
|
|
142
|
+ stored_password=$("${PROJECT_NAME}-pass" -u root -a mariadb)
|
143
|
143
|
if [[ "$stored_password" == "$MARIADB_PASSWORD" ]]; then
|
144
|
144
|
shred -zu $DATABASE_PASSWORD_FILE
|
145
|
145
|
echo $'MariaDB password moved into password store'
|
146
|
146
|
return
|
147
|
147
|
fi
|
148
|
148
|
fi
|
149
|
|
- MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
|
|
149
|
+ MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
|
150
|
150
|
if [[ "$MARIADB_PASSWORD" == *'failed'* ]]; then
|
151
|
151
|
echo $'Could not obtain mariadb password'
|
152
|
152
|
exit 835225
|
|
@@ -155,12 +155,12 @@ function get_mariadb_password {
|
155
|
155
|
|
156
|
156
|
function mariadb_kill_stone_dead {
|
157
|
157
|
systemctl stop mariadb
|
158
|
|
- kill_pid=$(ps aux | grep mysqld_safe | awk -F ' ' '{print $2}' | head -n 1)
|
159
|
|
- kill -9 $kill_pid
|
160
|
|
- kill_pid=$(ps aux | grep mysqld | awk -F ' ' '{print $2}' | head -n 1)
|
161
|
|
- kill -9 $kill_pid
|
162
|
|
- kill_pid=$(ps aux | grep mysqld | awk -F ' ' '{print $2}' | head -n 1)
|
163
|
|
- kill -9 $kill_pid
|
|
158
|
+ kill_pid=$(pgrep mysqld_safe | head -n 1)
|
|
159
|
+ kill -9 "$kill_pid"
|
|
160
|
+ kill_pid=$(pgrep mysqld | head -n 1)
|
|
161
|
+ kill -9 "$kill_pid"
|
|
162
|
+ kill_pid=$(pgrep mysqld | head -n 1)
|
|
163
|
+ kill -9 "$kill_pid"
|
164
|
164
|
}
|
165
|
165
|
|
166
|
166
|
function mariadb_fix_authentication {
|
|
@@ -201,14 +201,15 @@ function install_mariadb {
|
201
|
201
|
|
202
|
202
|
function_check get_mariadb_password
|
203
|
203
|
get_mariadb_password
|
204
|
|
- if [ ! $MARIADB_PASSWORD ]; then
|
205
|
|
- if [ -f $IMAGE_PASSWORD_FILE ]; then
|
206
|
|
- MARIADB_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
|
|
204
|
+ if [ ! "$MARIADB_PASSWORD" ]; then
|
|
205
|
+ if [ -f "$IMAGE_PASSWORD_FILE" ]; then
|
|
206
|
+ passfile="$(cat "$IMAGE_PASSWORD_FILE")"
|
|
207
|
+ MARIADB_PASSWORD="$(printf "%s" "$passfile")"
|
207
|
208
|
else
|
208
|
|
- MARIADB_PASSWORD="$(openssl rand -base64 32 | cut -c1-${MINIMUM_PASSWORD_LENGTH})"
|
|
209
|
+ MARIADB_PASSWORD=$(create_password "${MINIMUM_PASSWORD_LENGTH}")
|
209
|
210
|
fi
|
210
|
211
|
fi
|
211
|
|
- ${PROJECT_NAME}-pass -u root -a mariadb -p "$MARIADB_PASSWORD"
|
|
212
|
+ "${PROJECT_NAME}-pass" -u root -a mariadb -p "$MARIADB_PASSWORD"
|
212
|
213
|
|
213
|
214
|
debconf-set-selections <<< "mariadb-server mariadb-server/root_password password $MARIADB_PASSWORD"
|
214
|
215
|
debconf-set-selections <<< "mariadb-server mariadb-server/root_password_again password $MARIADB_PASSWORD"
|
|
@@ -243,37 +244,37 @@ function install_mariadb {
|
243
|
244
|
function backup_databases_script_header {
|
244
|
245
|
if [ ! -f /usr/bin/backupdatabases ]; then
|
245
|
246
|
# daily
|
246
|
|
- echo '#!/bin/sh' > /usr/bin/backupdatabases
|
247
|
|
- echo '' >> /usr/bin/backupdatabases
|
248
|
|
- echo "EMAIL='$MY_EMAIL_ADDRESS'" >> /usr/bin/backupdatabases
|
249
|
|
- echo '' >> /usr/bin/backupdatabases
|
250
|
|
- echo "MYSQL_PASSWORD=\$(${PROJECT_NAME}-pass -u root -a mariadb)" >> /usr/bin/backupdatabases
|
251
|
|
- echo 'umask 0077' >> /usr/bin/backupdatabases
|
252
|
|
- echo '' >> /usr/bin/backupdatabases
|
253
|
|
- echo '# exit if we are backing up to friends servers' >> /usr/bin/backupdatabases
|
254
|
|
- echo "if [ -f $FRIENDS_SERVERS_LIST ]; then" >> /usr/bin/backupdatabases
|
255
|
|
- echo ' exit 1' >> /usr/bin/backupdatabases
|
256
|
|
- echo 'fi' >> /usr/bin/backupdatabases
|
|
247
|
+ { echo '#!/bin/sh';
|
|
248
|
+ echo '';
|
|
249
|
+ echo "EMAIL='$MY_EMAIL_ADDRESS'";
|
|
250
|
+ echo '';
|
|
251
|
+ echo "MYSQL_PASSWORD=\$(${PROJECT_NAME}-pass -u root -a mariadb)";
|
|
252
|
+ echo 'umask 0077';
|
|
253
|
+ echo '';
|
|
254
|
+ echo '# exit if we are backing up to friends servers';
|
|
255
|
+ echo "if [ -f $FRIENDS_SERVERS_LIST ]; then";
|
|
256
|
+ echo ' exit 1';
|
|
257
|
+ echo 'fi'; } > /usr/bin/backupdatabases
|
257
|
258
|
chmod 600 /usr/bin/backupdatabases
|
258
|
259
|
chmod +x /usr/bin/backupdatabases
|
259
|
260
|
|
260
|
|
- echo '#!/bin/sh' > /etc/cron.daily/backupdatabasesdaily
|
261
|
|
- echo '/usr/bin/backupdatabases' >> /etc/cron.daily/backupdatabasesdaily
|
|
261
|
+ { echo '#!/bin/sh';
|
|
262
|
+ echo '/usr/bin/backupdatabases'; } > /etc/cron.daily/backupdatabasesdaily
|
262
|
263
|
chmod 600 /etc/cron.daily/backupdatabasesdaily
|
263
|
264
|
chmod +x /etc/cron.daily/backupdatabasesdaily
|
264
|
265
|
|
265
|
266
|
# weekly
|
266
|
|
- echo '#!/bin/sh' > /etc/cron.weekly/backupdatabasesweekly
|
267
|
|
- echo '' >> /etc/cron.weekly/backupdatabasesweekly
|
268
|
|
- echo 'umask 0077' >> /etc/cron.weekly/backupdatabasesweekly
|
|
267
|
+ { echo '#!/bin/sh';
|
|
268
|
+ echo '';
|
|
269
|
+ echo 'umask 0077'; } > /etc/cron.weekly/backupdatabasesweekly
|
269
|
270
|
|
270
|
271
|
chmod 600 /etc/cron.weekly/backupdatabasesweekly
|
271
|
272
|
chmod +x /etc/cron.weekly/backupdatabasesweekly
|
272
|
273
|
|
273
|
274
|
# monthly
|
274
|
|
- echo '#!/bin/sh' > /etc/cron.monthly/backupdatabasesmonthly
|
275
|
|
- echo '' >> /etc/cron.monthly/backupdatabasesmonthly
|
276
|
|
- echo 'umask 0077' >> /etc/cron.monthly/backupdatabasesmonthly
|
|
275
|
+ { echo '#!/bin/sh';
|
|
276
|
+ echo '';
|
|
277
|
+ echo 'umask 0077'; } > /etc/cron.monthly/backupdatabasesmonthly
|
277
|
278
|
|
278
|
279
|
chmod 600 /etc/cron.monthly/backupdatabasesmonthly
|
279
|
280
|
chmod +x /etc/cron.monthly/backupdatabasesmonthly
|
|
@@ -289,7 +290,7 @@ function repair_databases_script {
|
289
|
290
|
return
|
290
|
291
|
fi
|
291
|
292
|
|
292
|
|
- db_pass=$(${PROJECT_NAME}-pass -u root -p mariadb)
|
|
293
|
+ db_pass=$("${PROJECT_NAME}-pass" -u root -p mariadb)
|
293
|
294
|
if [[ "$db_pass" == 'Error:'* ]]; then
|
294
|
295
|
return
|
295
|
296
|
fi
|
|
@@ -304,22 +305,23 @@ function repair_databases_script {
|
304
|
305
|
|
305
|
306
|
function remove_database {
|
306
|
307
|
app_name="$1"
|
307
|
|
- if [ ! -d $INSTALL_DIR ]; then
|
308
|
|
- mkdir $INSTALL_DIR
|
|
308
|
+ if [ ! -d "$INSTALL_DIR" ]; then
|
|
309
|
+ mkdir "$INSTALL_DIR"
|
309
|
310
|
fi
|
310
|
311
|
echo "drop database ${app_name};
|
311
|
|
-quit" > $INSTALL_DIR/batch.sql
|
312
|
|
- chmod 600 $INSTALL_DIR/batch.sql
|
|
312
|
+quit" > "$INSTALL_DIR/batch.sql"
|
|
313
|
+ chmod 600 "$INSTALL_DIR/batch.sql"
|
313
|
314
|
keep_database_running
|
314
|
|
- mysql -u root --password="$MARIADB_PASSWORD" < $INSTALL_DIR/batch.sql
|
315
|
|
- shred -zu $INSTALL_DIR/batch.sql
|
|
315
|
+ mysql -u root --password="$MARIADB_PASSWORD" < "$INSTALL_DIR/batch.sql"
|
|
316
|
+ shred -zu "$INSTALL_DIR/batch.sql"
|
316
|
317
|
}
|
317
|
318
|
|
318
|
319
|
function initialise_database {
|
319
|
320
|
database_name=$1
|
320
|
321
|
database_file=$2
|
321
|
322
|
keep_database_running
|
322
|
|
- mysql -u root --password="$MARIADB_PASSWORD" -D $database_name < $database_file
|
|
323
|
+ mysql -u root --password="$MARIADB_PASSWORD" -D "$database_name" < "$database_file"
|
|
324
|
+ # shellcheck disable=SC2181
|
323
|
325
|
if [ ! "$?" = "0" ]; then
|
324
|
326
|
exit 62952
|
325
|
327
|
fi
|
|
@@ -329,25 +331,25 @@ function run_query {
|
329
|
331
|
database_name=$1
|
330
|
332
|
database_query=$2
|
331
|
333
|
keep_database_running
|
332
|
|
- mysql -u root --password="$MARIADB_PASSWORD" -e "$database_query" $database_name
|
|
334
|
+ mysql -u root --password="$MARIADB_PASSWORD" -e "$database_query" "$database_name"
|
333
|
335
|
}
|
334
|
336
|
|
335
|
337
|
function run_query_root {
|
336
|
338
|
database_name=$1
|
337
|
339
|
database_query=$2
|
338
|
340
|
keep_database_running
|
339
|
|
- mysql -e "$database_query" $database_name
|
|
341
|
+ mysql -e "$database_query" "$database_name"
|
340
|
342
|
}
|
341
|
343
|
|
342
|
344
|
function create_database {
|
343
|
345
|
app_name="$1"
|
344
|
346
|
app_admin_password="$2"
|
345
|
347
|
app_admin_username=$3
|
346
|
|
- if [ ! -d $INSTALL_DIR ]; then
|
347
|
|
- mkdir $INSTALL_DIR
|
|
348
|
+ if [ ! -d "$INSTALL_DIR" ]; then
|
|
349
|
+ mkdir "$INSTALL_DIR"
|
348
|
350
|
fi
|
349
|
|
- if [ ! $app_admin_username ]; then
|
350
|
|
- app_admin_username=${app_name}admin
|
|
351
|
+ if [ ! "$app_admin_username" ]; then
|
|
352
|
+ app_admin_username="${app_name}admin"
|
351
|
353
|
fi
|
352
|
354
|
|
353
|
355
|
echo "create database ${app_name};
|
|
@@ -355,11 +357,11 @@ CREATE USER '$app_admin_username@localhost' IDENTIFIED BY '${app_admin_password}
|
355
|
357
|
update mysql.user set plugin = '' where User='$app_admin_username@localhost';
|
356
|
358
|
GRANT ALL PRIVILEGES ON ${app_name}.* TO '$app_admin_username@localhost';
|
357
|
359
|
flush privileges;
|
358
|
|
-quit" > $INSTALL_DIR/batch.sql
|
359
|
|
- chmod 600 $INSTALL_DIR/batch.sql
|
|
360
|
+quit" > "$INSTALL_DIR/batch.sql"
|
|
361
|
+ chmod 600 "$INSTALL_DIR/batch.sql"
|
360
|
362
|
keep_database_running
|
361
|
|
- mysql -u root --password="$MARIADB_PASSWORD" < $INSTALL_DIR/batch.sql
|
362
|
|
- shred -zu $INSTALL_DIR/batch.sql
|
|
363
|
+ mysql -u root --password="$MARIADB_PASSWORD" < "$INSTALL_DIR/batch.sql"
|
|
364
|
+ shred -zu "$INSTALL_DIR/batch.sql"
|
363
|
365
|
}
|
364
|
366
|
|
365
|
367
|
function run_query_with_output {
|
|
@@ -381,11 +383,11 @@ function drop_database {
|
381
|
383
|
|
382
|
384
|
echo "drop database ${app_name};
|
383
|
385
|
flush privileges;
|
384
|
|
-quit" > $INSTALL_DIR/batch.sql
|
385
|
|
- chmod 600 $INSTALL_DIR/batch.sql
|
|
386
|
+quit" > "$INSTALL_DIR/batch.sql"
|
|
387
|
+ chmod 600 "$INSTALL_DIR/batch.sql"
|
386
|
388
|
keep_database_running
|
387
|
|
- mysql -u root --password="$MARIADB_PASSWORD" < $INSTALL_DIR/batch.sql
|
388
|
|
- shred -zu $INSTALL_DIR/batch.sql
|
|
389
|
+ mysql -u root --password="$MARIADB_PASSWORD" < "$INSTALL_DIR/batch.sql"
|
|
390
|
+ shred -zu "$INSTALL_DIR/batch.sql"
|
389
|
391
|
}
|
390
|
392
|
|
391
|
393
|
|
|
@@ -393,7 +395,7 @@ function database_reinstall {
|
393
|
395
|
apt-get -yq purge mariadb*
|
394
|
396
|
rm -rf /var/lib/mysql
|
395
|
397
|
rm -rf /etc/mysql
|
396
|
|
- sed -i '/mariadb/d' ~/${PROJECT_NAME}-completed.txt
|
|
398
|
+ sed -i '/mariadb/d' "${HOME}/${PROJECT_NAME}-completed.txt"
|
397
|
399
|
install_mariadb
|
398
|
400
|
}
|
399
|
401
|
|
|
@@ -404,11 +406,11 @@ function install_rethinkdb {
|
404
|
406
|
exit 723723452
|
405
|
407
|
fi
|
406
|
408
|
|
407
|
|
- if [ ! -d $INSTALL_DIR ]; then
|
408
|
|
- mkdir -p $INSTALL_DIR
|
|
409
|
+ if [ ! -d "$INSTALL_DIR" ]; then
|
|
410
|
+ mkdir -p "$INSTALL_DIR"
|
409
|
411
|
fi
|
410
|
412
|
|
411
|
|
- cd $INSTALL_DIR
|
|
413
|
+ cd "$INSTALL_DIR" || exit 6384684
|
412
|
414
|
|
413
|
415
|
echo "deb http://download.rethinkdb.com/apt $DEBIAN_VERSION main" | tee /etc/apt/sources.list.d/rethinkdb.list
|
414
|
416
|
|
|
@@ -416,25 +418,25 @@ function install_rethinkdb {
|
416
|
418
|
apt-get update
|
417
|
419
|
apt-get -yq install rethinkdb
|
418
|
420
|
|
419
|
|
- echo 'runuser=rethinkdb' > /etc/rethinkdb/instances.d/default.conf
|
420
|
|
- echo 'rungroup=rethinkdb' >> /etc/rethinkdb/instances.d/default.conf
|
421
|
|
- echo '# pid-file=/var/run/rethinkdb/rethinkdb.pid' >> /etc/rethinkdb/instances.d/default.conf
|
422
|
|
- echo '# directory=/var/lib/rethinkdb/default' >> /etc/rethinkdb/instances.d/default.conf
|
423
|
|
- echo '# log-file=/var/log/rethinkdb' >> /etc/rethinkdb/instances.d/default.conf
|
424
|
|
- echo 'bind=127.0.0.1' >> /etc/rethinkdb/instances.d/default.conf
|
425
|
|
- echo '# canonical-address=' >> /etc/rethinkdb/instances.d/default.conf
|
426
|
|
- echo '# driver-port=28015' >> /etc/rethinkdb/instances.d/default.conf
|
427
|
|
- echo '# cluster-port=29015' >> /etc/rethinkdb/instances.d/default.conf
|
428
|
|
- echo '# join=example.com:29015' >> /etc/rethinkdb/instances.d/default.conf
|
429
|
|
- echo '# port-offset=0' >> /etc/rethinkdb/instances.d/default.conf
|
430
|
|
- echo '# reql-http-proxy=socks5://example.com:1080' >> /etc/rethinkdb/instances.d/default.conf
|
431
|
|
- echo '# http-port=8091' >> /etc/rethinkdb/instances.d/default.conf
|
432
|
|
- echo '# no-http-admin' >> /etc/rethinkdb/instances.d/default.conf
|
433
|
|
- echo '# cores=2' >> /etc/rethinkdb/instances.d/default.conf
|
434
|
|
- echo '# cache-size=1024' >> /etc/rethinkdb/instances.d/default.conf
|
435
|
|
- echo '# io-threads=64' >> /etc/rethinkdb/instances.d/default.conf
|
436
|
|
- echo '# direct-io' >> /etc/rethinkdb/instances.d/default.conf
|
437
|
|
- echo '# server-name=server1' >> /etc/rethinkdb/instances.d/default.conf
|
|
421
|
+ { echo 'runuser=rethinkdb';
|
|
422
|
+ echo 'rungroup=rethinkdb';
|
|
423
|
+ echo '# pid-file=/var/run/rethinkdb/rethinkdb.pid';
|
|
424
|
+ echo '# directory=/var/lib/rethinkdb/default';
|
|
425
|
+ echo '# log-file=/var/log/rethinkdb';
|
|
426
|
+ echo 'bind=127.0.0.1';
|
|
427
|
+ echo '# canonical-address=';
|
|
428
|
+ echo '# driver-port=28015';
|
|
429
|
+ echo '# cluster-port=29015';
|
|
430
|
+ echo '# join=example.com:29015';
|
|
431
|
+ echo '# port-offset=0';
|
|
432
|
+ echo '# reql-http-proxy=socks5://example.com:1080';
|
|
433
|
+ echo '# http-port=8091';
|
|
434
|
+ echo '# no-http-admin';
|
|
435
|
+ echo '# cores=2';
|
|
436
|
+ echo '# cache-size=1024';
|
|
437
|
+ echo '# io-threads=64';
|
|
438
|
+ echo '# direct-io';
|
|
439
|
+ echo '# server-name=server1'; } > /etc/rethinkdb/instances.d/default.conf
|
438
|
440
|
|
439
|
441
|
systemctl restart rethinkdb
|
440
|
442
|
}
|