Base ready
This commit is contained in:
		
							
								
								
									
										291
									
								
								ops/cookbooks/vendor/mysql/libraries/helpers.rb
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										291
									
								
								ops/cookbooks/vendor/mysql/libraries/helpers.rb
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,291 @@ | ||||
| module MysqlCookbook | ||||
|   module HelpersBase | ||||
|     require 'shellwords' | ||||
|  | ||||
|     def el6? | ||||
|       return true if node['platform_family'] == 'rhel' && node['platform_version'].to_i == 6 | ||||
|       false | ||||
|     end | ||||
|  | ||||
|     def el7? | ||||
|       return true if node['platform_family'] == 'rhel' && node['platform_version'].to_i == 7 | ||||
|       false | ||||
|     end | ||||
|  | ||||
|     def wheezy? | ||||
|       return true if node['platform'] == 'debian' && node['platform_version'].to_i == 7 | ||||
|       false | ||||
|     end | ||||
|  | ||||
|     def jessie? | ||||
|       return true if node['platform'] == 'debian' && node['platform_version'].to_i == 8 | ||||
|       false | ||||
|     end | ||||
|  | ||||
|     def stretch? | ||||
|       return true if node['platform'] == 'debian' && node['platform_version'].to_i == 9 | ||||
|       false | ||||
|     end | ||||
|  | ||||
|     def trusty? | ||||
|       return true if node['platform'] == 'ubuntu' && node['platform_version'] == '14.04' | ||||
|       return true if node['platform'] == 'linuxmint' && node['platform_version'] =~ /^17\.[0-9]$/ | ||||
|       false | ||||
|     end | ||||
|  | ||||
|     def xenial? | ||||
|       return true if node['platform'] == 'ubuntu' && node['platform_version'] == '16.04' | ||||
|       false | ||||
|     end | ||||
|  | ||||
|     def defaults_file | ||||
|       "#{etc_dir}/my.cnf" | ||||
|     end | ||||
|  | ||||
|     def default_data_dir | ||||
|       return "/var/lib/#{mysql_name}" if node['os'] == 'linux' | ||||
|       return "/opt/local/lib/#{mysql_name}" if node['os'] == 'solaris2' | ||||
|       return "/var/db/#{mysql_name}" if node['os'] == 'freebsd' | ||||
|     end | ||||
|  | ||||
|     def default_error_log | ||||
|       "#{log_dir}/error.log" | ||||
|     end | ||||
|  | ||||
|     def default_pid_file | ||||
|       "#{run_dir}/mysqld.pid" | ||||
|     end | ||||
|  | ||||
|     def default_major_version | ||||
|       # rhelish | ||||
|       return '5.1' if el6? | ||||
|       return '5.6' if el7? | ||||
|       return '5.6' if node['platform'] == 'amazon' | ||||
|  | ||||
|       # debian | ||||
|       return '5.5' if wheezy? | ||||
|       return '5.5' if jessie? | ||||
|  | ||||
|       # ubuntu | ||||
|       return '5.5' if trusty? | ||||
|       return '5.7' if xenial? | ||||
|  | ||||
|       # misc | ||||
|       return '5.6' if node['platform'] == 'freebsd' | ||||
|       return '5.6' if node['platform'] == 'fedora' | ||||
|       return '5.6' if node['platform_family'] == 'suse' | ||||
|     end | ||||
|  | ||||
|     def major_from_full(v) | ||||
|       v.split('.').shift(2).join('.') | ||||
|     end | ||||
|  | ||||
|     def mysql_name | ||||
|       "mysql-#{instance}" | ||||
|     end | ||||
|  | ||||
|     def default_socket_file | ||||
|       "#{run_dir}/mysqld.sock" | ||||
|     end | ||||
|  | ||||
|     def default_client_package_name | ||||
|       return ['mysql', 'mysql-devel'] if major_version == '5.1' && el6? | ||||
|       return ['mysql55', 'mysql55-devel.x86_64'] if major_version == '5.5' && node['platform'] == 'amazon' | ||||
|       return ['mysql56', 'mysql56-devel.x86_64'] if major_version == '5.6' && node['platform'] == 'amazon' | ||||
|       return ['mysql-client-5.5', 'libmysqlclient-dev'] if major_version == '5.5' && node['platform_family'] == 'debian' | ||||
|       return ['mysql-client-5.6', 'libmysqlclient-dev'] if major_version == '5.6' && node['platform_family'] == 'debian' | ||||
|       return ['mysql-client-5.7', 'libmysqlclient-dev'] if major_version == '5.7' && node['platform_family'] == 'debian' | ||||
|       return 'mysql-community-server-client' if major_version == '5.6' && node['platform_family'] == 'suse' | ||||
|       ['mysql-community-client', 'mysql-community-devel'] | ||||
|     end | ||||
|  | ||||
|     def default_server_package_name | ||||
|       return 'mysql-server' if major_version == '5.1' && el6? | ||||
|       return 'mysql55-server' if major_version == '5.5' && node['platform'] == 'amazon' | ||||
|       return 'mysql56-server' if major_version == '5.6' && node['platform'] == 'amazon' | ||||
|       return 'mysql-server-5.5' if major_version == '5.5' && node['platform_family'] == 'debian' | ||||
|       return 'mysql-server-5.6' if major_version == '5.6' && node['platform_family'] == 'debian' | ||||
|       return 'mysql-server-5.7' if major_version == '5.7' && node['platform_family'] == 'debian' | ||||
|       return 'mysql-community-server' if major_version == '5.6' && node['platform_family'] == 'suse' | ||||
|       'mysql-community-server' | ||||
|     end | ||||
|  | ||||
|     def socket_dir | ||||
|       File.dirname(socket) | ||||
|     end | ||||
|  | ||||
|     def run_dir | ||||
|       return "#{prefix_dir}/var/run/#{mysql_name}" if node['platform_family'] == 'rhel' | ||||
|       return "/run/#{mysql_name}" if node['platform_family'] == 'debian' | ||||
|       "/var/run/#{mysql_name}" | ||||
|     end | ||||
|  | ||||
|     def prefix_dir | ||||
|       return "/opt/mysql#{pkg_ver_string}" if node['platform_family'] == 'omnios' | ||||
|       return '/opt/local' if node['platform_family'] == 'smartos' | ||||
|       return "/opt/rh/#{scl_name}/root" if scl_package? | ||||
|     end | ||||
|  | ||||
|     def scl_name | ||||
|       return unless node['platform_family'] == 'rhel' | ||||
|       return 'mysql51' if version == '5.1' && node['platform_version'].to_i == 5 | ||||
|       return 'mysql55' if version == '5.5' && node['platform_version'].to_i == 5 | ||||
|     end | ||||
|  | ||||
|     def scl_package? | ||||
|       return unless node['platform_family'] == 'rhel' | ||||
|       return true if version == '5.1' && node['platform_version'].to_i == 5 | ||||
|       return true if version == '5.5' && node['platform_version'].to_i == 5 | ||||
|       false | ||||
|     end | ||||
|  | ||||
|     def etc_dir | ||||
|       return "/opt/mysql#{pkg_ver_string}/etc/#{mysql_name}" if node['platform_family'] == 'omnios' | ||||
|       return "#{prefix_dir}/etc/#{mysql_name}" if node['platform_family'] == 'smartos' | ||||
|       "#{prefix_dir}/etc/#{mysql_name}" | ||||
|     end | ||||
|  | ||||
|     def base_dir | ||||
|       prefix_dir || '/usr' | ||||
|     end | ||||
|  | ||||
|     def system_service_name | ||||
|       return 'mysql51-mysqld' if node['platform_family'] == 'rhel' && scl_name == 'mysql51' | ||||
|       return 'mysql55-mysqld' if node['platform_family'] == 'rhel' && scl_name == 'mysql55' | ||||
|       return 'mysqld' if node['platform_family'] == 'rhel' | ||||
|       return 'mysqld' if node['platform_family'] == 'fedora' | ||||
|       'mysql' # not one of the above | ||||
|     end | ||||
|  | ||||
|     def v56plus | ||||
|       return false if version.split('.')[0].to_i < 5 | ||||
|       return false if version.split('.')[1].to_i < 6 | ||||
|       true | ||||
|     end | ||||
|  | ||||
|     def v57plus | ||||
|       return false if version.split('.')[0].to_i < 5 | ||||
|       return false if version.split('.')[1].to_i < 7 | ||||
|       true | ||||
|     end | ||||
|  | ||||
|     def default_include_dir | ||||
|       "#{etc_dir}/conf.d" | ||||
|     end | ||||
|  | ||||
|     def log_dir | ||||
|       return "/var/adm/log/#{mysql_name}" if node['platform_family'] == 'omnios' | ||||
|       "#{prefix_dir}/var/log/#{mysql_name}" | ||||
|     end | ||||
|  | ||||
|     def lc_messages_dir; end | ||||
|  | ||||
|     def init_records_script | ||||
|       # Note: shell-escaping passwords in a SQL file may cause corruption - eg | ||||
|       # mysql will read \& as &, but \% as \%. Just escape bare-minimum \ and ' | ||||
|       sql_escaped_password = root_password.gsub('\\') { '\\\\' }.gsub("'") { '\\\'' } | ||||
|  | ||||
|       <<-EOS | ||||
|         set -e | ||||
|         rm -rf /tmp/#{mysql_name} | ||||
|         mkdir /tmp/#{mysql_name} | ||||
|  | ||||
|         cat > /tmp/#{mysql_name}/my.sql <<-'EOSQL' | ||||
| UPDATE mysql.user SET #{password_column_name}=PASSWORD('#{sql_escaped_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 | ||||
|  | ||||
|        #{db_init} | ||||
|        #{record_init} | ||||
|  | ||||
|        while [ ! -f #{pid_file} ] ; do sleep 1 ; done | ||||
|        kill `cat #{pid_file}` | ||||
|        while [ -f #{pid_file} ] ; do sleep 1 ; done | ||||
|        rm -rf /tmp/#{mysql_name} | ||||
|        EOS | ||||
|     end | ||||
|  | ||||
|     def password_column_name | ||||
|       return 'authentication_string' if v57plus | ||||
|       'password' | ||||
|     end | ||||
|  | ||||
|     def root_password | ||||
|       if initial_root_password == '' | ||||
|         Chef::Log.info('Root password is empty') | ||||
|         return '' | ||||
|       end | ||||
|       initial_root_password | ||||
|     end | ||||
|  | ||||
|     def password_expired | ||||
|       return ", password_expired='N'" if v57plus | ||||
|       '' | ||||
|     end | ||||
|  | ||||
|     def db_init | ||||
|       return mysqld_initialize_cmd if v57plus | ||||
|       mysql_install_db_cmd | ||||
|     end | ||||
|  | ||||
|     def mysql_install_db_bin | ||||
|       return "#{base_dir}/scripts/mysql_install_db" if node['platform_family'] == 'omnios' | ||||
|       return "#{prefix_dir}/bin/mysql_install_db" if node['platform_family'] == 'smartos' | ||||
|       'mysql_install_db' | ||||
|     end | ||||
|  | ||||
|     def mysql_install_db_cmd | ||||
|       cmd = mysql_install_db_bin | ||||
|       cmd << " --defaults-file=#{etc_dir}/my.cnf" | ||||
|       cmd << " --datadir=#{data_dir}" | ||||
|       cmd << ' --explicit_defaults_for_timestamp' if v56plus && !v57plus | ||||
|       return "scl enable #{scl_name} \"#{cmd}\"" if scl_package? | ||||
|       cmd | ||||
|     end | ||||
|  | ||||
|     def mysqladmin_bin | ||||
|       return "#{prefix_dir}/bin/mysqladmin" if node['platform_family'] == 'smartos' | ||||
|       return 'mysqladmin' if scl_package? | ||||
|       "#{prefix_dir}/usr/bin/mysqladmin" | ||||
|     end | ||||
|  | ||||
|     def mysqld_bin | ||||
|       return "#{prefix_dir}/libexec/mysqld" if node['platform_family'] == 'smartos' | ||||
|       return "#{base_dir}/bin/mysqld" if node['platform_family'] == 'omnios' | ||||
|       return '/usr/sbin/mysqld' if node['platform_family'] == 'fedora' && v56plus | ||||
|       return '/usr/libexec/mysqld' if node['platform_family'] == 'fedora' | ||||
|       return 'mysqld' if scl_package? | ||||
|       "#{prefix_dir}/usr/sbin/mysqld" | ||||
|     end | ||||
|  | ||||
|     def mysqld_initialize_cmd | ||||
|       cmd = mysqld_bin | ||||
|       cmd << " --defaults-file=#{etc_dir}/my.cnf" | ||||
|       cmd << ' --initialize' | ||||
|       cmd << ' --explicit_defaults_for_timestamp' if v56plus | ||||
|       return "scl enable #{scl_name} \"#{cmd}\"" if scl_package? | ||||
|       cmd | ||||
|     end | ||||
|  | ||||
|     def mysqld_safe_bin | ||||
|       return "#{prefix_dir}/bin/mysqld_safe" if node['platform_family'] == 'smartos' | ||||
|       return "#{base_dir}/bin/mysqld_safe" if node['platform_family'] == 'omnios' | ||||
|       return 'mysqld_safe' if scl_package? | ||||
|       "#{prefix_dir}/usr/bin/mysqld_safe" | ||||
|     end | ||||
|  | ||||
|     def record_init | ||||
|       cmd = v56plus ? mysqld_bin : mysqld_safe_bin | ||||
|       cmd << " --defaults-file=#{etc_dir}/my.cnf" | ||||
|       cmd << " --init-file=/tmp/#{mysql_name}/my.sql" | ||||
|       cmd << ' --explicit_defaults_for_timestamp' if v56plus | ||||
|       cmd << ' &' | ||||
|       return "scl enable #{scl_name} \"#{cmd}\"" if scl_package? | ||||
|       cmd | ||||
|     end | ||||
|   end | ||||
| end | ||||
							
								
								
									
										71
									
								
								ops/cookbooks/vendor/mysql/libraries/matchers.rb
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								ops/cookbooks/vendor/mysql/libraries/matchers.rb
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,71 @@ | ||||
| if defined?(ChefSpec) | ||||
|   ChefSpec.define_matcher :mysql_config | ||||
|   ChefSpec.define_matcher :mysql_service | ||||
|   ChefSpec.define_matcher :mysql_client | ||||
|  | ||||
|   # mysql_client_client_installation_package | ||||
|   def install_mysql_client_installation_package(resource_name) | ||||
|     ChefSpec::Matchers::ResourceMatcher.new(:mysql_client_installation_package, :create, resource_name) | ||||
|   end | ||||
|  | ||||
|   def remove_mysql_client_installation_package(resource_name) | ||||
|     ChefSpec::Matchers::ResourceMatcher.new(:mysql_client_installation_package, :remove, resource_name) | ||||
|   end | ||||
|  | ||||
|   # mysql_server_server_installation_package | ||||
|   def install_mysql_server_installation_package(resource_name) | ||||
|     ChefSpec::Matchers::ResourceMatcher.new(:mysql_server_installation_package, :install, resource_name) | ||||
|   end | ||||
|  | ||||
|   def remove_mysql_server_installation_package(resource_name) | ||||
|     ChefSpec::Matchers::ResourceMatcher.new(:mysql_server_installation_package, :remove, resource_name) | ||||
|   end | ||||
|  | ||||
|   ##### | ||||
|   # old | ||||
|   ##### | ||||
|  | ||||
|   # client | ||||
|   def create_mysql_client(resource_name) | ||||
|     ChefSpec::Matchers::ResourceMatcher.new(:mysql_client, :create, resource_name) | ||||
|   end | ||||
|  | ||||
|   def delete_mysql_client(resource_name) | ||||
|     ChefSpec::Matchers::ResourceMatcher.new(:mysql_client, :delete, resource_name) | ||||
|   end | ||||
|  | ||||
|   # mysql_config | ||||
|   def create_mysql_config(resource_name) | ||||
|     ChefSpec::Matchers::ResourceMatcher.new(:mysql_config, :create, resource_name) | ||||
|   end | ||||
|  | ||||
|   def delete_mysql_config(resource_name) | ||||
|     ChefSpec::Matchers::ResourceMatcher.new(:mysql_config, :delete, resource_name) | ||||
|   end | ||||
|  | ||||
|   # service | ||||
|   def create_mysql_service(resource_name) | ||||
|     ChefSpec::Matchers::ResourceMatcher.new(:mysql_service, :create, resource_name) | ||||
|   end | ||||
|  | ||||
|   def delete_mysql_service(resource_name) | ||||
|     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 | ||||
|  | ||||
| end | ||||
							
								
								
									
										30
									
								
								ops/cookbooks/vendor/mysql/libraries/mysql_base.rb
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								ops/cookbooks/vendor/mysql/libraries/mysql_base.rb
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,30 @@ | ||||
| module MysqlCookbook | ||||
|   class MysqlBase < Chef::Resource | ||||
|     require_relative 'helpers' | ||||
|  | ||||
|     # All resources are composites | ||||
|     def whyrun_supported? | ||||
|       true | ||||
|     end | ||||
|  | ||||
|     ################ | ||||
|     # Type Constants | ||||
|     ################ | ||||
|  | ||||
|     Boolean = property_type( | ||||
|       is: [true, false], | ||||
|       default: false | ||||
|     ) unless defined?(Boolean) | ||||
|  | ||||
|     ################### | ||||
|     # Common Properties | ||||
|     ################### | ||||
|     property :run_group, String, default: 'mysql', desired_state: false | ||||
|     property :run_user, String, default: 'mysql', desired_state: false | ||||
|     property :version, String, default: lazy { default_major_version }, desired_state: false | ||||
|     property :include_dir, String, default: lazy { default_include_dir }, desired_state: false | ||||
|     property :major_version, String, default: lazy { major_from_full(version) }, desired_state: false | ||||
|  | ||||
|     action_class | ||||
|   end | ||||
| end | ||||
							
								
								
									
										31
									
								
								ops/cookbooks/vendor/mysql/libraries/mysql_client_installation_package.rb
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								ops/cookbooks/vendor/mysql/libraries/mysql_client_installation_package.rb
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,31 @@ | ||||
| module MysqlCookbook | ||||
|   class MysqlClientInstallationPackage < MysqlBase | ||||
|     # helper methods | ||||
|     require_relative 'helpers' | ||||
|     include MysqlCookbook::HelpersBase | ||||
|  | ||||
|     # Resource properties | ||||
|     resource_name :mysql_client_installation_package | ||||
|     provides :mysql_client_installation, os: 'linux' | ||||
|     provides :mysql_client, os: 'linux' | ||||
|  | ||||
|     property :package_name, [String, Array], default: lazy { default_client_package_name }, desired_state: false | ||||
|     property :package_options, [String, nil], desired_state: false | ||||
|     property :package_version, [String, nil], default: nil, desired_state: false | ||||
|  | ||||
|     # Actions | ||||
|     action :create do | ||||
|       package new_resource.package_name do | ||||
|         version new_resource.package_version if new_resource.package_version | ||||
|         options new_resource.package_options if new_resource.package_options | ||||
|         action :install | ||||
|       end | ||||
|     end | ||||
|  | ||||
|     action :delete do | ||||
|       package new_resource.package_name do | ||||
|         action :remove | ||||
|       end | ||||
|     end | ||||
|   end | ||||
| end | ||||
							
								
								
									
										56
									
								
								ops/cookbooks/vendor/mysql/libraries/mysql_config.rb
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								ops/cookbooks/vendor/mysql/libraries/mysql_config.rb
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,56 @@ | ||||
| module MysqlCookbook | ||||
|   class MysqlConfig < MysqlBase | ||||
|     resource_name :mysql_config | ||||
|  | ||||
|     property :config_name, String, name_property: true, desired_state: false | ||||
|     property :cookbook, String, desired_state: false | ||||
|     property :group, String, default: 'mysql', desired_state: false | ||||
|     property :instance, String, default: 'default', desired_state: false | ||||
|     property :owner, String, default: 'mysql', desired_state: false | ||||
|     property :source, String, desired_state: false | ||||
|     property :variables, [Hash], desired_state: false | ||||
|     property :version, String, default: lazy { default_major_version }, desired_state: false | ||||
|  | ||||
|     require_relative 'helpers' | ||||
|     include MysqlCookbook::HelpersBase | ||||
|  | ||||
|     provides :mysql_config | ||||
|  | ||||
|     action :create do | ||||
|       # hax because group property | ||||
|       g = Chef::Resource::Group.new(new_resource.group, run_context) | ||||
|       g.system true if new_resource.name == 'mysql' | ||||
|       resource_collection.insert g | ||||
|  | ||||
|       user new_resource.owner do | ||||
|         gid new_resource.owner | ||||
|         system true if new_resource.name == 'mysql' | ||||
|         action :create | ||||
|       end | ||||
|  | ||||
|       directory new_resource.include_dir do | ||||
|         owner new_resource.owner | ||||
|         group new_resource.group | ||||
|         mode '0750' | ||||
|         recursive true | ||||
|         action :create | ||||
|       end | ||||
|  | ||||
|       template "#{new_resource.include_dir}/#{new_resource.config_name}.cnf" do | ||||
|         owner new_resource.owner | ||||
|         group new_resource.group | ||||
|         mode '0640' | ||||
|         variables(new_resource.variables) | ||||
|         source new_resource.source | ||||
|         cookbook new_resource.cookbook | ||||
|         action :create | ||||
|       end | ||||
|     end | ||||
|  | ||||
|     action :delete do | ||||
|       file "#{new_resource.include_dir}/#{new_resource.config_name}.cnf" do | ||||
|         action :delete | ||||
|       end | ||||
|     end | ||||
|   end | ||||
| end | ||||
							
								
								
									
										42
									
								
								ops/cookbooks/vendor/mysql/libraries/mysql_server_installation_package.rb
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								ops/cookbooks/vendor/mysql/libraries/mysql_server_installation_package.rb
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,42 @@ | ||||
| module MysqlCookbook | ||||
|   class MysqlServerInstallationPackage < MysqlBase | ||||
|     # Resource properties | ||||
|     resource_name :mysql_server_installation_package | ||||
|     provides :mysql_server_installation, os: 'linux' | ||||
|  | ||||
|     property :package_name, String, default: lazy { default_server_package_name }, desired_state: false | ||||
|     property :package_options, [String, nil], desired_state: false | ||||
|     property :package_version, [String, nil], default: nil, desired_state: false | ||||
|  | ||||
|     # helper methods | ||||
|     require_relative 'helpers' | ||||
|     include MysqlCookbook::HelpersBase | ||||
|  | ||||
|     # Actions | ||||
|     action :install do | ||||
|       package new_resource.package_name do | ||||
|         version new_resource.package_version if new_resource.package_version | ||||
|         options new_resource.package_options if new_resource.package_options | ||||
|         notifies :install, 'package[perl-Sys-Hostname-Long]', :immediately if platform_family?('suse') | ||||
|         notifies :run, 'execute[Initial DB setup script]', :immediately if platform_family?('suse') | ||||
|         action :install | ||||
|       end | ||||
|  | ||||
|       package 'perl-Sys-Hostname-Long' do | ||||
|         action :nothing | ||||
|       end | ||||
|  | ||||
|       execute 'Initial DB setup script' do | ||||
|         environment 'INSTANCE' => new_resource.name | ||||
|         command '/usr/lib/mysql/mysql-systemd-helper install' | ||||
|         action :nothing | ||||
|       end | ||||
|     end | ||||
|  | ||||
|     action :delete do | ||||
|       package new_resource.package_name do | ||||
|         action :remove | ||||
|       end | ||||
|     end | ||||
|   end | ||||
| end | ||||
							
								
								
									
										105
									
								
								ops/cookbooks/vendor/mysql/libraries/mysql_service.rb
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										105
									
								
								ops/cookbooks/vendor/mysql/libraries/mysql_service.rb
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,105 @@ | ||||
| module MysqlCookbook | ||||
|   require_relative 'mysql_service_base' | ||||
|   class MysqlService < MysqlServiceBase | ||||
|     resource_name :mysql_service | ||||
|  | ||||
|     # installation type and service_manager | ||||
|     property :install_method, %w(package auto), default: 'auto', desired_state: false | ||||
|     property :service_manager, %w(sysvinit upstart systemd auto), default: 'auto', desired_state: false | ||||
|  | ||||
|     # mysql_server_installation | ||||
|     property :version, String, default: lazy { default_major_version }, desired_state: false | ||||
|     property :major_version, String, default: lazy { major_from_full(version) }, desired_state: false | ||||
|     property :package_name, String, default: lazy { default_package_name }, desired_state: false | ||||
|     property :package_options, [String, nil], desired_state: false | ||||
|     property :package_version, [String, nil], default: nil, desired_state: false | ||||
|  | ||||
|     ################ | ||||
|     # Helper Methods | ||||
|     ################ | ||||
|  | ||||
|     def copy_properties_to(to, *properties) | ||||
|       properties = self.class.properties.keys if properties.empty? | ||||
|       properties.each do |p| | ||||
|         # If the property is set on from, and exists on to, set the | ||||
|         # property on to | ||||
|         if to.class.properties.include?(p) && property_is_set?(p) | ||||
|           to.send(p, send(p)) | ||||
|         end | ||||
|       end | ||||
|     end | ||||
|  | ||||
|     action_class do | ||||
|       def installation(&block) | ||||
|         case new_resource.install_method | ||||
|         when 'auto' | ||||
|           install = mysql_server_installation(new_resource.name, &block) | ||||
|         when 'package' | ||||
|           install = mysql_server_installation_package(new_resource.name, &block) | ||||
|         when 'none' | ||||
|           Chef::Log.info('Skipping MySQL installation. Assuming it was handled previously.') | ||||
|           return | ||||
|         end | ||||
|         copy_properties_to(install) | ||||
|         install | ||||
|       end | ||||
|  | ||||
|       def svc_manager(&block) | ||||
|         case new_resource.service_manager | ||||
|         when 'auto' | ||||
|           svc = mysql_service_manager(new_resource.name, &block) | ||||
|         when 'sysvinit' | ||||
|           svc = mysql_service_manager_sysvinit(new_resource.name, &block) | ||||
|         when 'upstart' | ||||
|           svc = mysql_service_manager_upstart(new_resource.name, &block) | ||||
|         when 'systemd' | ||||
|           svc = mysql_service_manager_systemd(new_resource.name, &block) | ||||
|         end | ||||
|         copy_properties_to(svc) | ||||
|         svc | ||||
|       end | ||||
|     end | ||||
|  | ||||
|     ######### | ||||
|     # Actions | ||||
|     ######### | ||||
|  | ||||
|     action :create do | ||||
|       installation do | ||||
|         action :install | ||||
|       end | ||||
|  | ||||
|       svc_manager do | ||||
|         action :create | ||||
|       end | ||||
|     end | ||||
|  | ||||
|     action :start do | ||||
|       svc_manager do | ||||
|         action :start | ||||
|       end | ||||
|     end | ||||
|  | ||||
|     action :delete do | ||||
|       svc_manager do | ||||
|         action :delete | ||||
|       end | ||||
|  | ||||
|       installation do | ||||
|         action :delete | ||||
|       end | ||||
|     end | ||||
|  | ||||
|     action :restart do | ||||
|       svc_manager do | ||||
|         action :restart | ||||
|       end | ||||
|     end | ||||
|  | ||||
|     action :stop do | ||||
|       svc_manager do | ||||
|         action :stop | ||||
|       end | ||||
|     end | ||||
|   end | ||||
| end | ||||
							
								
								
									
										203
									
								
								ops/cookbooks/vendor/mysql/libraries/mysql_service_base.rb
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										203
									
								
								ops/cookbooks/vendor/mysql/libraries/mysql_service_base.rb
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,203 @@ | ||||
| module MysqlCookbook | ||||
|   class MysqlServiceBase < MysqlBase | ||||
|     property :bind_address, String, desired_state: false | ||||
|     property :charset, String, default: 'utf8', desired_state: false | ||||
|     property :data_dir, String, default: lazy { default_data_dir }, desired_state: false | ||||
|     property :error_log, String, default: lazy { default_error_log }, desired_state: false | ||||
|     property :initial_root_password, String, default: 'ilikerandompasswords', desired_state: false | ||||
|     property :instance, String, name_property: true, desired_state: false | ||||
|     property :mysqld_options, Hash, default: {}, desired_state: false | ||||
|     property :pid_file, String, default: lazy { default_pid_file }, desired_state: false | ||||
|     property :port, [String, Integer], default: '3306', desired_state: false | ||||
|     property :socket, String, default: lazy { default_socket_file }, desired_state: false | ||||
|     property :tmp_dir, String, desired_state: false | ||||
|  | ||||
|     alias socket_file socket | ||||
|  | ||||
|     require_relative 'helpers' | ||||
|     include MysqlCookbook::HelpersBase | ||||
|  | ||||
|     # action class methods are available within the actions and work as if the coded | ||||
|     # was inline the action. No messing with classes or passing in the new_resource | ||||
|     action_class do | ||||
|       def create_system_user | ||||
|         group 'mysql' do | ||||
|           action :create | ||||
|         end | ||||
|  | ||||
|         user 'mysql' do | ||||
|           gid 'mysql' | ||||
|           action :create | ||||
|         end | ||||
|       end | ||||
|  | ||||
|       def create_config | ||||
|         # require 'pry' ; binding.pry | ||||
|  | ||||
|         # Yak shaving secion. Account for random errata. | ||||
|         # | ||||
|         # Turns out that mysqld is hard coded to try and read | ||||
|         # /etc/mysql/my.cnf, and its presence causes problems when | ||||
|         # setting up multiple services. | ||||
|         file "#{prefix_dir}/etc/mysql/my.cnf" do | ||||
|           action :delete | ||||
|         end | ||||
|  | ||||
|         file "#{prefix_dir}/etc/my.cnf" do | ||||
|           action :delete | ||||
|         end | ||||
|  | ||||
|         # mysql_install_db is broken on 5.6.13 | ||||
|         link "#{prefix_dir}/usr/share/my-default.cnf" do | ||||
|           to "#{etc_dir}/my.cnf" | ||||
|           not_if { ::File.exist? "#{prefix_dir}/usr/share/my-default.cnf" } # FIXME: Chef bug? | ||||
|           action :create | ||||
|         end | ||||
|  | ||||
|         # Support directories | ||||
|         directory etc_dir do | ||||
|           owner new_resource.run_user | ||||
|           group new_resource.run_group | ||||
|           mode '0750' | ||||
|           recursive true | ||||
|           action :create | ||||
|         end | ||||
|  | ||||
|         directory new_resource.include_dir do | ||||
|           owner new_resource.run_user | ||||
|           group new_resource.run_group | ||||
|           mode '0750' | ||||
|           recursive true | ||||
|           action :create | ||||
|         end | ||||
|  | ||||
|         directory run_dir do | ||||
|           owner new_resource.run_user | ||||
|           group new_resource.run_group | ||||
|           mode '0755' | ||||
|           recursive true | ||||
|           action :create | ||||
|         end | ||||
|  | ||||
|         directory log_dir do | ||||
|           owner new_resource.run_user | ||||
|           group new_resource.run_group | ||||
|           mode '0750' | ||||
|           recursive true | ||||
|           action :create | ||||
|         end | ||||
|  | ||||
|         directory new_resource.data_dir do | ||||
|           owner new_resource.run_user | ||||
|           group new_resource.run_group | ||||
|           mode '0750' | ||||
|           recursive true | ||||
|           action :create | ||||
|         end | ||||
|  | ||||
|         # Main configuration file | ||||
|         template "#{etc_dir}/my.cnf" do | ||||
|           source 'my.cnf.erb' | ||||
|           cookbook 'mysql' | ||||
|           owner new_resource.run_user | ||||
|           group new_resource.run_group | ||||
|           mode '0600' | ||||
|           variables(config: new_resource) | ||||
|           action :create | ||||
|         end | ||||
|       end | ||||
|  | ||||
|       def initialize_database | ||||
|         # initialize database and create initial records | ||||
|         bash "#{new_resource.name} initial records" do | ||||
|           code init_records_script | ||||
|           umask '022' | ||||
|           returns [0, 1, 2] # facepalm | ||||
|           not_if "/usr/bin/test -f #{new_resource.data_dir}/mysql/user.frm" | ||||
|           action :run | ||||
|         end | ||||
|       end | ||||
|  | ||||
|       def delete_support_directories | ||||
|         # Stop the service before removing support directories | ||||
|         delete_stop_service | ||||
|  | ||||
|         directory etc_dir do | ||||
|           recursive true | ||||
|           action :delete | ||||
|         end | ||||
|  | ||||
|         directory run_dir do | ||||
|           recursive true | ||||
|           action :delete | ||||
|         end | ||||
|  | ||||
|         directory log_dir do | ||||
|           recursive true | ||||
|           action :delete | ||||
|         end | ||||
|       end | ||||
|  | ||||
|       # | ||||
|       # Platform specific bits | ||||
|       # | ||||
|       def configure_apparmor | ||||
|         # Do not add these resource if inside a container | ||||
|         # Only valid on Ubuntu | ||||
|         return if ::File.exist?('/.dockerenv') || ::File.exist?('/.dockerinit') || node['platform'] != 'ubuntu' | ||||
|  | ||||
|         # Apparmor | ||||
|         package 'apparmor' do | ||||
|           action :install | ||||
|         end | ||||
|  | ||||
|         directory '/etc/apparmor.d/local/mysql' do | ||||
|           owner 'root' | ||||
|           group 'root' | ||||
|           mode '0755' | ||||
|           recursive true | ||||
|           action :create | ||||
|         end | ||||
|  | ||||
|         template '/etc/apparmor.d/local/usr.sbin.mysqld' do | ||||
|           cookbook 'mysql' | ||||
|           source 'apparmor/usr.sbin.mysqld-local.erb' | ||||
|           owner 'root' | ||||
|           group 'root' | ||||
|           mode '0644' | ||||
|           action :create | ||||
|           notifies :restart, "service[#{new_resource.instance} apparmor]", :immediately | ||||
|         end | ||||
|  | ||||
|         template '/etc/apparmor.d/usr.sbin.mysqld' do | ||||
|           cookbook 'mysql' | ||||
|           source 'apparmor/usr.sbin.mysqld.erb' | ||||
|           owner 'root' | ||||
|           group 'root' | ||||
|           mode '0644' | ||||
|           action :create | ||||
|           notifies :restart, "service[#{new_resource.instance} apparmor]", :immediately | ||||
|         end | ||||
|  | ||||
|         template "/etc/apparmor.d/local/mysql/#{new_resource.instance}" do | ||||
|           cookbook 'mysql' | ||||
|           source 'apparmor/usr.sbin.mysqld-instance.erb' | ||||
|           owner 'root' | ||||
|           group 'root' | ||||
|           mode '0644' | ||||
|           variables( | ||||
|             config: new_resource, | ||||
|             mysql_name: mysql_name | ||||
|           ) | ||||
|           action :create | ||||
|           notifies :restart, "service[#{new_resource.instance} apparmor]", :immediately | ||||
|         end | ||||
|  | ||||
|         service "#{new_resource.instance} apparmor" do | ||||
|           service_name 'apparmor' | ||||
|           action :nothing | ||||
|         end | ||||
|       end | ||||
|     end | ||||
|   end | ||||
| end | ||||
							
								
								
									
										142
									
								
								ops/cookbooks/vendor/mysql/libraries/mysql_service_manager_systemd.rb
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										142
									
								
								ops/cookbooks/vendor/mysql/libraries/mysql_service_manager_systemd.rb
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,142 @@ | ||||
| module MysqlCookbook | ||||
|   class MysqlServiceManagerSystemd < MysqlServiceBase | ||||
|     resource_name :mysql_service_manager_systemd | ||||
|  | ||||
|     provides :mysql_service_manager, os: 'linux' do |_node| | ||||
|       Chef::Platform::ServiceHelpers.service_resource_providers.include?(:systemd) | ||||
|     end | ||||
|  | ||||
|     action :create do | ||||
|       # from base | ||||
|       create_system_user | ||||
|       stop_system_service | ||||
|       create_config | ||||
|       configure_apparmor | ||||
|       initialize_database | ||||
|     end | ||||
|  | ||||
|     action :start do | ||||
|       # Needed for Debian / Ubuntu | ||||
|       directory '/usr/libexec' do | ||||
|         owner 'root' | ||||
|         group 'root' | ||||
|         mode '0755' | ||||
|         action :create | ||||
|       end | ||||
|  | ||||
|       # this script is called by the main systemd unit file, and | ||||
|       # spins around until the service is actually up and running. | ||||
|       template "/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 | ||||
|  | ||||
|       # this is the main systemd unit file | ||||
|       template "/etc/systemd/system/#{mysql_name}.service" do | ||||
|         path "/etc/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.instance} systemctl daemon-reload]", :immediately | ||||
|         action :create | ||||
|       end | ||||
|  | ||||
|       # avoid 'Unit file changed on disk' warning | ||||
|       execute "#{new_resource.instance} systemctl daemon-reload" do | ||||
|         command '/bin/systemctl daemon-reload' | ||||
|         action :nothing | ||||
|       end | ||||
|  | ||||
|       # tmpfiles.d config so the service survives reboot | ||||
|       template "/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 mysql_name.to_s 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 mysql_name.to_s 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 mysql_name.to_s do | ||||
|         service_name mysql_name | ||||
|         provider Chef::Provider::Service::Systemd | ||||
|         supports restart: true | ||||
|         action :restart | ||||
|       end | ||||
|     end | ||||
|  | ||||
|     action :reload do | ||||
|       # service management resource | ||||
|       service mysql_name.to_s do | ||||
|         service_name mysql_name | ||||
|         provider Chef::Provider::Service::Systemd | ||||
|         action :reload | ||||
|       end | ||||
|     end | ||||
|  | ||||
|     action_class do | ||||
|       def stop_system_service | ||||
|         # service management resource | ||||
|         service '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 mysql_name.to_s 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 | ||||
|   end | ||||
| end | ||||
							
								
								
									
										79
									
								
								ops/cookbooks/vendor/mysql/libraries/mysql_service_manager_sysvinit.rb
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										79
									
								
								ops/cookbooks/vendor/mysql/libraries/mysql_service_manager_sysvinit.rb
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,79 @@ | ||||
| module MysqlCookbook | ||||
|   class MysqlServiceManagerSysvinit < MysqlServiceBase | ||||
|     resource_name :mysql_service_manager_sysvinit | ||||
|  | ||||
|     provides :mysql_service_manager, os: 'linux' | ||||
|  | ||||
|     action :create do | ||||
|       # from base | ||||
|       create_system_user | ||||
|       stop_system_service | ||||
|       create_config | ||||
|       initialize_database | ||||
|       configure_apparmor | ||||
|     end | ||||
|  | ||||
|     action :start do | ||||
|       template "/etc/init.d/#{mysql_name}" do | ||||
|         source 'sysvinit/mysqld.erb' | ||||
|         owner 'root' | ||||
|         group 'root' | ||||
|         mode '0755' | ||||
|         variables( | ||||
|           config: new_resource, | ||||
|           defaults_file: defaults_file, | ||||
|           error_log: new_resource.error_log, | ||||
|           mysql_name: mysql_name, | ||||
|           mysqladmin_bin: mysqladmin_bin, | ||||
|           mysqld_safe_bin: mysqld_safe_bin, | ||||
|           pid_file: new_resource.pid_file, | ||||
|           scl_name: scl_name | ||||
|         ) | ||||
|         cookbook 'mysql' | ||||
|         action :create | ||||
|       end | ||||
|  | ||||
|       service mysql_name do | ||||
|         supports restart: true, status: true | ||||
|         action [:enable, :start] | ||||
|       end | ||||
|     end | ||||
|  | ||||
|     action :stop do | ||||
|       service mysql_name do | ||||
|         supports restart: true, status: true | ||||
|         action [:stop] | ||||
|       end | ||||
|     end | ||||
|  | ||||
|     action :restart do | ||||
|       service mysql_name do | ||||
|         supports restart: true | ||||
|         action :restart | ||||
|       end | ||||
|     end | ||||
|  | ||||
|     action :reload do | ||||
|       service mysql_name do | ||||
|         action :reload | ||||
|       end | ||||
|     end | ||||
|  | ||||
|     action_class do | ||||
|       def stop_system_service | ||||
|         service system_service_name do | ||||
|           supports status: true | ||||
|           action [:stop, :disable] | ||||
|         end | ||||
|       end | ||||
|  | ||||
|       def delete_stop_service | ||||
|         service mysql_name do | ||||
|           supports status: true | ||||
|           action [:disable, :stop] | ||||
|           only_if { ::File.exist?("#{etc_dir}/init.d/#{mysql_name}") } | ||||
|         end | ||||
|       end | ||||
|     end | ||||
|   end | ||||
| end | ||||
							
								
								
									
										103
									
								
								ops/cookbooks/vendor/mysql/libraries/mysql_service_manager_upstart.rb
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										103
									
								
								ops/cookbooks/vendor/mysql/libraries/mysql_service_manager_upstart.rb
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,103 @@ | ||||
| module MysqlCookbook | ||||
|   class MysqlServiceManagerUpstart < MysqlServiceBase | ||||
|     resource_name :mysql_service_manager_upstart | ||||
|  | ||||
|     provides :mysql_service_manager, platform_family: 'debian' do |_node| | ||||
|       Chef::Platform::ServiceHelpers.service_resource_providers.include?(:upstart) && | ||||
|         !Chef::Platform::ServiceHelpers.service_resource_providers.include?(:systemd) && | ||||
|         !Chef::Platform::ServiceHelpers.service_resource_providers.include?(:redhat) && | ||||
|         ::File.exist?('/sbin/status') # Fix for Docker, in 7 and 8 images /sbin/status doesn't exists and Upstart provider doesn't work | ||||
|     end | ||||
|  | ||||
|     action :create do | ||||
|       # from base | ||||
|       create_system_user | ||||
|       stop_system_service | ||||
|       create_config | ||||
|       configure_apparmor | ||||
|       initialize_database | ||||
|     end | ||||
|  | ||||
|     action :start do | ||||
|       template "/usr/sbin/#{mysql_name}-wait-ready" do | ||||
|         source 'upstart/mysqld-wait-ready.erb' | ||||
|         owner 'root' | ||||
|         group 'root' | ||||
|         mode '0755' | ||||
|         variables(socket_file: socket_file) | ||||
|         cookbook 'mysql' | ||||
|         action :create | ||||
|       end | ||||
|  | ||||
|       template "/etc/init/#{mysql_name}.conf" do | ||||
|         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: new_resource.socket_dir | ||||
|         ) | ||||
|         cookbook 'mysql' | ||||
|         action :create | ||||
|       end | ||||
|  | ||||
|       service mysql_name do | ||||
|         provider Chef::Provider::Service::Upstart | ||||
|         supports status: true | ||||
|         action [:start] | ||||
|       end | ||||
|     end | ||||
|  | ||||
|     action :stop do | ||||
|       service mysql_name do | ||||
|         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 mysql_name do | ||||
|         provider Chef::Provider::Service::Upstart | ||||
|         action [:stop, :start] | ||||
|       end | ||||
|     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 mysql_name do | ||||
|         provider Chef::Provider::Service::Upstart | ||||
|         action [:stop, :start] | ||||
|       end | ||||
|     end | ||||
|  | ||||
|     action_class do | ||||
|       def stop_system_service | ||||
|         service system_service_name do | ||||
|           provider Chef::Provider::Service::Upstart | ||||
|           supports status: true | ||||
|           action [:stop, :disable] | ||||
|         end | ||||
|       end | ||||
|  | ||||
|       def delete_stop_service | ||||
|         service mysql_name do | ||||
|           provider Chef::Provider::Service::Upstart | ||||
|           action [:disable, :stop] | ||||
|           only_if { ::File.exist?("#{etc_dir}/init/#{mysql_name}") } | ||||
|         end | ||||
|       end | ||||
|     end | ||||
|   end | ||||
| end | ||||
		Reference in New Issue
	
	Block a user