Skip to content
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

Closed
stissot opened this issue Sep 15, 2014 · 9 comments
Closed

Change of port number should restart mysqld #5

stissot opened this issue Sep 15, 2014 · 9 comments
Assignees
Milestone

Comments

@stissot
Copy link
Contributor

stissot commented Sep 15, 2014

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.

@sinfomicien
Copy link
Contributor

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.

@stissot
Copy link
Contributor Author

stissot commented Sep 15, 2014

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

@sinfomicien
Copy link
Contributor

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).

@stissot
Copy link
Contributor Author

stissot commented Sep 15, 2014

A helper function to determine if the service needs to be restarted would be great.
Here is the helper function to check if a tcp socket is listening

# 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

@sinfomicien
Copy link
Contributor

Will commit something you could test as soon as all tests passed on my laptop.

sinfomicien added a commit that referenced this issue Sep 16, 2014
- Fix issue #5
- Add a create directory missing under CentOS
@sinfomicien
Copy link
Contributor

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.

@stissot
Copy link
Contributor Author

stissot commented Sep 17, 2014

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

@stissot stissot closed this as completed Sep 17, 2014
@sinfomicien
Copy link
Contributor

Ok, i did a good test finally. All tests went fine. I releaased the recipe after the resolution of the issue #4

@sinfomicien sinfomicien added this to the v0.2.3 milestone Sep 19, 2014
@sinfomicien sinfomicien self-assigned this Sep 19, 2014
jfwm2 pushed a commit to jfwm2/mariadb that referenced this issue Apr 4, 2017
Avoid normal attributes where simple override works
@lock
Copy link

lock bot commented Jul 24, 2018

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.

@lock lock bot locked as resolved and limited conversation to collaborators Jul 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants