<commit_before>#
# Cookbook Name:: mysql
# Recipe:: server
#
# Copyright 2008-2011, Opscode, Inc.
# Copyright 2015, <NAME> GmbH
#
# 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.
#

include_recipe 'mysql::deb'

# yes, for the CI environment, empty password is a good idea. VM is rolled back after eack run anyway.
node.set_unless['mysql']['server_debian_password'] = ""
node.set_unless['mysql']['server_root_password']   = ""
node.set_unless['mysql']['server_repl_password']   = ""

# Install prerequisites, including apparmor, which is installed here,
# only to satisfy the *.deb packages' requirements

package 'libaio1'
package 'apparmor'
package 'apparmor-utils'

if platform?(%w{debian ubuntu})

  directory "/var/cache/local/preseeding" do
    owner "root"
    group "root"
    mode 0755
    recursive true
  end

  execute "preseed mysql-server" do
    command "debconf-set-selections /var/cache/local/preseeding/mysql-server.seed"
    action :nothing
  end

  template "/var/cache/local/preseeding/mysql-server.seed" do
    source "mysql-server-deb.seed.erb"
    owner "root"
    group "root"
    mode "0600"
    notifies :run, resources(:execute => "preseed mysql-server"), :immediately
  end

  template "#{node['mysql']['conf_dir']}/debian.cnf" do
    source "debian.cnf.erb"
    owner "root"
    group "root"
    mode "0600"
  end
end

node.mysql.deb.server.packages.each do |pkg|
  package pkg
end

# Remove apparmor again, to put this recipe in line with 'mysql::server'
package "apparmor" do
  action :remove
  ignore_failure true
end

package "apparmor-utils" do
  action :remove
  ignore_failure true
end

service "mysql" do
  service_name value_for_platform([ "centos", "redhat", "suse", "fedora" ] => {"default" => "mysqld"}, "default" => "mysql")

  if (platform?("ubuntu") && node.platform_version.to_f >= 11.04)
    provider Chef::Provider::Service::Upstart
  end
  supports :status => true, :restart => true, :reload => true
  if node['mysql']['enabled']
    action :enable
  else
    action :disable
  end
end

template "#{node['mysql']['conf_dir']}/my.cnf" do
  source "my.cnf.erb"
  owner "root"
  group "root"
  mode "0644"
  notifies :restart, "service[mysql]", :immediately
end


# set the root password on platforms
# that don't support pre-seeding<commit_msg>Delay mysql-server installation until apparmor is removed<commit_after>#
# Cookbook Name:: mysql
# Recipe:: server
#
# Copyright 2008-2011, Opscode, Inc.
# Copyright 2015, Travis CI GmbH
#
# 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.
#

include_recipe 'mysql::deb'

# yes, for the CI environment, empty password is a good idea. VM is rolled back after eack run anyway.
node.set_unless['mysql']['server_debian_password'] = ""
node.set_unless['mysql']['server_root_password']   = ""
node.set_unless['mysql']['server_repl_password']   = ""

# Install prerequisites, including apparmor, which is installed here,
# only to satisfy the *.deb packages' requirements

package 'libaio1'

if platform?(%w{debian ubuntu})

  directory "/var/cache/local/preseeding" do
    owner "root"
    group "root"
    mode 0755
    recursive true
  end

  execute "preseed mysql-server" do
    command "debconf-set-selections /var/cache/local/preseeding/mysql-server.seed"
    action :nothing
  end

  template "/var/cache/local/preseeding/mysql-server.seed" do
    source "mysql-server-deb.seed.erb"
    owner "root"
    group "root"
    mode "0600"
    notifies :run, resources(:execute => "preseed mysql-server"), :immediately
  end

  template "#{node['mysql']['conf_dir']}/debian.cnf" do
    source "debian.cnf.erb"
    owner "root"
    group "root"
    mode "0600"
  end
end

# Remove apparmor again, to put this recipe in line with 'mysql::server'
package "apparmor" do
  action :remove
  ignore_failure true
end

package "apparmor-utils" do
  action :remove
  ignore_failure true
end

node.mysql.deb.server.packages.each do |pkg|
  package pkg
end

service "mysql" do
  service_name value_for_platform([ "centos", "redhat", "suse", "fedora" ] => {"default" => "mysqld"}, "default" => "mysql")

  if (platform?("ubuntu") && node.platform_version.to_f >= 11.04)
    provider Chef::Provider::Service::Upstart
  end
  supports :status => true, :restart => true, :reload => true
  if node['mysql']['enabled']
    action :enable
  else
    action :disable
  end
end

template "#{node['mysql']['conf_dir']}/my.cnf" do
  source "my.cnf.erb"
  owner "root"
  group "root"
  mode "0644"
  notifies :restart, "service[mysql]", :immediately
end


# set the root password on platforms
# that don't support pre-seeding
{'fraction_non_alphanumeric': 0.12022250134577427, 'fraction_numerical': 0.013278306118787008, 'mean_word_length': 4.151571164510166, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7648014', 'n_tokens_mistral': 1850, 'n_tokens_neox': 1733, 'n_words': 578}