Do not require every script that sources stackrc to also
source lib/databases.
* Move use_databases() to functions
* Set DATABASE_TYPE in stackrc
* Allow setting DATABASE_TYPE in localrc to work
(use_database() essentially just sets DATABASE_TYPE at this stage
so continuing to use it is equivalent)
* Validate DATABASE_TYPE in stack.sh.
* Change sudo to postgresql user to go through root to eliminate
password prompt
* fix use_database error condition
Change-Id: Ibb080c76e6cd7c6eebbb641a894d54b1dde78ca6
... | ... |
@@ -841,6 +841,22 @@ function upload_image() { |
841 | 841 |
fi |
842 | 842 |
} |
843 | 843 |
|
844 |
+# Set the database backend to use |
|
845 |
+# When called from stackrc/localrc DATABASE_BACKENDS has not been |
|
846 |
+# initialized yet, just save the configuration selection and call back later |
|
847 |
+# to validate it. |
|
848 |
+# $1 The name of the database backend to use (mysql, postgresql, ...) |
|
849 |
+function use_database { |
|
850 |
+ if [[ -z "$DATABASE_BACKENDS" ]]; then |
|
851 |
+ # The backends haven't initialized yet, just save the selection for now |
|
852 |
+ DATABASE_TYPE=$1 |
|
853 |
+ return |
|
854 |
+ fi |
|
855 |
+ use_exclusive_service DATABASE_BACKENDS DATABASE_TYPE $1 && return 0 |
|
856 |
+ ret=$? |
|
857 |
+ return $ret |
|
858 |
+} |
|
859 |
+ |
|
844 | 860 |
# Toggle enable/disable_service for services that must run exclusive of each other |
845 | 861 |
# $1 The name of a variable containing a space-separated list of services |
846 | 862 |
# $2 The name of a variable in which to store the enabled service's name |
... | ... |
@@ -62,15 +62,6 @@ function initialize_database_backends { |
62 | 62 |
return 0 |
63 | 63 |
} |
64 | 64 |
|
65 |
-# Set the database backend to use |
|
66 |
-# $1 The name of the database backend to use (mysql, postgresql, ...) |
|
67 |
-function use_database { |
|
68 |
- use_exclusive_service DATABASE_BACKENDS DATABASE_TYPE $1 && return 0 |
|
69 |
- ret=$? |
|
70 |
- echo "Invalid database '$1'" |
|
71 |
- return $ret |
|
72 |
-} |
|
73 |
- |
|
74 | 65 |
# Recreate a given database |
75 | 66 |
# $1 The name of the database |
76 | 67 |
# $2 The character set/encoding of the database |
... | ... |
@@ -38,8 +38,8 @@ function configure_database_postgresql { |
38 | 38 |
start_service postgresql |
39 | 39 |
|
40 | 40 |
# If creating the role fails, chances are it already existed. Try to alter it. |
41 |
- sudo -u postgres -i psql -c "CREATE ROLE $DATABASE_USER WITH SUPERUSER LOGIN PASSWORD '$DATABASE_PASSWORD'" || \ |
|
42 |
- sudo -u postgres -i psql -c "ALTER ROLE $DATABASE_USER WITH SUPERUSER LOGIN PASSWORD '$DATABASE_PASSWORD'" |
|
41 |
+ sudo -u root sudo -u postgres -i psql -c "CREATE ROLE $DATABASE_USER WITH SUPERUSER LOGIN PASSWORD '$DATABASE_PASSWORD'" || \ |
|
42 |
+ sudo -u root sudo -u postgres -i psql -c "ALTER ROLE $DATABASE_USER WITH SUPERUSER LOGIN PASSWORD '$DATABASE_PASSWORD'" |
|
43 | 43 |
} |
44 | 44 |
|
45 | 45 |
function install_database_postgresql { |
... | ... |
@@ -29,8 +29,6 @@ source $TOP_DIR/functions |
29 | 29 |
# and ``DISTRO`` |
30 | 30 |
GetDistro |
31 | 31 |
|
32 |
-# Import database library (must be loaded before stackrc which sources localrc) |
|
33 |
-source $TOP_DIR/lib/database |
|
34 | 32 |
|
35 | 33 |
|
36 | 34 |
# Settings |
... | ... |
@@ -92,6 +90,14 @@ DEST=${DEST:-/opt/stack} |
92 | 92 |
# Sanity Check |
93 | 93 |
# ============ |
94 | 94 |
|
95 |
+# Import database configuration |
|
96 |
+source $TOP_DIR/lib/database |
|
97 |
+ |
|
98 |
+# Validate database selection |
|
99 |
+# Since DATABASE_BACKENDS is now set, this also gets ENABLED_SERVICES |
|
100 |
+# properly configured for the database selection. |
|
101 |
+use_database $DATABASE_TYPE || echo "Invalid database '$DATABASE_TYPE'" |
|
102 |
+ |
|
95 | 103 |
# Remove services which were negated in ENABLED_SERVICES |
96 | 104 |
# using the "-" prefix (e.g., "-rabbit") instead of |
97 | 105 |
# calling disable_service(). |
... | ... |
@@ -6,12 +6,15 @@ RC_DIR=$(cd $(dirname "$BASH_SOURCE") && pwd) |
6 | 6 |
# Destination path for installation |
7 | 7 |
DEST=/opt/stack |
8 | 8 |
|
9 |
+# Select the default database |
|
10 |
+DATABASE_TYPE=mysql |
|
11 |
+ |
|
9 | 12 |
# Specify which services to launch. These generally correspond to |
10 | 13 |
# screen tabs. To change the default list, use the ``enable_service`` and |
11 | 14 |
# ``disable_service`` functions in ``localrc``. |
12 | 15 |
# For example, to enable Swift add this to ``localrc``: |
13 | 16 |
# enable_service swift |
14 |
-ENABLED_SERVICES=g-api,g-reg,key,n-api,n-crt,n-obj,n-cpu,n-net,cinder,c-sch,c-api,c-vol,n-sch,n-novnc,n-xvnc,n-cauth,horizon,mysql,rabbit |
|
17 |
+ENABLED_SERVICES=g-api,g-reg,key,n-api,n-crt,n-obj,n-cpu,n-net,cinder,c-sch,c-api,c-vol,n-sch,n-novnc,n-xvnc,n-cauth,horizon,rabbit,$DATABASE_TYPE |
|
15 | 18 |
|
16 | 19 |
# Set the default Nova APIs to enable |
17 | 20 |
NOVA_ENABLED_APIS=ec2,osapi_compute,metadata |