Combines cleanup for mysql, postgresql and rpc
Change-Id: I37b928a669146671c946fc1ccb8e3ef1a27a3891
| ... | ... |
@@ -47,22 +47,22 @@ function recreate_database_mysql {
|
| 47 | 47 |
} |
| 48 | 48 |
|
| 49 | 49 |
function configure_database_mysql {
|
| 50 |
- local slow_log |
|
| 50 |
+ local my_conf mysql slow_log |
|
| 51 | 51 |
echo_summary "Configuring and starting MySQL" |
| 52 | 52 |
|
| 53 | 53 |
if is_ubuntu; then |
| 54 |
- MY_CONF=/etc/mysql/my.cnf |
|
| 55 |
- MYSQL=mysql |
|
| 54 |
+ my_conf=/etc/mysql/my.cnf |
|
| 55 |
+ mysql=mysql |
|
| 56 | 56 |
elif is_fedora; then |
| 57 | 57 |
if [[ $DISTRO =~ (rhel7) ]]; then |
| 58 |
- MYSQL=mariadb |
|
| 58 |
+ mysql=mariadb |
|
| 59 | 59 |
else |
| 60 |
- MYSQL=mysqld |
|
| 60 |
+ mysql=mysqld |
|
| 61 | 61 |
fi |
| 62 |
- MY_CONF=/etc/my.cnf |
|
| 62 |
+ my_conf=/etc/my.cnf |
|
| 63 | 63 |
elif is_suse; then |
| 64 |
- MY_CONF=/etc/my.cnf |
|
| 65 |
- MYSQL=mysql |
|
| 64 |
+ my_conf=/etc/my.cnf |
|
| 65 |
+ mysql=mysql |
|
| 66 | 66 |
else |
| 67 | 67 |
exit_distro_not_supported "mysql configuration" |
| 68 | 68 |
fi |
| ... | ... |
@@ -70,7 +70,7 @@ function configure_database_mysql {
|
| 70 | 70 |
# Start mysql-server |
| 71 | 71 |
if is_fedora || is_suse; then |
| 72 | 72 |
# service is not started by default |
| 73 |
- start_service $MYSQL |
|
| 73 |
+ start_service $mysql |
|
| 74 | 74 |
fi |
| 75 | 75 |
|
| 76 | 76 |
# Set the root password - only works the first time. For Ubuntu, we already |
| ... | ... |
@@ -87,9 +87,9 @@ function configure_database_mysql {
|
| 87 | 87 |
# Change ‘bind-address’ from localhost (127.0.0.1) to any (0.0.0.0) and |
| 88 | 88 |
# set default db type to InnoDB |
| 89 | 89 |
sudo bash -c "source $TOP_DIR/functions && \ |
| 90 |
- iniset $MY_CONF mysqld bind-address 0.0.0.0 && \ |
|
| 91 |
- iniset $MY_CONF mysqld sql_mode STRICT_ALL_TABLES && \ |
|
| 92 |
- iniset $MY_CONF mysqld default-storage-engine InnoDB" |
|
| 90 |
+ iniset $my_conf mysqld bind-address 0.0.0.0 && \ |
|
| 91 |
+ iniset $my_conf mysqld sql_mode STRICT_ALL_TABLES && \ |
|
| 92 |
+ iniset $my_conf mysqld default-storage-engine InnoDB" |
|
| 93 | 93 |
|
| 94 | 94 |
|
| 95 | 95 |
if [[ "$DATABASE_QUERY_LOGGING" == "True" ]]; then |
| ... | ... |
@@ -102,19 +102,19 @@ function configure_database_mysql {
|
| 102 | 102 |
sudo sed -e '/log.slow.queries/d' \ |
| 103 | 103 |
-e '/long.query.time/d' \ |
| 104 | 104 |
-e '/log.queries.not.using.indexes/d' \ |
| 105 |
- -i $MY_CONF |
|
| 105 |
+ -i $my_conf |
|
| 106 | 106 |
|
| 107 | 107 |
# Turn on slow query log, log all queries (any query taking longer than |
| 108 | 108 |
# 0 seconds) and log all non-indexed queries |
| 109 | 109 |
sudo bash -c "source $TOP_DIR/functions && \ |
| 110 |
- iniset $MY_CONF mysqld slow-query-log 1 && \ |
|
| 111 |
- iniset $MY_CONF mysqld slow-query-log-file $slow_log && \ |
|
| 112 |
- iniset $MY_CONF mysqld long-query-time 0 && \ |
|
| 113 |
- iniset $MY_CONF mysqld log-queries-not-using-indexes 1" |
|
| 110 |
+ iniset $my_conf mysqld slow-query-log 1 && \ |
|
| 111 |
+ iniset $my_conf mysqld slow-query-log-file $slow_log && \ |
|
| 112 |
+ iniset $my_conf mysqld long-query-time 0 && \ |
|
| 113 |
+ iniset $my_conf mysqld log-queries-not-using-indexes 1" |
|
| 114 | 114 |
|
| 115 | 115 |
fi |
| 116 | 116 |
|
| 117 |
- restart_service $MYSQL |
|
| 117 |
+ restart_service $mysql |
|
| 118 | 118 |
} |
| 119 | 119 |
|
| 120 | 120 |
function install_database_mysql {
|
| ... | ... |
@@ -42,11 +42,12 @@ function recreate_database_postgresql {
|
| 42 | 42 |
} |
| 43 | 43 |
|
| 44 | 44 |
function configure_database_postgresql {
|
| 45 |
+ local pg_conf pg_dir pg_hba root_roles |
|
| 45 | 46 |
echo_summary "Configuring and starting PostgreSQL" |
| 46 | 47 |
if is_fedora; then |
| 47 |
- PG_HBA=/var/lib/pgsql/data/pg_hba.conf |
|
| 48 |
- PG_CONF=/var/lib/pgsql/data/postgresql.conf |
|
| 49 |
- if ! sudo [ -e $PG_HBA ]; then |
|
| 48 |
+ pg_hba=/var/lib/pgsql/data/pg_hba.conf |
|
| 49 |
+ pg_conf=/var/lib/pgsql/data/postgresql.conf |
|
| 50 |
+ if ! sudo [ -e $pg_hba ]; then |
|
| 50 | 51 |
if ! [[ $DISTRO =~ (rhel6) ]]; then |
| 51 | 52 |
sudo postgresql-setup initdb |
| 52 | 53 |
else |
| ... | ... |
@@ -54,25 +55,25 @@ function configure_database_postgresql {
|
| 54 | 54 |
fi |
| 55 | 55 |
fi |
| 56 | 56 |
elif is_ubuntu; then |
| 57 |
- PG_DIR=`find /etc/postgresql -name pg_hba.conf|xargs dirname` |
|
| 58 |
- PG_HBA=$PG_DIR/pg_hba.conf |
|
| 59 |
- PG_CONF=$PG_DIR/postgresql.conf |
|
| 57 |
+ pg_dir=`find /etc/postgresql -name pg_hba.conf|xargs dirname` |
|
| 58 |
+ pg_hba=$pg_dir/pg_hba.conf |
|
| 59 |
+ pg_conf=$pg_dir/postgresql.conf |
|
| 60 | 60 |
elif is_suse; then |
| 61 |
- PG_HBA=/var/lib/pgsql/data/pg_hba.conf |
|
| 62 |
- PG_CONF=/var/lib/pgsql/data/postgresql.conf |
|
| 61 |
+ pg_hba=/var/lib/pgsql/data/pg_hba.conf |
|
| 62 |
+ pg_conf=/var/lib/pgsql/data/postgresql.conf |
|
| 63 | 63 |
# initdb is called when postgresql is first started |
| 64 |
- sudo [ -e $PG_HBA ] || start_service postgresql |
|
| 64 |
+ sudo [ -e $pg_hba ] || start_service postgresql |
|
| 65 | 65 |
else |
| 66 | 66 |
exit_distro_not_supported "postgresql configuration" |
| 67 | 67 |
fi |
| 68 | 68 |
# Listen on all addresses |
| 69 |
- sudo sed -i "/listen_addresses/s/.*/listen_addresses = '*'/" $PG_CONF |
|
| 69 |
+ sudo sed -i "/listen_addresses/s/.*/listen_addresses = '*'/" $pg_conf |
|
| 70 | 70 |
# Set max_connections |
| 71 |
- sudo sed -i "/max_connections/s/.*/max_connections = $MAX_DB_CONNECTIONS/" $PG_CONF |
|
| 71 |
+ sudo sed -i "/max_connections/s/.*/max_connections = $MAX_DB_CONNECTIONS/" $pg_conf |
|
| 72 | 72 |
# Do password auth from all IPv4 clients |
| 73 |
- sudo sed -i "/^host/s/all\s\+127.0.0.1\/32\s\+ident/$DATABASE_USER\t0.0.0.0\/0\tpassword/" $PG_HBA |
|
| 73 |
+ sudo sed -i "/^host/s/all\s\+127.0.0.1\/32\s\+ident/$DATABASE_USER\t0.0.0.0\/0\tpassword/" $pg_hba |
|
| 74 | 74 |
# Do password auth for all IPv6 clients |
| 75 |
- sudo sed -i "/^host/s/all\s\+::1\/128\s\+ident/$DATABASE_USER\t::0\/0\tpassword/" $PG_HBA |
|
| 75 |
+ sudo sed -i "/^host/s/all\s\+::1\/128\s\+ident/$DATABASE_USER\t::0\/0\tpassword/" $pg_hba |
|
| 76 | 76 |
restart_service postgresql |
| 77 | 77 |
|
| 78 | 78 |
# Create the role if it's not here or else alter it. |
| ... | ... |
@@ -86,14 +87,14 @@ function configure_database_postgresql {
|
| 86 | 86 |
|
| 87 | 87 |
function install_database_postgresql {
|
| 88 | 88 |
echo_summary "Installing postgresql" |
| 89 |
- PGPASS=$HOME/.pgpass |
|
| 90 |
- if [[ ! -e $PGPASS ]]; then |
|
| 91 |
- cat <<EOF > $PGPASS |
|
| 89 |
+ local pgpass=$HOME/.pgpass |
|
| 90 |
+ if [[ ! -e $pgpass ]]; then |
|
| 91 |
+ cat <<EOF > $pgpass |
|
| 92 | 92 |
*:*:*:$DATABASE_USER:$DATABASE_PASSWORD |
| 93 | 93 |
EOF |
| 94 |
- chmod 0600 $PGPASS |
|
| 94 |
+ chmod 0600 $pgpass |
|
| 95 | 95 |
else |
| 96 |
- sed -i "s/:root:\w\+/:root:$DATABASE_PASSWORD/" $PGPASS |
|
| 96 |
+ sed -i "s/:root:\w\+/:root:$DATABASE_PASSWORD/" $pgpass |
|
| 97 | 97 |
fi |
| 98 | 98 |
if is_ubuntu; then |
| 99 | 99 |
install_package postgresql |
| ... | ... |
@@ -26,6 +26,8 @@ set +o xtrace |
| 26 | 26 |
# Make sure we only have one rpc backend enabled. |
| 27 | 27 |
# Also check the specified rpc backend is available on your platform. |
| 28 | 28 |
function check_rpc_backend {
|
| 29 |
+ local c svc |
|
| 30 |
+ |
|
| 29 | 31 |
local rpc_needed=1 |
| 30 | 32 |
# We rely on the fact that filenames in lib/* match the service names |
| 31 | 33 |
# that can be passed as arguments to is_service_enabled. |
| ... | ... |
@@ -138,6 +140,7 @@ function restart_rpc_backend {
|
| 138 | 138 |
# NOTE(bnemec): Retry initial rabbitmq configuration to deal with |
| 139 | 139 |
# the fact that sometimes it fails to start properly. |
| 140 | 140 |
# Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1059028 |
| 141 |
+ local i |
|
| 141 | 142 |
for i in `seq 10`; do |
| 142 | 143 |
if is_fedora || is_suse; then |
| 143 | 144 |
# service is not started by default |