Skip to content

Commit

Permalink
Push what I've got but we're looking at a table flip
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Webb <[email protected]>
  • Loading branch information
damacus committed May 2, 2024
1 parent 0b258d9 commit 6fb5bb8
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 243 deletions.
3 changes: 1 addition & 2 deletions libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,7 @@ def mysqld_bin
end

def mysql_systemd_start_pre
return '/usr/bin/mysqld_pre_systemd' if el7? || el8? || fedora?
return '/usr/bin/mysql-systemd-start pre' if platform_family?('rhel')
return '/usr/bin/mysqld_pre_systemd' if el7? || el8? || fedora? || platform_family?('rhel')
return '/usr/lib/mysql/mysql-systemd-helper install' if suse?

'/usr/share/mysql/mysql-systemd-start pre'
Expand Down
22 changes: 6 additions & 16 deletions libraries/mysql_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ class MysqlService < MysqlServiceBase

# installation type and service_manager
property :install_method, %w(package auto none), 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: '8.0', 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], desired_state: false
property :package_options, String, desired_state: false
property :package_version, String, desired_state: false

################
# Helper Methods
Expand All @@ -24,13 +23,12 @@ def copy_properties_to(to, *properties)
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
to.send(p, send(p)) if to.class.properties.include?(p) && property_is_set?(p)
end
end

action_class do
# rubocop:disable Metrics/MethodLength
def installation(&block)
case new_resource.install_method
when 'auto'
Expand All @@ -44,18 +42,10 @@ def installation(&block)
copy_properties_to(install)
install
end
# rubocop:enable Metrics/MethodLength

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
svc = mysql_service_manager_systemd(new_resource.name, &block)
copy_properties_to(svc)
svc
end
Expand Down
33 changes: 17 additions & 16 deletions libraries/mysql_service_manager_systemd.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# rubocop:disable Style/FrozenStringLiteralComment
module MysqlCookbook
# rubocop:disable Metrics/ClassLength, Style/Documentation
class MysqlServiceManagerSystemd < MysqlServiceBase
resource_name :mysql_service_manager_systemd
provides :mysql_service_manager_systemd
Expand All @@ -16,6 +18,7 @@ class MysqlServiceManagerSystemd < MysqlServiceBase
initialize_database
end

# rubocop:disable Metrics/BlockLength
action :start do
# Needed for Debian / Ubuntu
directory '/usr/libexec' do
Expand All @@ -38,24 +41,19 @@ class MysqlServiceManagerSystemd < MysqlServiceBase
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"
# Use an override.conf so that we override the values we care about and
# let the package do the heavy lifting
# this stops us from breaking during upgrades as we have done before
template '/etc/systemd/system/mysqld.service.d/override.conf' do
path '/etc/systemd/system/mysqld.service.d/override.conf'
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,
mysql_systemd_start_pre: mysql_systemd_start_pre,
mysql_systemd: mysql_systemd
)
variables(config: new_resource)
cookbook 'mysql'
notifies :run, "execute[#{new_resource.instance} systemctl daemon-reload]", :immediately
action :create
action :nothing
end

# avoid 'Unit file changed on disk' warning
Expand Down Expand Up @@ -85,17 +83,18 @@ class MysqlServiceManagerSystemd < MysqlServiceBase
service_name mysql_name
provider Chef::Provider::Service::Systemd
supports restart: true, status: true
action [:enable, :start]
action %i[enable start]
end
end
# rubocop:enable Metrics/BlockLength

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]
action %i[disable stop]
only_if { ::File.exist?("/usr/lib/systemd/system/#{mysql_name}.service") }
end
end
Expand Down Expand Up @@ -126,7 +125,7 @@ def stop_system_service
service_name system_service_name
provider Chef::Provider::Service::Systemd
supports status: true
action [:stop, :disable]
action %i[disable stop]
end
end

Expand All @@ -136,10 +135,12 @@ def delete_stop_service
service_name mysql_name
provider Chef::Provider::Service::Systemd
supports status: true
action [:disable, :stop]
action %i[disable stop]
only_if { ::File.exist?("/usr/lib/systemd/system/#{mysql_name}.service") }
end
end
end
end
# rubocop:enable Metrics/ClassLength, Style/Documentation
end
# rubocop:enable Style/FrozenStringLiteralComment
80 changes: 0 additions & 80 deletions libraries/mysql_service_manager_sysvinit.rb

This file was deleted.

104 changes: 0 additions & 104 deletions libraries/mysql_service_manager_upstart.rb

This file was deleted.

18 changes: 0 additions & 18 deletions templates/default/systemd/mysqld.service.erb
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
[Unit]
Description=mysql_service[mysql-<%= @config.instance %>]
After=syslog.target
After=network.target

[Service]
Type=simple
User=<%= @config.run_user %>
Group=<%= @config.run_group %>
PermissionsStartOnly=true
ExecStartPre=<%= @mysql_systemd_start_pre %>

ExecStart=<%= @mysqld_bin %> --defaults-file=<%= @etc_dir %>/my.cnf --basedir=<%= @base_dir %>
ExecStartPost=<%= @mysql_systemd %>
TimeoutSec=300
Restart=on-failure
RuntimeDirectory=mysqld
RuntimeDirectoryMode=755

[Install]
WantedBy=multi-user.target
2 changes: 0 additions & 2 deletions test/cookbooks/test/recipes/user_database.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
::Chef::DSL::Recipe.include MysqlCookbook::HashedPassword::Helper

include_recipe 'test::yum_repo'

# variables
root_pass = 'arandompassword'

Expand Down
10 changes: 5 additions & 5 deletions test/cookbooks/test/recipes/yum_repo.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Before that, we use "native" versions

# unless node['mysql_test'].nil? || platform_family?('debian')
# yum_mysql_community_repo 'mysql_repo' do
# version node['mysql_test']['version']
# end
# end
unless node['mysql_test'].nil? || platform_family?('debian')
yum_mysql_community_repo 'mysql_repo' do
version node['mysql_test']['version']
end
end

0 comments on commit 6fb5bb8

Please sign in to comment.