summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2018-12-13 12:40:30 -0600
committerRobert Speicher <rspeicher@gmail.com>2019-01-08 11:47:32 -0600
commit5947382ba87729b9f80428f11e2cd77ceaef49d6 (patch)
tree7e8bb40862cfd7c081cb3b6a9e7b1f7f600f4913
parent4d649e98f755f7741360baf9830cf3f05cce3a0e (diff)
downloadgitlab-ce-rs-prepare-k8s-runner.tar.gz
Conditionally setup database usersrs-prepare-k8s-runner
Due to `getent` now always returning a value for both `postgres` and `mysql`, we were always attempting to create database users even when `SETUP_DB` was false. We now check for service availability before attempting to create database users.
-rw-r--r--scripts/create_mysql_user.sh10
-rw-r--r--scripts/create_postgres_user.sh8
-rw-r--r--scripts/prepare_build.sh3
3 files changed, 14 insertions, 7 deletions
diff --git a/scripts/create_mysql_user.sh b/scripts/create_mysql_user.sh
index 71c6169bfd0..6a11a9e12b1 100644
--- a/scripts/create_mysql_user.sh
+++ b/scripts/create_mysql_user.sh
@@ -1,7 +1,9 @@
#!/bin/bash
-mysql --user=root --host=127.0.0.1 <<EOF
-CREATE USER IF NOT EXISTS 'gitlab'@'127.0.0.1';
-GRANT ALL PRIVILEGES ON gitlabhq_test.* TO 'gitlab'@'127.0.0.1';
-FLUSH PRIVILEGES;
+if mysqladmin ping --user=root --host=127.0.0.1; then
+ mysql --user=root --host=127.0.0.1 <<EOF
+ CREATE USER IF NOT EXISTS 'gitlab'@'127.0.0.1';
+ GRANT ALL PRIVILEGES ON gitlabhq_test.* TO 'gitlab'@'127.0.0.1';
+ FLUSH PRIVILEGES;
EOF
+fi
diff --git a/scripts/create_postgres_user.sh b/scripts/create_postgres_user.sh
index 0fa065b0387..8e0f84f62ca 100644
--- a/scripts/create_postgres_user.sh
+++ b/scripts/create_postgres_user.sh
@@ -1,6 +1,8 @@
#!/bin/bash
-psql -h localhost -U postgres postgres <<EOF
-CREATE USER gitlab;
-GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO gitlab;
+if pg_isready -h localhost -U postgres; then
+ psql -h localhost -U postgres postgres <<EOF
+ CREATE USER gitlab;
+ GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO gitlab;
EOF
+fi
diff --git a/scripts/prepare_build.sh b/scripts/prepare_build.sh
index 043f532cd69..c3f060e4a1e 100644
--- a/scripts/prepare_build.sh
+++ b/scripts/prepare_build.sh
@@ -66,5 +66,8 @@ sed -i 's/localhost/redis/g' config/redis.shared_state.yml
if [ "$SETUP_DB" != "false" ]; then
setup_db
elif getent hosts postgres || getent hosts mysql; then
+ # NOTE: Due to adding both of these entries to /etc/hosts, this will always
+ # run. Anything using a database should ensure it's actually accepting
+ # connections!
setup_db_user_only
fi