#
# Cookbook:: irrigate-mysql
# Recipe:: default
#
# Copyright:: (C) The Orchard
#
# All rights reserved - Do Not Redistribute
#
# Determine the service name based on the operating system.
# In Debian, the MySQL service is named mysql.service instead of mysqld.service
service_name = node['platform'] == 'debian' ? 'mysql' : 'mysqld'

user_ulimit 'mysql' do
  filehandle_limit node['mysql']['ulimit']['nofile']
end

# Add systemd drop-in file to control ulimit parameters.
directory "/etc/systemd/system/#{service_name}.service.d" do
  action :create
end

# Reload systemd units if drop-in is added/changed.
execute 'reload_systemd_service' do
  command '/bin/systemctl daemon-reload'
  timeout 10
  action :nothing
end

# This might otherwise also immediately restart the mysql service, but
# in a production setting that is probably a bad idea.
template "/etc/systemd/system/#{service_name}.service.d/#{service_name}.conf" do
  source 'mysqld_systemd_dropin.conf.erb'
  mode '0640'
  notifies :run, 'execute[reload_systemd_service]', :immediately
end
