Skip to content

Cookbook

Sven Pachnit edited this page Apr 10, 2018 · 1 revision

Cookbook

Check if local MySQL is running

If you are like me and have you development DB not running at all times you might find it annoying to dump and download a huge file to find out it can't import. Put this snippet into your config.rb:

# Check local MySQL server is running before attempting to suck anything
def _suck_variation identifier, ctn, variation, var
  Open3.popen2e(%{#{ctn.local_client_call} -N -e 'SHOW DATABASES;'}, pgroup: true) do |_stdin, _stdouterr, _thread|
    _stdin.close
    exit_code = _thread.value
    result = _stdouterr.read.chomp.downcase
    if result["can't connect to local mysql server"]
      abort "Local MySQL server is not running!"
    end
  end if ctn
  super
end
Clone this wiki locally