Update cookbooks and add wordpress cookbook

This commit is contained in:
Greg Karékinian
2016-02-19 18:09:49 +01:00
parent 9ba973e3ac
commit 820b0ab3f8
606 changed files with 22421 additions and 14084 deletions

View File

@@ -1,6 +1,57 @@
mysql Cookbook CHANGELOG
========================
v6.1.2 (2015-10-05)
--------------------
- Amazon Linux 2015.09
v6.1.1 (2015-09-24)
--------------------
- Completing ChefSpec matchers
v6.1.0 (2015-07-17)
--------------------
- Adding tunables for tmp_dir, error_log, and pid_file
- Adding mysqld_options hash interface for main my.cnf template
v6.0.31 (2015-07-13)
--------------------
- Reverting create_stop_system_service checks
v6.0.30 (2015-07-13)
--------------------
- Ubuntu 15.04 support
- Check for scripts and unit files during create_stop_system_service
v6.0.29 (2015-07-12)
--------------------
- Patch to allow blank root password
- Adding package information for Suse 12.0
v6.0.28 (2015-07-10)
--------------------
- Fixes for 12.4.x
v6.0.27 (2015-07-09)
--------------------
- Allowing integer value for port number
v6.0.26 (2015-07-07)
--------------------
- Reverting breaking changes introduced in 6.0.25
v6.0.25 (2015-07-06)
--------------------
- Fixes for 12.4.1
v6.0.24 (2015-06-27)
--------------------
- #341 - Changing default GRANT for root from '%' to 'localhost' and '127.0.0.1'
v6.0.23 (2015-06-21)
--------------------
- #354 Better handling of long MySQL startup times
v6.0.22 (2015-05-07)
--------------------
- Debian 8 (Jessie) support

View File

@@ -37,6 +37,8 @@ The following platforms have been tested with Test Kitchen:
|----------------+-----+-----+-----+-----+-----|
| ubuntu-14.04 | | | X | X | |
|----------------+-----+-----+-----+-----+-----|
| ubuntu-15.04 | | | | X | |
|----------------+-----+-----+-----+-----+-----|
| centos-5 | X | X | X | X | X |
|----------------+-----+-----+-----+-----+-----|
| centos-6 | | X | X | X | X |
@@ -85,7 +87,7 @@ The configuration file is at `/etc/mysql-foo/my.cnf`. It contains the
minimum options to get the service running. It looks like this.
```
# Chef generated my.cnf for instance mysql-default
# Chef generated my.cnf for instance mysql-foo
[client]
default-character-set = utf8
@@ -195,6 +197,8 @@ to reference is `mysql_service[name]`, not `service[mysql]`.
on the machine. This is useful when mounting external storage. When
omitted, it will default to the platform's native location.
- `error_log` - Tunable location of the error_log
- `initial_root_password` - allows the user to specify the initial
root password for mysql when initializing new databases.
This can be set explicitly in a recipe, driven from a node
@@ -219,6 +223,14 @@ omitted, it will default to the platform's native location.
that particular address. If the address is "0.0.0.0" (IPv4) or "::" (IPv6), the
server accepts TCP/IP connections on all IPv4 or IPv6 interfaces.
- `mysqld_options` - A key value hash of options to be rendered into
the main my.cnf. WARNING - It is highly recommended that you use the
`mysql_config` resource instead of sending extra config into a
`mysql_service` resource. This will allow you to set up
notifications and subscriptions between the service and its
configuration. That being said, this can be useful for adding extra
options needed for database initialization at first run.
- `port` - determines the listen port for the mysqld service. When
omitted, it will default to '3306'.
@@ -228,11 +240,15 @@ omitted, it will default to the platform's native location.
- `run_user` - The name of the system user the `mysql_service` should
run as. Defaults to 'mysql'.
- `pid_file` - Tunable location of the pid file.
- `socket` - determines where to write the socket file for the
`mysql_service` instance. Useful when configuring clients on the
same machine to talk over socket and skip the networking stack.
Defaults to a calculated value based on platform and instance name.
- `tmp_dir` - Tunable location of the tmp_dir
- `version` - allows the user to select from the versions available
for the platform, where applicable. When omitted, it will install
the default MySQL version for the target platform. Available version
@@ -255,28 +271,28 @@ but you can specify one if your platform support it.
mysql_service[instance-1] do
port '1234'
data_dir '/mnt/lottadisk'
provider Chef::Provider::MysqlService::Sysvinit
provider Chef::Provider::MysqlServiceSysvinit
action [:create, :start]
end
```
- `Chef::Provider::MysqlService` - Configures everything needed t run
- `Chef::Provider::MysqlServiceBase` - Configures everything needed t run
a MySQL service except the platform service facility. This provider
should never be used directly. The `:start`, `:stop`, `:restart`, and
`:reload` actions are stubs meant to be overridden by the providers
below.
- `Chef::Provider::MysqlService::Smf` - Starts a `mysql_service` using
- `Chef::Provider::MysqlServiceSmf` - Starts a `mysql_service` using
the Service Management Facility, used by Solaris and IllumOS. Manages
the FMRI and method script.
- `Chef::Provider::MysqlService::Systemd` - Starts a `mysql_service`
- `Chef::Provider::MysqlServiceSystemd` - Starts a `mysql_service`
using SystemD. Manages the unit file and activation state
- `Chef::Provider::MysqlService::Sysvinit` - Starts a `mysql_service`
- `Chef::Provider::MysqlServiceSysvinit` - Starts a `mysql_service`
using SysVinit. Manages the init script and status.
- `Chef::Provider::MysqlService::Upstart` - Starts a `mysql_service`
- `Chef::Provider::MysqlServiceUpstart` - Starts a `mysql_service`
using Upstart. Manages job definitions and status.
### mysql_config
@@ -503,7 +519,7 @@ overlap among multiple MySQL configurations.
To connect to the socket from the command line, check the socket in the relevant my.cnf file and use something like this:
`mysql -S /var/run/mysql-default/mysqld.sock -Pwhatever`
`mysql -S /var/run/mysql-foo/mysqld.sock -Pwhatever`
Or to connect over the network, use something like this:
connect over the network..

View File

@@ -34,6 +34,7 @@ module MysqlCookbook
end
def error_log
return new_resource.error_log if new_resource.error_log
"#{log_dir}/error.log"
end
@@ -60,7 +61,7 @@ module MysqlCookbook
end
def pkg_ver_string
parsed_version.gsub('.', '') if node['platform_family'] == 'omnios'
parsed_version.delete('.') if node['platform_family'] == 'omnios'
end
def prefix_dir
@@ -105,6 +106,24 @@ module MysqlCookbook
true
end
def password_column_name
return 'authentication_string' if v57plus
'password'
end
def password_expired
return ", password_expired='N'" if v57plus
''
end
def root_password
if new_resource.initial_root_password == ''
Chef::Log.info('Root password is empty')
return ''
end
Shellwords.escape(new_resource.initial_root_password)
end
# database and initial records
# initialization commands
@@ -148,10 +167,11 @@ module MysqlCookbook
mkdir /tmp/#{mysql_name}
cat > /tmp/#{mysql_name}/my.sql <<-EOSQL
DELETE FROM mysql.user ;
CREATE USER 'root'@'%' IDENTIFIED BY '#{Shellwords.escape(new_resource.initial_root_password)}' ;
GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION ;
UPDATE mysql.user SET #{password_column_name}=PASSWORD('#{root_password}')#{password_expired} WHERE user = 'root';
DELETE FROM mysql.user WHERE USER LIKE '';
DELETE FROM mysql.user WHERE user = 'root' and host NOT IN ('127.0.0.1', 'localhost');
FLUSH PRIVILEGES;
DELETE FROM mysql.db WHERE db LIKE 'test%';
DROP DATABASE IF EXISTS test ;
EOSQL
@@ -204,6 +224,7 @@ EOSQL
end
def pid_file
return new_resource.pid_file if new_resource.pid_file
"#{run_dir}/mysqld.pid"
end
@@ -228,6 +249,7 @@ EOSQL
end
def tmp_dir
return new_resource.tmp_dir if new_resource.tmp_dir
'/tmp'
end
@@ -256,6 +278,8 @@ EOSQL
@pkginfo.set['debian']['14.10']['5.5']['server_package'] = 'mysql-server-5.5'
@pkginfo.set['debian']['14.10']['5.6']['client_package'] = %w(mysql-client-5.6 libmysqlclient-dev)
@pkginfo.set['debian']['14.10']['5.6']['server_package'] = 'mysql-server-5.6'
@pkginfo.set['debian']['15.04']['5.6']['client_package'] = %w(mysql-client-5.6 libmysqlclient-dev)
@pkginfo.set['debian']['15.04']['5.6']['server_package'] = 'mysql-server-5.6'
@pkginfo.set['debian']['6']['5.1']['client_package'] = %w(mysql-client libmysqlclient-dev)
@pkginfo.set['debian']['6']['5.1']['server_package'] = 'mysql-server-5.1'
@pkginfo.set['debian']['7']['5.5']['client_package'] = %w(mysql-client libmysqlclient-dev)
@@ -272,6 +296,14 @@ EOSQL
@pkginfo.set['fedora']['20']['5.6']['server_package'] = 'mysql-community-server'
@pkginfo.set['fedora']['20']['5.7']['client_package'] = %w(mysql-community-client mysql-community-devel)
@pkginfo.set['fedora']['20']['5.7']['server_package'] = 'mysql-community-server'
@pkginfo.set['fedora']['21']['5.6']['client_package'] = %w(mysql-community-client mysql-community-devel)
@pkginfo.set['fedora']['21']['5.6']['server_package'] = 'mysql-community-server'
@pkginfo.set['fedora']['21']['5.7']['client_package'] = %w(mysql-community-client mysql-community-devel)
@pkginfo.set['fedora']['21']['5.7']['server_package'] = 'mysql-community-server'
@pkginfo.set['fedora']['22']['5.6']['client_package'] = %w(mysql-community-client mysql-community-devel)
@pkginfo.set['fedora']['22']['5.6']['server_package'] = 'mysql-community-server'
@pkginfo.set['fedora']['22']['5.7']['client_package'] = %w(mysql-community-client mysql-community-devel)
@pkginfo.set['fedora']['22']['5.7']['server_package'] = 'mysql-community-server'
@pkginfo.set['freebsd']['10']['5.5']['client_package'] = %w(mysql55-client)
@pkginfo.set['freebsd']['10']['5.5']['server_package'] = 'mysql55-server'
@pkginfo.set['freebsd']['9']['5.5']['client_package'] = %w(mysql55-client)
@@ -296,6 +328,14 @@ EOSQL
@pkginfo.set['rhel']['2015.03']['5.6']['server_package'] = 'mysql-community-server'
@pkginfo.set['rhel']['2015.03']['5.7']['client_package'] = %w(mysql-community-client mysql-community-devel)
@pkginfo.set['rhel']['2015.03']['5.7']['server_package'] = 'mysql-community-server'
@pkginfo.set['rhel']['2015.09']['5.1']['server_package'] = %w(mysql51 mysql51-devel)
@pkginfo.set['rhel']['2015.09']['5.1']['server_package'] = 'mysql51-server'
@pkginfo.set['rhel']['2015.09']['5.5']['client_package'] = %w(mysql-community-client mysql-community-devel)
@pkginfo.set['rhel']['2015.09']['5.5']['server_package'] = 'mysql-community-server'
@pkginfo.set['rhel']['2015.09']['5.6']['client_package'] = %w(mysql-community-client mysql-community-devel)
@pkginfo.set['rhel']['2015.09']['5.6']['server_package'] = 'mysql-community-server'
@pkginfo.set['rhel']['2015.09']['5.7']['client_package'] = %w(mysql-community-client mysql-community-devel)
@pkginfo.set['rhel']['2015.09']['5.7']['server_package'] = 'mysql-community-server'
@pkginfo.set['rhel']['5']['5.0']['client_package'] = %w(mysql mysql-devel)
@pkginfo.set['rhel']['5']['5.0']['server_package'] = 'mysql-server'
@pkginfo.set['rhel']['5']['5.1']['client_package'] = %w(mysql51-mysql)
@@ -326,6 +366,8 @@ EOSQL
@pkginfo.set['smartos']['5.11']['5.6']['server_package'] = 'mysql-server'
@pkginfo.set['suse']['11.3']['5.5']['client_package'] = %w(mysql-client)
@pkginfo.set['suse']['11.3']['5.5']['server_package'] = 'mysql'
@pkginfo.set['suse']['12.0']['5.5']['client_package'] = %w(mysql-client)
@pkginfo.set['suse']['12.0']['5.5']['server_package'] = 'mysql'
@pkginfo
end
@@ -372,7 +414,7 @@ EOSQL
node['platform_version'],
parsed_version,
:client_package
)
)
end
def server_package
@@ -382,7 +424,7 @@ EOSQL
node['platform_version'],
parsed_version,
:server_package
)
)
end
def server_package_name
@@ -403,7 +445,6 @@ EOSQL
return '5.5' if node['platform_family'] == 'debian' && node['platform_version'] == '14.10'
return '5.5' if node['platform_family'] == 'debian' && node['platform_version'].to_i == 7
return '5.5' if node['platform_family'] == 'debian' && node['platform_version'].to_i == 8
return '5.5' if node['platform_family'] == 'fedora'
return '5.5' if node['platform_family'] == 'freebsd'
return '5.5' if node['platform_family'] == 'omnios'
return '5.5' if node['platform_family'] == 'rhel' && node['platform_version'].to_i == 2014
@@ -411,6 +452,8 @@ EOSQL
return '5.5' if node['platform_family'] == 'rhel' && node['platform_version'].to_i == 7
return '5.5' if node['platform_family'] == 'smartos'
return '5.5' if node['platform_family'] == 'suse'
return '5.6' if node['platform_family'] == 'fedora'
return '5.6' if node['platform_family'] == 'debian' && node['platform_version'] == '15.04'
end
end
end

View File

@@ -1,4 +1,17 @@
if defined?(ChefSpec)
if ChefSpec.respond_to?(:define_matcher)
# ChefSpec >= 4.1
ChefSpec.define_matcher :mysql_config
ChefSpec.define_matcher :mysql_service
ChefSpec.define_matcher :mysql_client
elsif defined?(ChefSpec::Runner) &&
ChefSpec::Runner.respond_to?(:define_runner_method)
# ChefSpec < 4.1
ChefSpec::Runner.define_runner_method :mysql_config
ChefSpec::Runner.define_runner_method :mysql_service
ChefSpec::Runner.define_runner_method :mysql_client
end
# config
def create_mysql_config(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:mysql_config, :create, resource_name)
@@ -17,6 +30,22 @@ if defined?(ChefSpec)
ChefSpec::Matchers::ResourceMatcher.new(:mysql_service, :delete, resource_name)
end
def start_mysql_service(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:mysql_service, :start, resource_name)
end
def stop_mysql_service(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:mysql_service, :stop, resource_name)
end
def restart_mysql_service(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:mysql_service, :restart, resource_name)
end
def reload_mysql_service(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:mysql_service, :reload, resource_name)
end
# client
def create_mysql_client(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:mysql_client, :create, resource_name)

View File

@@ -5,6 +5,7 @@ class Chef
class Provider
class MysqlClient < Chef::Provider::LWRPBase
include MysqlCookbook::Helpers
provides :mysql_client if defined?(provides)
use_inline_resources if defined?(use_inline_resources)

View File

@@ -5,6 +5,7 @@ class Chef
class Provider
class MysqlConfig < Chef::Provider::LWRPBase
include MysqlCookbook::Helpers
provides :mysql_config if defined?(provides)
use_inline_resources if defined?(use_inline_resources)

View File

@@ -3,8 +3,7 @@ require_relative 'helpers'
class Chef
class Provider
class MysqlService < Chef::Provider::LWRPBase
# Chef 11 LWRP DSL Methods
class MysqlServiceBase < Chef::Provider::LWRPBase
use_inline_resources if defined?(use_inline_resources)
def whyrun_supported?
@@ -138,7 +137,7 @@ class Chef
socket_file: socket_file,
tmp_dir: tmp_dir,
data_dir: parsed_data_dir
)
)
action :create
end
@@ -234,7 +233,7 @@ class Chef
run_dir: run_dir,
pid_file: pid_file,
socket_file: socket_file
)
)
action :create
notifies :restart, "service[#{new_resource.name} :create apparmor]", :immediately
end

View File

@@ -1,83 +1,89 @@
class Chef
class Provider
class MysqlService
class Smf < Chef::Provider::MysqlService
action :start do
method_script_path = "/lib/svc/method/#{mysql_name}" if node['platform'] == 'omnios'
method_script_path = "/opt/local/lib/svc/method/#{mysql_name}" if node['platform'] == 'smartos'
class MysqlServiceSmf < Chef::Provider::MysqlServiceBase
# FIXME: we should have a service_helper to determine if the platform supports SMF similarly
# to how we handle systemd on linux
if defined?(provides)
provides :mysql_service, os: %w(solaris2 omnios smartos openindiana opensolaris nexentacore) do
File.exist?('/usr/sbin/svccfg')
end
end
template "#{new_resource.name} :start #{method_script_path}" do
path method_script_path
cookbook 'mysql'
source 'smf/svc.method.mysqld.erb'
owner 'root'
group 'root'
mode '0555'
variables(
base_dir: base_dir,
data_dir: parsed_data_dir,
defaults_file: defaults_file,
error_log: error_log,
mysql_name: mysql_name,
mysqld_bin: mysqld_bin,
pid_file: pid_file
)
action :create
end
action :start do
method_script_path = "/lib/svc/method/#{mysql_name}" if node['platform'] == 'omnios'
method_script_path = "/opt/local/lib/svc/method/#{mysql_name}" if node['platform'] == 'smartos'
smf "#{new_resource.name} :start #{mysql_name}" do
name mysql_name
user new_resource.run_user
group new_resource.run_group
start_command "#{method_script_path} start"
end
service "#{new_resource.name} :start #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Solaris
supports restart: true
action [:enable]
end
template "#{new_resource.name} :start #{method_script_path}" do
path method_script_path
cookbook 'mysql'
source 'smf/svc.method.mysqld.erb'
owner 'root'
group 'root'
mode '0555'
variables(
base_dir: base_dir,
data_dir: parsed_data_dir,
defaults_file: defaults_file,
error_log: error_log,
mysql_name: mysql_name,
mysqld_bin: mysqld_bin,
pid_file: pid_file
)
action :create
end
action :stop do
service "#{new_resource.name} :stop #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Solaris
supports restart: true
action :stop
end
smf "#{new_resource.name} :start #{mysql_name}" do
name mysql_name
user new_resource.run_user
group new_resource.run_group
start_command "#{method_script_path} start"
end
action :restart do
service "#{new_resource.name} :restart #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Solaris
supports restart: true
action :restart
end
service "#{new_resource.name} :start #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Solaris
supports restart: true
action [:enable]
end
end
action :reload do
service "#{new_resource.name} :reload #{mysql_name}" do
provider Chef::Provider::Service::Solaris
service_name mysql_name
supports reload: true
action :reload
end
action :stop do
service "#{new_resource.name} :stop #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Solaris
supports restart: true
action :stop
end
end
def create_stop_system_service
# nothing to do here
action :restart do
service "#{new_resource.name} :restart #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Solaris
supports restart: true
action :restart
end
end
def delete_stop_service
service "#{new_resource.name} :delete #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Solaris
supports restart: true
action :stop
end
action :reload do
service "#{new_resource.name} :reload #{mysql_name}" do
provider Chef::Provider::Service::Solaris
service_name mysql_name
supports reload: true
action :reload
end
end
def create_stop_system_service
# nothing to do here
end
def delete_stop_service
service "#{new_resource.name} :delete #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Solaris
supports restart: true
action :stop
end
end
end

View File

@@ -1,119 +1,133 @@
require_relative 'provider_mysql_service_base'
class Chef
class Provider
class MysqlService
class Systemd < Chef::Provider::MysqlService
action :start do
# this script is called by the main systemd unit file, and
# spins around until the service is actually up and running.
template "#{new_resource.name} :start /usr/libexec/#{mysql_name}-wait-ready" do
path "/usr/libexec/#{mysql_name}-wait-ready"
source 'systemd/mysqld-wait-ready.erb'
owner 'root'
group 'root'
mode '0755'
variables(socket_file: socket_file)
cookbook 'mysql'
action :create
end
class MysqlServiceSystemd < Chef::Provider::MysqlServiceBase
if defined?(provides)
provides :mysql_service, os: 'linux' do
Chef::Platform::ServiceHelpers.service_resource_providers.include?(:systemd)
end
end
# this is the main systemd unit file
template "#{new_resource.name} :start /usr/lib/systemd/system/#{mysql_name}.service" do
path "/usr/lib/systemd/system/#{mysql_name}.service"
source 'systemd/mysqld.service.erb'
owner 'root'
group 'root'
mode '0644'
variables(
config: new_resource,
etc_dir: etc_dir,
base_dir: base_dir,
mysqld_bin: mysqld_bin
)
cookbook 'mysql'
notifies :run, "execute[#{new_resource.name} :start systemctl daemon-reload]", :immediately
action :create
end
# avoid 'Unit file changed on disk' warning
execute "#{new_resource.name} :start systemctl daemon-reload" do
command '/usr/bin/systemctl daemon-reload'
action :nothing
end
# tmpfiles.d config so the service survives reboot
template "#{new_resource.name} :start /usr/lib/tmpfiles.d/#{mysql_name}.conf" do
path "/usr/lib/tmpfiles.d/#{mysql_name}.conf"
source 'tmpfiles.d.conf.erb'
owner 'root'
group 'root'
mode '0644'
variables(
run_dir: run_dir,
run_user: new_resource.run_user,
run_group: new_resource.run_group
)
cookbook 'mysql'
action :create
end
# service management resource
service "#{new_resource.name} :start #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Systemd
supports restart: true, status: true
action [:enable, :start]
end
action :start do
# Needed for Debian / Ubuntu
directory '/usr/libexec' do
owner 'root'
group 'root'
mode '0755'
action :create
end
action :stop do
# service management resource
service "#{new_resource.name} :stop #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Systemd
supports status: true
action [:disable, :stop]
only_if { ::File.exist?("/usr/lib/systemd/system/#{mysql_name}.service") }
end
# this script is called by the main systemd unit file, and
# spins around until the service is actually up and running.
template "#{new_resource.name} :start /usr/libexec/#{mysql_name}-wait-ready" do
path "/usr/libexec/#{mysql_name}-wait-ready"
source 'systemd/mysqld-wait-ready.erb'
owner 'root'
group 'root'
mode '0755'
variables(socket_file: socket_file)
cookbook 'mysql'
action :create
end
action :restart do
# service management resource
service "#{new_resource.name} :restart #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Systemd
supports restart: true
action :restart
end
# this is the main systemd unit file
template "#{new_resource.name} :start /lib/systemd/system/#{mysql_name}.service" do
path "/lib/systemd/system/#{mysql_name}.service"
source 'systemd/mysqld.service.erb'
owner 'root'
group 'root'
mode '0644'
variables(
config: new_resource,
etc_dir: etc_dir,
base_dir: base_dir,
mysqld_bin: mysqld_bin
)
cookbook 'mysql'
notifies :run, "execute[#{new_resource.name} :start systemctl daemon-reload]", :immediately
action :create
end
action :reload do
# service management resource
service "#{new_resource.name} :reload #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Systemd
action :reload
end
# avoid 'Unit file changed on disk' warning
execute "#{new_resource.name} :start systemctl daemon-reload" do
command '/bin/systemctl daemon-reload'
action :nothing
end
def create_stop_system_service
# service management resource
service "#{new_resource.name} :create mysql" do
service_name 'mysqld'
provider Chef::Provider::Service::Systemd
supports status: true
action [:stop, :disable]
end
# tmpfiles.d config so the service survives reboot
template "#{new_resource.name} :start /usr/lib/tmpfiles.d/#{mysql_name}.conf" do
path "/usr/lib/tmpfiles.d/#{mysql_name}.conf"
source 'tmpfiles.d.conf.erb'
owner 'root'
group 'root'
mode '0644'
variables(
run_dir: run_dir,
run_user: new_resource.run_user,
run_group: new_resource.run_group
)
cookbook 'mysql'
action :create
end
def delete_stop_service
# service management resource
service "#{new_resource.name} :delete #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Systemd
supports status: true
action [:disable, :stop]
only_if { ::File.exist?("/usr/lib/systemd/system/#{mysql_name}.service") }
end
# service management resource
service "#{new_resource.name} :start #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Systemd
supports restart: true, status: true
action [:enable, :start]
end
end
action :stop do
# service management resource
service "#{new_resource.name} :stop #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Systemd
supports status: true
action [:disable, :stop]
only_if { ::File.exist?("/usr/lib/systemd/system/#{mysql_name}.service") }
end
end
action :restart do
# service management resource
service "#{new_resource.name} :restart #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Systemd
supports restart: true
action :restart
end
end
action :reload do
# service management resource
service "#{new_resource.name} :reload #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Systemd
action :reload
end
end
def create_stop_system_service
# service management resource
service "#{new_resource.name} :create mysql" do
service_name system_service_name
provider Chef::Provider::Service::Systemd
supports status: true
action [:stop, :disable]
end
end
def delete_stop_service
# service management resource
service "#{new_resource.name} :delete #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Systemd
supports status: true
action [:disable, :stop]
only_if { ::File.exist?("/usr/lib/systemd/system/#{mysql_name}.service") }
end
end
end

View File

@@ -1,85 +1,87 @@
require_relative 'provider_mysql_service_base'
class Chef
class Provider
class MysqlService
class Sysvinit < Chef::Provider::MysqlService
action :start do
template "#{new_resource.name} :start /etc/init.d/#{mysql_name}" do
path "/etc/init.d/#{mysql_name}"
source 'sysvinit/mysqld.erb'
owner 'root'
group 'root'
mode '0755'
variables(
config: new_resource,
defaults_file: defaults_file,
error_log: error_log,
mysql_name: mysql_name,
mysqladmin_bin: mysqladmin_bin,
mysqld_safe_bin: mysqld_safe_bin,
pid_file: pid_file,
scl_name: scl_name
)
cookbook 'mysql'
action :create
end
class MysqlServiceSysvinit < Chef::Provider::MysqlServiceBase
provides :mysql_service, os: '!windows' if defined?(provides)
service "#{new_resource.name} :start #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Init::Redhat if node['platform_family'] == 'redhat'
provider Chef::Provider::Service::Init::Insserv if node['platform_family'] == 'debian'
supports restart: true, status: true
action [:enable, :start]
end
action :start do
template "#{new_resource.name} :start /etc/init.d/#{mysql_name}" do
path "/etc/init.d/#{mysql_name}"
source 'sysvinit/mysqld.erb'
owner 'root'
group 'root'
mode '0755'
variables(
config: new_resource,
defaults_file: defaults_file,
error_log: error_log,
mysql_name: mysql_name,
mysqladmin_bin: mysqladmin_bin,
mysqld_safe_bin: mysqld_safe_bin,
pid_file: pid_file,
scl_name: scl_name
)
cookbook 'mysql'
action :create
end
action :stop do
service "#{new_resource.name} :stop #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Init::Redhat if node['platform_family'] == 'redhat'
provider Chef::Provider::Service::Init::Insserv if node['platform_family'] == 'debian'
supports restart: true, status: true
action [:stop]
end
service "#{new_resource.name} :start #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Init::Redhat if node['platform_family'] == 'redhat'
provider Chef::Provider::Service::Init::Insserv if node['platform_family'] == 'debian'
supports restart: true, status: true
action [:enable, :start]
end
end
action :restart do
service "#{new_resource.name} :restart #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Init::Redhat if node['platform_family'] == 'redhat'
provider Chef::Provider::Service::Init::Insserv if node['platform_family'] == 'debian'
supports restart: true
action :restart
end
action :stop do
service "#{new_resource.name} :stop #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Init::Redhat if node['platform_family'] == 'redhat'
provider Chef::Provider::Service::Init::Insserv if node['platform_family'] == 'debian'
supports restart: true, status: true
action [:stop]
end
end
action :reload do
service "#{new_resource.name} :reload #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Init::Redhat if node['platform_family'] == 'redhat'
provider Chef::Provider::Service::Init::Insserv if node['platform_family'] == 'debian'
action :reload
end
action :restart do
service "#{new_resource.name} :restart #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Init::Redhat if node['platform_family'] == 'redhat'
provider Chef::Provider::Service::Init::Insserv if node['platform_family'] == 'debian'
supports restart: true
action :restart
end
end
def create_stop_system_service
service "#{new_resource.name} :create #{system_service_name}" do
service_name system_service_name
provider Chef::Provider::Service::Init::Redhat if node['platform_family'] == 'redhat'
provider Chef::Provider::Service::Init::Insserv if node['platform_family'] == 'debian'
supports status: true
action [:stop, :disable]
end
action :reload do
service "#{new_resource.name} :reload #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Init::Redhat if node['platform_family'] == 'redhat'
provider Chef::Provider::Service::Init::Insserv if node['platform_family'] == 'debian'
action :reload
end
end
def delete_stop_service
service "#{new_resource.name} :delete #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Init::Redhat if node['platform_family'] == 'redhat'
provider Chef::Provider::Service::Init::Insserv if node['platform_family'] == 'debian'
supports status: true
action [:disable, :stop]
only_if { ::File.exist?("#{etc_dir}/init.d/#{mysql_name}") }
end
def create_stop_system_service
service "#{new_resource.name} :create #{system_service_name}" do
service_name system_service_name
provider Chef::Provider::Service::Init::Redhat if node['platform_family'] == 'redhat'
provider Chef::Provider::Service::Init::Insserv if node['platform_family'] == 'debian'
supports status: true
action [:stop, :disable]
end
end
def delete_stop_service
service "#{new_resource.name} :delete #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Init::Redhat if node['platform_family'] == 'redhat'
provider Chef::Provider::Service::Init::Insserv if node['platform_family'] == 'debian'
supports status: true
action [:disable, :stop]
only_if { ::File.exist?("#{etc_dir}/init.d/#{mysql_name}") }
end
end
end

View File

@@ -1,105 +1,112 @@
require_relative 'provider_mysql_service_base'
class Chef
class Provider
class MysqlService
class Upstart < Chef::Provider::MysqlService
action :start do
template "#{new_resource.name} :start /usr/sbin/#{mysql_name}-wait-ready" do
path "/usr/sbin/#{mysql_name}-wait-ready"
source 'upstart/mysqld-wait-ready.erb'
owner 'root'
group 'root'
mode '0755'
variables(socket_file: socket_file)
cookbook 'mysql'
action :create
end
class MysqlServiceUpstart < Chef::Provider::MysqlServiceBase
if defined?(provides)
provides :mysql_service, os: 'linux' do
Chef::Platform::ServiceHelpers.service_resource_providers.include?(:upstart) &&
!Chef::Platform::ServiceHelpers.service_resource_providers.include?(:redhat)
end
end
template "#{new_resource.name} :start /etc/init/#{mysql_name}.conf" do
path "/etc/init/#{mysql_name}.conf"
source 'upstart/mysqld.erb'
owner 'root'
group 'root'
mode '0644'
variables(
defaults_file: defaults_file,
mysql_name: mysql_name,
run_group: new_resource.run_group,
run_user: new_resource.run_user,
socket_dir: socket_dir
)
cookbook 'mysql'
action :create
end
service "#{new_resource.name} :start #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Upstart
supports status: true
action [:start]
end
action :start do
template "#{new_resource.name} :start /usr/sbin/#{mysql_name}-wait-ready" do
path "/usr/sbin/#{mysql_name}-wait-ready"
source 'upstart/mysqld-wait-ready.erb'
owner 'root'
group 'root'
mode '0755'
variables(socket_file: socket_file)
cookbook 'mysql'
action :create
end
action :stop do
service "#{new_resource.name} :stop #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Upstart
supports restart: true, status: true
action [:stop]
end
template "#{new_resource.name} :start /etc/init/#{mysql_name}.conf" do
path "/etc/init/#{mysql_name}.conf"
source 'upstart/mysqld.erb'
owner 'root'
group 'root'
mode '0644'
variables(
defaults_file: defaults_file,
mysql_name: mysql_name,
run_group: new_resource.run_group,
run_user: new_resource.run_user,
socket_dir: socket_dir
)
cookbook 'mysql'
action :create
end
action :restart do
# With Upstart, restarting the service doesn't behave "as expected".
# We want the post-start stanzas, which wait until the
# service is available before returning
#
# http://upstart.ubuntu.com/cookbook/#restart
service "#{new_resource.name} :restart stop #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Upstart
action :stop
end
service "#{new_resource.name} :start #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Upstart
supports status: true
action [:start]
end
end
service "#{new_resource.name} :restart start #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Upstart
action :start
end
action :stop do
service "#{new_resource.name} :stop #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Upstart
supports restart: true, status: true
action [:stop]
end
end
action :restart do
# With Upstart, restarting the service doesn't behave "as expected".
# We want the post-start stanzas, which wait until the
# service is available before returning
#
# http://upstart.ubuntu.com/cookbook/#restart
service "#{new_resource.name} :restart stop #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Upstart
action :stop
end
action :reload do
# With Upstart, reload just sends a HUP signal to the process.
# As far as I can tell, this doesn't work the way it's
# supposed to, so we need to actually restart the service.
service "#{new_resource.name} :reload stop #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Upstart
action :stop
end
service "#{new_resource.name} :restart start #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Upstart
action :start
end
end
service "#{new_resource.name} :reload start #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Upstart
action :start
end
action :reload do
# With Upstart, reload just sends a HUP signal to the process.
# As far as I can tell, this doesn't work the way it's
# supposed to, so we need to actually restart the service.
service "#{new_resource.name} :reload stop #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Upstart
action :stop
end
def create_stop_system_service
service "#{new_resource.name} :create #{system_service_name}" do
service_name system_service_name
provider Chef::Provider::Service::Upstart
supports status: true
action [:stop, :disable]
end
service "#{new_resource.name} :reload start #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Upstart
action :start
end
end
def delete_stop_service
service "#{new_resource.name} :delete #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Upstart
action [:disable, :stop]
only_if { ::File.exist?("#{etc_dir}/init/#{mysql_name}") }
end
def create_stop_system_service
service "#{new_resource.name} :create #{system_service_name}" do
service_name system_service_name
provider Chef::Provider::Service::Upstart
supports status: true
action [:stop, :disable]
end
end
def delete_stop_service
service "#{new_resource.name} :delete #{mysql_name}" do
service_name mysql_name
provider Chef::Provider::Service::Upstart
action [:disable, :stop]
only_if { ::File.exist?("#{etc_dir}/init/#{mysql_name}") }
end
end
end

View File

@@ -0,0 +1,45 @@
begin
require 'chef/platform/provider_priority_map'
rescue LoadError
end
require_relative 'provider_mysql_service_smf'
require_relative 'provider_mysql_service_systemd'
require_relative 'provider_mysql_service_sysvinit'
require_relative 'provider_mysql_service_upstart'
require_relative 'provider_mysql_config'
require_relative 'provider_mysql_client'
if defined? Chef::Platform::ProviderPriorityMap
Chef::Platform::ProviderPriorityMap.instance.priority(
:mysql_service,
[Chef::Provider::MysqlServiceSystemd, Chef::Provider::MysqlServiceUpstart, Chef::Provider::MysqlServiceSysvinit],
os: 'linux'
)
else
# provider mappings for Chef 11
# systemd service
Chef::Platform.set platform: :fedora, version: '>= 19', resource: :mysql_service, provider: Chef::Provider::MysqlServiceSystemd
Chef::Platform.set platform: :redhat, version: '>= 7.0', resource: :mysql_service, provider: Chef::Provider::MysqlServiceSystemd
Chef::Platform.set platform: :centos, version: '>= 7.0', resource: :mysql_service, provider: Chef::Provider::MysqlServiceSystemd
Chef::Platform.set platform: :scientific, version: '>= 7.0', resource: :mysql_service, provider: Chef::Provider::MysqlServiceSystemd
Chef::Platform.set platform: :oracle, version: '>= 7.0', resource: :mysql_service, provider: Chef::Provider::MysqlServiceSystemd
# smf service
Chef::Platform.set platform: :omnios, resource: :mysql_service, provider: Chef::Provider::MysqlServiceSmf
Chef::Platform.set platform: :smartos, resource: :mysql_service, provider: Chef::Provider::MysqlServiceSmf
# upstart service
Chef::Platform.set platform: :ubuntu, resource: :mysql_service, provider: Chef::Provider::MysqlServiceUpstart
# default service
Chef::Platform.set resource: :mysql_service, provider: Chef::Provider::MysqlServiceSysvinit
# config
Chef::Platform.set resource: :mysql_config, provider: Chef::Provider::MysqlConfig
# client
Chef::Platform.set resource: :mysql_client, provider: Chef::Provider::MysqlClient
end

View File

@@ -3,6 +3,8 @@ require 'chef/resource/lwrp_base'
class Chef
class Resource
class MysqlClient < Chef::Resource::LWRPBase
provides :mysql_client
self.resource_name = :mysql_client
actions :create, :delete
default_action :create

View File

@@ -3,6 +3,8 @@ require 'chef/resource/lwrp_base'
class Chef
class Resource
class MysqlConfig < Chef::Resource::LWRPBase
provides :mysql_config
self.resource_name = :mysql_config
actions :create, :delete
default_action :create

View File

@@ -3,6 +3,8 @@ require 'chef/resource/lwrp_base'
class Chef
class Resource
class MysqlService < Chef::Resource::LWRPBase
provides :mysql_service
self.resource_name = :mysql_service
actions :create, :delete, :start, :stop, :restart, :reload
default_action :create
@@ -15,11 +17,15 @@ class Chef
attribute :package_name, kind_of: String, default: nil
attribute :package_version, kind_of: String, default: nil
attribute :bind_address, kind_of: String, default: nil
attribute :port, kind_of: String, default: '3306'
attribute :port, kind_of: [String, Integer], default: '3306'
attribute :run_group, kind_of: String, default: 'mysql'
attribute :run_user, kind_of: String, default: 'mysql'
attribute :socket, kind_of: String, default: nil
attribute :mysqld_options, kind_of: Hash, default: {}
attribute :version, kind_of: String, default: nil
attribute :error_log, kind_of: String, default: nil
attribute :tmp_dir, kind_of: String, default: nil
attribute :pid_file, kind_of: String, default: nil
end
end
end

View File

