Bug 1318295 - Vagrant: Move mysql setup to shell provisioner

The MySQL service takes several seconds to restart, so we skip doing so
if the config file already exists with the expected content.

The privileges/database creation steps are idempotent and extremely
fast, so it's not worth the boilerplate of checking before running.
This commit is contained in:
Ed Morley 2017-03-15 17:14:32 +00:00
Родитель d403b08b59
Коммит 70fbac5db3
5 изменённых файлов: 21 добавлений и 41 удалений

Просмотреть файл

@ -77,7 +77,7 @@ matrix:
before_install:
- curl -sSo ~/elasticsearch.deb https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.3.5/elasticsearch-2.3.5.deb && sudo dpkg -i ~/elasticsearch.deb
- sudo service elasticsearch start
- sudo cp puppet/files/mysql/my.cnf /etc/mysql/conf.d/treeherder.cnf
- sudo cp vagrant/mysql.cnf /etc/mysql/conf.d/treeherder.cnf
- sudo service mysql restart
# Create a clean virtualenv rather than using the one given to us,
# to work around: https://github.com/travis-ci/travis-ci/issues/4873
@ -112,7 +112,7 @@ matrix:
before_install:
- curl -sSo ~/elasticsearch.deb https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.3.5/elasticsearch-2.3.5.deb && sudo dpkg -i ~/elasticsearch.deb
- sudo service elasticsearch start
- sudo cp puppet/files/mysql/my.cnf /etc/mysql/conf.d/treeherder.cnf
- sudo cp vagrant/mysql.cnf /etc/mysql/conf.d/treeherder.cnf
- sudo service mysql restart
# Create a clean virtualenv rather than using the one given to us,
# to work around: https://github.com/travis-ci/travis-ci/issues/4873
@ -141,7 +141,7 @@ matrix:
before_install:
- curl -sSo ~/elasticsearch.deb https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.3.5/elasticsearch-2.3.5.deb && sudo dpkg -i ~/elasticsearch.deb
- sudo service elasticsearch start
- sudo cp puppet/files/mysql/my.cnf /etc/mysql/conf.d/treeherder.cnf
- sudo cp vagrant/mysql.cnf /etc/mysql/conf.d/treeherder.cnf
- sudo service mysql restart
# Create a clean virtualenv rather than using the one given to us,
# to work around: https://github.com/travis-ci/travis-ci/issues/4873
@ -172,7 +172,7 @@ matrix:
before_install:
- curl -sSo ~/elasticsearch.deb https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.3.5/elasticsearch-2.3.5.deb && sudo dpkg -i ~/elasticsearch.deb
- sudo service elasticsearch start
- sudo cp puppet/files/mysql/my.cnf /etc/mysql/conf.d/treeherder.cnf
- sudo cp vagrant/mysql.cnf /etc/mysql/conf.d/treeherder.cnf
- sudo service mysql restart
# Create a clean virtualenv rather than using the one given to us,
# to work around: https://github.com/travis-ci/travis-ci/issues/4873

Просмотреть файл

@ -1,36 +0,0 @@
class mysql {
package { 'mysql-server-5.6':
ensure => installed
}
service { 'mysql':
ensure => running,
enable => true,
require => Package['mysql-server-5.6'],
}
# We cannot symlink since shared folders are world-writeable on
# Windows hosts, so MySQL server would reject the config file.
file{"/etc/mysql/conf.d/treeherder.cnf":
source => "${PROJ_DIR}/puppet/files/mysql/my.cnf",
owner => "root", group => "root", mode => 0644,
notify => Service['mysql'],
require => [
Package['mysql-server-5.6']
]
}
exec { "create-db":
unless => "mysql -uroot treeherder",
command => "mysql -uroot -e \"create database treeherder;\"",
require => Service['mysql'],
}
# The default `root@localhost` grant only allows loopback interface connections.
exec { "grant-db-privs":
unless => "mysql -uroot -e \"SHOW GRANTS FOR root@'%'\"",
command => "mysql -uroot -e \"GRANT ALL PRIVILEGES ON *.* to root@'%'\"",
require => Service['mysql']
}
}

Просмотреть файл

@ -18,7 +18,6 @@ file {"/etc/profile.d/treeherder.sh":
class vagrant {
class {
mysql: before => Class["elasticsearch"];
elasticsearch: before => Class["python"];
python: before => Class["nodejs"];
nodejs: before => Class["varnish"];

Просмотреть файл

Просмотреть файл

@ -4,9 +4,13 @@
# Make non-zero exit codes & other errors fatal.
set -euo pipefail
SRC_DIR="$HOME/treeherder"
# Suppress prompts during apt-get invocations.
export DEBIAN_FRONTEND=noninteractive
cd "$SRC_DIR"
if [[ ! -f /etc/apt/sources.list.d/fkrull-deadsnakes-python2_7-trusty.list ]]; then
echo '-----> Adding APT repository for Python 2.7'
sudo add-apt-repository -y ppa:fkrull/deadsnakes-python2.7 2>&1
@ -26,3 +30,16 @@ fi
echo '-----> Installing/updating APT packages'
sudo -E apt-get -yqq update
sudo -E apt-get -yqq install --no-install-recommends \
mysql-server-5.6 \
if ! cmp -s vagrant/mysql.cnf /etc/mysql/conf.d/treeherder.cnf; then
echo '-----> Configuring MySQL'
sudo cp vagrant/mysql.cnf /etc/mysql/conf.d/treeherder.cnf
sudo service mysql restart
fi
echo '-----> Initialising MySQL database'
# The default `root@localhost` grant only allows loopback interface connections.
mysql -u root -e 'GRANT ALL PRIVILEGES ON *.* to root@"%"'
mysql -u root -e 'CREATE DATABASE IF NOT EXISTS treeherder'