-
-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change of port number should restart mysqld #5
Comments
In theory, you're right! But in fact, i found a little bit risky to do a service restart when config file change. Some users (including me) used to have the chef-client service or cron locally. And i do not want the recipe to restart services, until it's absolutely needed. When the port change, yes it's needed, but i do not know how to check if only one attribute has changed... There's some minor changes on the config file for which i do not want to restart the service. If you have an idea on how to do it... I will be very happy to implement it, or to merge it if you want. |
Here is what I put in my recipe as a workaround: # restart to ensure the server is listening to the new port service 'mysql' do action :restart not_if { is_port_open?('127.0.0.1', node['mariadb']['mysqld']['port']) } end |
Not so ugly... Will try to create a helper which can decide wether to restart the service or not. I think that in the future some others attributes will have the same problem (like the unix socket path). |
A helper function to determine if the service needs to be restarted would be great. # Helper methods for use in templates and recipes # Use in recipes with: # ::Chef::Recipe.send(:include, MariaDB::Helper) module MariaDB module Helper require 'socket' require 'timeout' def is_port_open?(ip, port) begin Timeout::timeout(1) do begin s = TCPSocket.new(ip, port) s.close return true rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH return false end end rescue Timeout::Error end return false end end end |
Will commit something you could test as soon as all tests passed on my laptop. |
- Fix issue #5 - Add a create directory missing under CentOS
Now, i have a problem to test with chefspec... I don't know how to mock properly a Class method. If you have an idea... But the code itself must work. |
Thanks Nicolas for quick fix, the restart trigger works great by my side :) Since ChefSpec is running an in-memory representation without deploying the real mysqld service, I don't think it can check if a port is listening (this is for serverspec). Below is a dirty workaround that will trigger a restart each time the helper method is invoked in a ChefSpec environment, and then make test pass. def do_port_connect(ip, port) return false if defined?(ChefSpec) [...] end |
Ok, i did a good test finally. All tests went fine. I releaased the recipe after the resolution of the issue #4 |
Avoid normal attributes where simple override works
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
When
node['mariadb']['mysqld']['port']
is set to another value, the service still listens to the default port 3306. We have to restart the service to get it apply. The server or config recipe should notify the service to restart.The text was updated successfully, but these errors were encountered: