Skip to content

Commit

Permalink
Merge pull request #166 from fboismenu/fix_#163
Browse files Browse the repository at this point in the history
Fixes #163: Ensure configuration reload and server start after config
  • Loading branch information
shoekstra committed Oct 5, 2017
2 parents 31a2788 + 9055631 commit 75b2830
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 79 deletions.
12 changes: 6 additions & 6 deletions .kitchen.dokken.yml
Expand Up @@ -17,47 +17,47 @@ platforms:
platform: rhel
pid_one_command: /sbin/init
intermediate_instructions:
- RUN yum -y install which initscripts
- RUN yum -y install which initscripts sudo

- name: centos-7
driver:
image: centos:7
platform: rhel
pid_one_command: /usr/lib/systemd/systemd
intermediate_instructions:
- RUN yum -y install lsof which initscripts net-tools
- RUN yum -y install lsof which initscripts net-tools sudo

- name: debian-7
driver:
image: debian:7
pid_one_command: /sbin/init
intermediate_instructions:
- RUN /usr/bin/apt-get update
- RUN /usr/bin/apt-get install lsb-release net-tools -y
- RUN /usr/bin/apt-get install lsb-release net-tools sudo -y

- name: debian-8
driver:
image: debian:8
pid_one_command: /bin/systemd
intermediate_instructions:
- RUN /usr/bin/apt-get update
- RUN /usr/bin/apt-get install lsb-release net-tools -y
- RUN /usr/bin/apt-get install lsb-release net-tools sudo -y

- name: ubuntu-14.04
driver:
image: ubuntu-upstart:14.04
pid_one_command: /sbin/init
intermediate_instructions:
- RUN /usr/bin/apt-get update
- RUN /usr/bin/apt-get install net-tools -y
- RUN /usr/bin/apt-get install net-tools sudo -y

- name: ubuntu-16.04
driver:
image: ubuntu:16.04
pid_one_command: /bin/systemd
intermediate_instructions:
- RUN /usr/bin/apt-get update
- RUN /usr/bin/apt-get install net-tools -y
- RUN /usr/bin/apt-get install net-tools sudo -y

suites:
#
Expand Down
3 changes: 3 additions & 0 deletions .kitchen.yml
Expand Up @@ -12,6 +12,9 @@ platforms:
- name: centos-6.8
- name: centos-7.3
- name: debian-7.11
provisioner:
name: chef_zero
require_chef_omnibus: 12
- name: debian-8.7
- name: ubuntu-14.04
- name: ubuntu-16.04
Expand Down
18 changes: 18 additions & 0 deletions recipes/_debian_server_postinstall.rb
@@ -0,0 +1,18 @@
#
# Cookbook Name:: mariadb
# Recipe:: _debian_server_postinstall
#
# Copyright 2014, blablacar.com
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
@@ -1,6 +1,6 @@
#
# Cookbook Name:: mariadb
# Recipe:: _debian_server
# Recipe:: _debian_server_preinstall
#
# Copyright 2014, blablacar.com
#
Expand Down
58 changes: 58 additions & 0 deletions recipes/_mariadb_postinstall.rb
@@ -0,0 +1,58 @@
#
# Cookbook Name:: mariadb
# Recipe:: _server_postinstall
#
# Copyright 2014, blablacar.com
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

if node['mariadb']['allow_root_pass_change']
# Used to change root password after first install
# Still experimental
md5 = if node['mariadb']['server_root_password'].empty?
Digest::MD5.hexdigest('empty')
else
Digest::MD5.hexdigest(node['mariadb']['server_root_password'])
end

file '/etc/mysql_root_change' do
content md5
action :create
notifies :run, 'execute[install-grants]', :immediately
end
end

if node['mariadb']['allow_root_pass_change'] ||
node['mariadb']['remove_anonymous_users'] ||
node['mariadb']['forbid_remote_root'] ||
node['mariadb']['remove_test_database']

execute 'install-grants' do
command '/bin/bash -e /etc/mariadb_grants \'' + \
node['mariadb']['server_root_password'] + '\''
only_if { File.exist?('/etc/mariadb_grants') }
sensitive true
action :nothing
end

template '/etc/mariadb_grants' do
sensitive true
source 'mariadb_grants.erb'
owner 'root'
group 'root'
mode '0600'
helpers MariaDB::Helper
notifies :run, 'execute[install-grants]', :immediately
end
end
2 changes: 1 addition & 1 deletion recipes/_mariadb_repository.rb
@@ -1,6 +1,6 @@
#
# Cookbook Name:: mariadb
# Recipe:: _redhat_repository
# Recipe:: _mariadb_repository
#
# Copyright 2014, blablacar.com
#
Expand Down
25 changes: 25 additions & 0 deletions recipes/_redhat_server_postinstall.rb
@@ -0,0 +1,25 @@
#
# Cookbook Name:: mariadb
# Recipe:: _redhat_server_postinstall
#
# Copyright 2014, blablacar.com
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

execute 'change first install root password' do
command '/usr/bin/mysqladmin -u root password \'' + \
node['mariadb']['server_root_password'] + '\''
sensitive true
not_if { node['mariadb']['server_root_password'].empty? }
end
@@ -1,6 +1,6 @@
#
# Cookbook Name:: mariadb
# Recipe:: _redhat_server
# Recipe:: _redhat_server_preinstall
#
# Copyright 2014, blablacar.com
#
Expand Down Expand Up @@ -30,29 +30,3 @@
action :install
not_if { use_os_native || use_scl }
end

ruby_block 'MariaDB first start' do
block do
true
end
action :nothing
subscribes :run, 'package[MariaDB-server]', :immediately
notifies :create, 'directory[/var/log/mysql]', :immediately
notifies :start, 'service[mysql]', :immediately
notifies :run, 'execute[change first install root password]', :immediately
end

directory '/var/log/mysql' do
action :nothing
user 'mysql'
group 'mysql'
mode '0755'
end

execute 'change first install root password' do
command '/usr/bin/mysqladmin -u root password \'' + \
node['mariadb']['server_root_password'] + '\''
action :nothing
sensitive true
not_if { node['mariadb']['server_root_password'].empty? }
end
11 changes: 11 additions & 0 deletions recipes/config.rb
Expand Up @@ -17,6 +17,14 @@
# limitations under the License.
#

begin
resources('ruby_block[restart_mysql]')
no_mysql_restart_rc = false
rescue Chef::Exceptions::ResourceNotFound
no_mysql_restart_rc = true
# see Galera SST issue, justifying why we tolerate this.
end

template '/root/.my.cnf' do
source 'root.cnf.erb'
owner 'root'
Expand All @@ -30,6 +38,7 @@
owner 'root'
group 'root'
mode '0644'
notifies :create, 'ruby_block[restart_mysql]', :immediately unless no_mysql_restart_rc
end

directory '/etc/my.cnf.d/' do
Expand Down Expand Up @@ -85,6 +94,7 @@
section 'mysqld'
option innodb_options
action :add
notifies :create, 'ruby_block[restart_mysql]', :immediately unless no_mysql_restart_rc
end

replication_opts = {}
Expand Down Expand Up @@ -112,4 +122,5 @@
section 'mysqld'
option replication_opts
action :add
notifies :create, 'ruby_block[restart_mysql]', :immediately unless no_mysql_restart_rc
end

0 comments on commit 75b2830

Please sign in to comment.