diff --git a/lib/databases/mysql b/lib/databases/mysql index 0ccfce5454..67bf85ac97 100644 --- a/lib/databases/mysql +++ b/lib/databases/mysql @@ -47,22 +47,22 @@ function recreate_database_mysql { } function configure_database_mysql { - local slow_log + local my_conf mysql slow_log echo_summary "Configuring and starting MySQL" if is_ubuntu; then - MY_CONF=/etc/mysql/my.cnf - MYSQL=mysql + my_conf=/etc/mysql/my.cnf + mysql=mysql elif is_fedora; then if [[ $DISTRO =~ (rhel7) ]]; then - MYSQL=mariadb + mysql=mariadb else - MYSQL=mysqld + mysql=mysqld fi - MY_CONF=/etc/my.cnf + my_conf=/etc/my.cnf elif is_suse; then - MY_CONF=/etc/my.cnf - MYSQL=mysql + my_conf=/etc/my.cnf + mysql=mysql else exit_distro_not_supported "mysql configuration" fi @@ -70,7 +70,7 @@ function configure_database_mysql { # Start mysql-server if is_fedora || is_suse; then # service is not started by default - start_service $MYSQL + start_service $mysql fi # 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 # set default db type to InnoDB sudo bash -c "source $TOP_DIR/functions && \ - iniset $MY_CONF mysqld bind-address 0.0.0.0 && \ - iniset $MY_CONF mysqld sql_mode STRICT_ALL_TABLES && \ - iniset $MY_CONF mysqld default-storage-engine InnoDB" + iniset $my_conf mysqld bind-address 0.0.0.0 && \ + iniset $my_conf mysqld sql_mode STRICT_ALL_TABLES && \ + iniset $my_conf mysqld default-storage-engine InnoDB" if [[ "$DATABASE_QUERY_LOGGING" == "True" ]]; then @@ -102,19 +102,19 @@ function configure_database_mysql { sudo sed -e '/log.slow.queries/d' \ -e '/long.query.time/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 # 0 seconds) and log all non-indexed queries sudo bash -c "source $TOP_DIR/functions && \ - iniset $MY_CONF mysqld slow-query-log 1 && \ - iniset $MY_CONF mysqld slow-query-log-file $slow_log && \ - iniset $MY_CONF mysqld long-query-time 0 && \ - iniset $MY_CONF mysqld log-queries-not-using-indexes 1" + iniset $my_conf mysqld slow-query-log 1 && \ + iniset $my_conf mysqld slow-query-log-file $slow_log && \ + iniset $my_conf mysqld long-query-time 0 && \ + iniset $my_conf mysqld log-queries-not-using-indexes 1" fi - restart_service $MYSQL + restart_service $mysql } function install_database_mysql { diff --git a/lib/databases/postgresql b/lib/databases/postgresql index 6e85d6ec77..fb6d304180 100644 --- a/lib/databases/postgresql +++ b/lib/databases/postgresql @@ -42,11 +42,12 @@ function recreate_database_postgresql { } function configure_database_postgresql { + local pg_conf pg_dir pg_hba root_roles echo_summary "Configuring and starting PostgreSQL" if is_fedora; then - PG_HBA=/var/lib/pgsql/data/pg_hba.conf - PG_CONF=/var/lib/pgsql/data/postgresql.conf - if ! sudo [ -e $PG_HBA ]; then + pg_hba=/var/lib/pgsql/data/pg_hba.conf + pg_conf=/var/lib/pgsql/data/postgresql.conf + if ! sudo [ -e $pg_hba ]; then if ! [[ $DISTRO =~ (rhel6) ]]; then sudo postgresql-setup initdb else @@ -54,25 +55,25 @@ function configure_database_postgresql { fi fi elif is_ubuntu; then - PG_DIR=`find /etc/postgresql -name pg_hba.conf|xargs dirname` - PG_HBA=$PG_DIR/pg_hba.conf - PG_CONF=$PG_DIR/postgresql.conf + pg_dir=`find /etc/postgresql -name pg_hba.conf|xargs dirname` + pg_hba=$pg_dir/pg_hba.conf + pg_conf=$pg_dir/postgresql.conf elif is_suse; then - PG_HBA=/var/lib/pgsql/data/pg_hba.conf - PG_CONF=/var/lib/pgsql/data/postgresql.conf + pg_hba=/var/lib/pgsql/data/pg_hba.conf + pg_conf=/var/lib/pgsql/data/postgresql.conf # initdb is called when postgresql is first started - sudo [ -e $PG_HBA ] || start_service postgresql + sudo [ -e $pg_hba ] || start_service postgresql else exit_distro_not_supported "postgresql configuration" fi # 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 - 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 - 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 - 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 # Create the role if it's not here or else alter it. @@ -86,14 +87,14 @@ function configure_database_postgresql { function install_database_postgresql { echo_summary "Installing postgresql" - PGPASS=$HOME/.pgpass - if [[ ! -e $PGPASS ]]; then - cat < $PGPASS + local pgpass=$HOME/.pgpass + if [[ ! -e $pgpass ]]; then + cat < $pgpass *:*:*:$DATABASE_USER:$DATABASE_PASSWORD EOF - chmod 0600 $PGPASS + chmod 0600 $pgpass else - sed -i "s/:root:\w\+/:root:$DATABASE_PASSWORD/" $PGPASS + sed -i "s/:root:\w\+/:root:$DATABASE_PASSWORD/" $pgpass fi if is_ubuntu; then install_package postgresql diff --git a/lib/rpc_backend b/lib/rpc_backend index a62d4e71a8..38da50c4f8 100644 --- a/lib/rpc_backend +++ b/lib/rpc_backend @@ -26,6 +26,8 @@ set +o xtrace # Make sure we only have one rpc backend enabled. # Also check the specified rpc backend is available on your platform. function check_rpc_backend { + local c svc + local rpc_needed=1 # We rely on the fact that filenames in lib/* match the service names # 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 # the fact that sometimes it fails to start properly. # Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1059028 + local i for i in `seq 10`; do if is_fedora || is_suse; then # service is not started by default