Clean up local variable usage - Backends

Combines cleanup for mysql, postgresql and rpc

Change-Id: I37b928a669146671c946fc1ccb8e3ef1a27a3891
This commit is contained in:
Dean Troyer 2014-07-25 14:56:22 -05:00
parent d3121f649d
commit 3ef23bceec
3 changed files with 40 additions and 36 deletions

View File

@ -47,22 +47,22 @@ function recreate_database_mysql {
} }
function configure_database_mysql { function configure_database_mysql {
local slow_log local my_conf mysql slow_log
echo_summary "Configuring and starting MySQL" echo_summary "Configuring and starting MySQL"
if is_ubuntu; then if is_ubuntu; then
MY_CONF=/etc/mysql/my.cnf my_conf=/etc/mysql/my.cnf
MYSQL=mysql mysql=mysql
elif is_fedora; then elif is_fedora; then
if [[ $DISTRO =~ (rhel7) ]]; then if [[ $DISTRO =~ (rhel7) ]]; then
MYSQL=mariadb mysql=mariadb
else else
MYSQL=mysqld mysql=mysqld
fi fi
MY_CONF=/etc/my.cnf my_conf=/etc/my.cnf
elif is_suse; then elif is_suse; then
MY_CONF=/etc/my.cnf my_conf=/etc/my.cnf
MYSQL=mysql mysql=mysql
else else
exit_distro_not_supported "mysql configuration" exit_distro_not_supported "mysql configuration"
fi fi
@ -70,7 +70,7 @@ function configure_database_mysql {
# Start mysql-server # Start mysql-server
if is_fedora || is_suse; then if is_fedora || is_suse; then
# service is not started by default # service is not started by default
start_service $MYSQL start_service $mysql
fi fi
# Set the root password - only works the first time. For Ubuntu, we already # Set the root password - only works the first time. For Ubuntu, we already
@ -87,9 +87,9 @@ function configure_database_mysql {
# Change bind-address from localhost (127.0.0.1) to any (0.0.0.0) and # Change bind-address from localhost (127.0.0.1) to any (0.0.0.0) and
# set default db type to InnoDB # set default db type to InnoDB
sudo bash -c "source $TOP_DIR/functions && \ sudo bash -c "source $TOP_DIR/functions && \
iniset $MY_CONF mysqld bind-address 0.0.0.0 && \ iniset $my_conf mysqld bind-address 0.0.0.0 && \
iniset $MY_CONF mysqld sql_mode STRICT_ALL_TABLES && \ iniset $my_conf mysqld sql_mode STRICT_ALL_TABLES && \
iniset $MY_CONF mysqld default-storage-engine InnoDB" iniset $my_conf mysqld default-storage-engine InnoDB"
if [[ "$DATABASE_QUERY_LOGGING" == "True" ]]; then if [[ "$DATABASE_QUERY_LOGGING" == "True" ]]; then
@ -102,19 +102,19 @@ function configure_database_mysql {
sudo sed -e '/log.slow.queries/d' \ sudo sed -e '/log.slow.queries/d' \
-e '/long.query.time/d' \ -e '/long.query.time/d' \
-e '/log.queries.not.using.indexes/d' \ -e '/log.queries.not.using.indexes/d' \
-i $MY_CONF -i $my_conf
# Turn on slow query log, log all queries (any query taking longer than # Turn on slow query log, log all queries (any query taking longer than
# 0 seconds) and log all non-indexed queries # 0 seconds) and log all non-indexed queries
sudo bash -c "source $TOP_DIR/functions && \ sudo bash -c "source $TOP_DIR/functions && \
iniset $MY_CONF mysqld slow-query-log 1 && \ iniset $my_conf mysqld slow-query-log 1 && \
iniset $MY_CONF mysqld slow-query-log-file $slow_log && \ iniset $my_conf mysqld slow-query-log-file $slow_log && \
iniset $MY_CONF mysqld long-query-time 0 && \ iniset $my_conf mysqld long-query-time 0 && \
iniset $MY_CONF mysqld log-queries-not-using-indexes 1" iniset $my_conf mysqld log-queries-not-using-indexes 1"
fi fi
restart_service $MYSQL restart_service $mysql
} }
function install_database_mysql { function install_database_mysql {

View File

@ -42,11 +42,12 @@ function recreate_database_postgresql {
} }
function configure_database_postgresql { function configure_database_postgresql {
local pg_conf pg_dir pg_hba root_roles
echo_summary "Configuring and starting PostgreSQL" echo_summary "Configuring and starting PostgreSQL"
if is_fedora; then if is_fedora; then
PG_HBA=/var/lib/pgsql/data/pg_hba.conf pg_hba=/var/lib/pgsql/data/pg_hba.conf
PG_CONF=/var/lib/pgsql/data/postgresql.conf pg_conf=/var/lib/pgsql/data/postgresql.conf
if ! sudo [ -e $PG_HBA ]; then if ! sudo [ -e $pg_hba ]; then
if ! [[ $DISTRO =~ (rhel6) ]]; then if ! [[ $DISTRO =~ (rhel6) ]]; then
sudo postgresql-setup initdb sudo postgresql-setup initdb
else else
@ -54,25 +55,25 @@ function configure_database_postgresql {
fi fi
fi fi
elif is_ubuntu; then elif is_ubuntu; then
PG_DIR=`find /etc/postgresql -name pg_hba.conf|xargs dirname` pg_dir=`find /etc/postgresql -name pg_hba.conf|xargs dirname`
PG_HBA=$PG_DIR/pg_hba.conf pg_hba=$pg_dir/pg_hba.conf
PG_CONF=$PG_DIR/postgresql.conf pg_conf=$pg_dir/postgresql.conf
elif is_suse; then elif is_suse; then
PG_HBA=/var/lib/pgsql/data/pg_hba.conf pg_hba=/var/lib/pgsql/data/pg_hba.conf
PG_CONF=/var/lib/pgsql/data/postgresql.conf pg_conf=/var/lib/pgsql/data/postgresql.conf
# initdb is called when postgresql is first started # initdb is called when postgresql is first started
sudo [ -e $PG_HBA ] || start_service postgresql sudo [ -e $pg_hba ] || start_service postgresql
else else
exit_distro_not_supported "postgresql configuration" exit_distro_not_supported "postgresql configuration"
fi fi
# Listen on all addresses # Listen on all addresses
sudo sed -i "/listen_addresses/s/.*/listen_addresses = '*'/" $PG_CONF sudo sed -i "/listen_addresses/s/.*/listen_addresses = '*'/" $pg_conf
# Set max_connections # Set max_connections
sudo sed -i "/max_connections/s/.*/max_connections = $MAX_DB_CONNECTIONS/" $PG_CONF sudo sed -i "/max_connections/s/.*/max_connections = $MAX_DB_CONNECTIONS/" $pg_conf
# Do password auth from all IPv4 clients # Do password auth from all IPv4 clients
sudo sed -i "/^host/s/all\s\+127.0.0.1\/32\s\+ident/$DATABASE_USER\t0.0.0.0\/0\tpassword/" $PG_HBA sudo sed -i "/^host/s/all\s\+127.0.0.1\/32\s\+ident/$DATABASE_USER\t0.0.0.0\/0\tpassword/" $pg_hba
# Do password auth for all IPv6 clients # Do password auth for all IPv6 clients
sudo sed -i "/^host/s/all\s\+::1\/128\s\+ident/$DATABASE_USER\t::0\/0\tpassword/" $PG_HBA sudo sed -i "/^host/s/all\s\+::1\/128\s\+ident/$DATABASE_USER\t::0\/0\tpassword/" $pg_hba
restart_service postgresql restart_service postgresql
# Create the role if it's not here or else alter it. # Create the role if it's not here or else alter it.
@ -86,14 +87,14 @@ function configure_database_postgresql {
function install_database_postgresql { function install_database_postgresql {
echo_summary "Installing postgresql" echo_summary "Installing postgresql"
PGPASS=$HOME/.pgpass local pgpass=$HOME/.pgpass
if [[ ! -e $PGPASS ]]; then if [[ ! -e $pgpass ]]; then
cat <<EOF > $PGPASS cat <<EOF > $pgpass
*:*:*:$DATABASE_USER:$DATABASE_PASSWORD *:*:*:$DATABASE_USER:$DATABASE_PASSWORD
EOF EOF
chmod 0600 $PGPASS chmod 0600 $pgpass
else else
sed -i "s/:root:\w\+/:root:$DATABASE_PASSWORD/" $PGPASS sed -i "s/:root:\w\+/:root:$DATABASE_PASSWORD/" $pgpass
fi fi
if is_ubuntu; then if is_ubuntu; then
install_package postgresql install_package postgresql

View File

@ -26,6 +26,8 @@ set +o xtrace
# Make sure we only have one rpc backend enabled. # Make sure we only have one rpc backend enabled.
# Also check the specified rpc backend is available on your platform. # Also check the specified rpc backend is available on your platform.
function check_rpc_backend { function check_rpc_backend {
local c svc
local rpc_needed=1 local rpc_needed=1
# We rely on the fact that filenames in lib/* match the service names # We rely on the fact that filenames in lib/* match the service names
# that can be passed as arguments to is_service_enabled. # that can be passed as arguments to is_service_enabled.
@ -138,6 +140,7 @@ function restart_rpc_backend {
# NOTE(bnemec): Retry initial rabbitmq configuration to deal with # NOTE(bnemec): Retry initial rabbitmq configuration to deal with
# the fact that sometimes it fails to start properly. # the fact that sometimes it fails to start properly.
# Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1059028 # Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1059028
local i
for i in `seq 10`; do for i in `seq 10`; do
if is_fedora || is_suse; then if is_fedora || is_suse; then
# service is not started by default # service is not started by default