@@ -1,47 +0,0 @@
# provider mappings for Chef 11
#########
# service
#########
Chef::Platform.set platform: :amazon, resource: :mysql_service, provider: Chef::Provider::MysqlService::Sysvinit
Chef::Platform.set platform: :centos, version: '< 7.0', resource: :mysql_service, provider: Chef::Provider::MysqlService::Sysvinit
Chef::Platform.set platform: :centos, version: '>= 7.0', resource: :mysql_service, provider: Chef::Provider::MysqlService::Systemd
Chef::Platform.set platform: :debian, resource: :mysql_service, provider: Chef::Provider::MysqlService::Sysvinit
Chef::Platform.set platform: :fedora, version: '< 19', resource: :mysql_service, provider: Chef::Provider::MysqlService::Sysvinit
Chef::Platform.set platform: :fedora, version: '>= 19', resource: :mysql_service, provider: Chef::Provider::MysqlService::Systemd
Chef::Platform.set platform: :omnios, resource: :mysql_service, provider: Chef::Provider::MysqlService::Smf
Chef::Platform.set platform: :redhat, version: '< 7.0', resource: :mysql_service, provider: Chef::Provider::MysqlService::Sysvinit
Chef::Platform.set platform: :redhat, version: '>= 7.0', resource: :mysql_service, provider: Chef::Provider::MysqlService::Systemd
Chef::Platform.set platform: :scientific, version: '< 7.0', resource: :mysql_service, provider: Chef::Provider::MysqlService::Sysvinit
Chef::Platform.set platform: :scientific, version: '>= 7.0', resource: :mysql_service, provider: Chef::Provider::MysqlService::Systemd
Chef::Platform.set platform: :smartos, resource: :mysql_service, provider: Chef::Provider::MysqlService::Smf
Chef::Platform.set platform: :suse, resource: :mysql_service, provider: Chef::Provider::MysqlService::Sysvinit
Chef::Platform.set platform: :ubuntu, resource: :mysql_service, provider: Chef::Provider::MysqlService::Upstart
#########
# config
#########
Chef::Platform.set platform: :amazon, resource: :mysql_config, provider: Chef::Provider::MysqlConfig
Chef::Platform.set platform: :centos, resource: :mysql_config, provider: Chef::Provider::MysqlConfig
Chef::Platform.set platform: :debian, resource: :mysql_config, provider: Chef::Provider::MysqlConfig
Chef::Platform.set platform: :fedora, resource: :mysql_config, provider: Chef::Provider::MysqlConfig
Chef::Platform.set platform: :omnios, resource: :mysql_config, provider: Chef::Provider::MysqlConfig
Chef::Platform.set platform: :redhat, resource: :mysql_config, provider: Chef::Provider::MysqlConfig
Chef::Platform.set platform: :scientific, resource: :mysql_config, provider: Chef::Provider::MysqlConfig
Chef::Platform.set platform: :smartos, resource: :mysql_config, provider: Chef::Provider::MysqlConfig
Chef::Platform.set platform: :suse, resource: :mysql_config, provider: Chef::Provider::MysqlConfig
Chef::Platform.set platform: :ubuntu, resource: :mysql_config, provider: Chef::Provider::MysqlConfig
#########
# client
#########
Chef::Platform.set platform: :amazon, resource: :mysql_client, provider: Chef::Provider::MysqlClient
Chef::Platform.set platform: :centos, resource: :mysql_client, provider: Chef::Provider::MysqlClient
Chef::Platform.set platform: :debian, resource: :mysql_client, provider: Chef::Provider::MysqlClient
Chef::Platform.set platform: :fedora, resource: :mysql_client, provider: Chef::Provider::MysqlClient
Chef::Platform.set platform: :omnios, resource: :mysql_client, provider: Chef::Provider::MysqlClient
Chef::Platform.set platform: :redhat, resource: :mysql_client, provider: Chef::Provider::MysqlClient
Chef::Platform.set platform: :scientific, resource: :mysql_client, provider: Chef::Provider::MysqlClient
Chef::Platform.set platform: :smartos, resource: :mysql_client, provider: Chef::Provider::MysqlClient
Chef::Platform.set platform: :suse, resource: :mysql_client, provider: Chef::Provider::MysqlClient
Chef::Platform.set platform: :ubuntu, resource: :mysql_client, provider: Chef::Provider::MysqlClient

View File

@@ -1 +1 @@
{"name":"mysql","version":"6.0.22","description":"Provides mysql_service, mysql_config, and mysql_client resources","long_description":"","maintainer":"Chef Software, Inc.","maintainer_email":"cookbooks@chef.io","license":"Apache 2.0","platforms":{"amazon":">= 0.0.0","redhat":">= 0.0.0","centos":">= 0.0.0","scientific":">= 0.0.0","fedora":">= 0.0.0","debian":">= 0.0.0","ubuntu":">= 0.0.0","smartos":">= 0.0.0","omnios":">= 0.0.0","suse":">= 0.0.0"},"dependencies":{"yum-mysql-community":">= 0.0.0","smf":">= 0.0.0"},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{}}
{"name":"mysql","version":"6.1.2","description":"Provides mysql_service, mysql_config, and mysql_client resources","long_description":"","maintainer":"Chef Software, Inc.","maintainer_email":"cookbooks@chef.io","license":"Apache 2.0","platforms":{"amazon":">= 0.0.0","redhat":">= 0.0.0","centos":">= 0.0.0","scientific":">= 0.0.0","fedora":">= 0.0.0","debian":">= 0.0.0","ubuntu":">= 0.0.0","smartos":">= 0.0.0","omnios":">= 0.0.0","suse":">= 0.0.0"},"dependencies":{"yum-mysql-community":">= 0.0.0","smf":">= 0.0.0"},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{}}

View File

@@ -38,6 +38,9 @@ datadir = <%= @data_dir %>
<% if @tmp_dir %>
tmpdir = <%= @tmp_dir %>
<% end %>
<% @config.mysqld_options.each do |option,value| %>
<%= option %> = <%= value %>
<% end %>
<% if @lc_messages_dir %>
lc-messages-dir = <%= @lc_messages_dir %>
<% end %>

View File

@@ -30,8 +30,9 @@
# Variables
####
STARTTIMEOUT=30
STOPTIMEOUT=15
STARTTIMEOUT=900
STOPTIMEOUT=900
PID_DELAY=60
####
# Helper functions
@@ -131,6 +132,7 @@ print_stop_failure() {
start_command() {
# Attempt to start <%= @mysql_name %>
echo "Starting MySQL instance <%= @mysql_name %>"
local scl_name="<%= @scl_name %>"
if [ -z $scl_name ]; then
@@ -176,21 +178,32 @@ start() {
if running; then
break
fi
let CURRENT_DELAY=${STARTTIMEOUT}-${TIMEOUT}
if [ $CURRENT_DELAY -gt $PID_DELAY ] \
&& ! pid_exists; then
break
fi
sleep 1
let TIMEOUT=${TIMEOUT}-1
done
# Handle timeout
if [ $TIMEOUT -eq 0 ]; then
if running; then
# successbaby.gif
print_start_success
return 0
elif ! pid_exists; then
# Handle startup failure
print_start_failure
return 3
elif [ $TIMEOUT -eq 0 ]; then
# Handle timeout
print_start_failure
# clean up
kill $start_pid 2>/dev/null
return 1
fi
# successbaby.gif
print_start_success
return 0
}
# Reload <%= @mysql_name %>