[chef] Re: Re: Re: mysql recipe on ubuntu


Chronological Thread 
  • From: Ranjib Dey < >
  • To:
  • Subject: [chef] Re: Re: Re: mysql recipe on ubuntu
  • Date: Mon, 22 Aug 2011 16:24:12 +0530



On Mon, Aug 22, 2011 at 2:57 PM, Raphael Bauduin < "> > wrote:
Hi Madhurranjan,

On Thu, Aug 18, 2011 at 8:20 PM, Madhurranjan Mohaan
< "> > wrote:
> Hi Raphael,
> Not sure if this would help your case but this is more for a centos
> installation .We had trouble to make sure that we assign the password only
> the first time and do certain checks. Basically we wanted it to be
> idempotent. We used something to this effect:. It wouldn't enter this block
> if mysql server was already installed and we added definitions to
> create/delete DBs and modify passwords.

thanks, but this does not apply to my problem. I need the recipe to
wait until the mysql server is ready.

Raph


Hi Raph,
you can use this ruby_block resource for that:

ruby_block "wait for mysql to come up" do
 block do
  my_sock = TCPSocket.new('127.0.0.1', 3306)
        readable = IO.select([my_sock], nil, nil, 5)
        if readable
          puts ("mysql  accepting connections on  banner is #{my_sock.gets}")
          true
        else
          false
        end
      rescue 
          Chef::Log.info ("mysql is not awake after 5 seconds ")
      ensure
        my_sock && my_sock.close
      end
 end
end

but this block is not idempotent, and will be executed in every run, you may use the not_if {`ps --no-headers -C mysqld`} to make this idempotent  , or set the action to :nothing and notify this resource from some other resource with action run.

hope this helps
ranjib

> if ! File.exists?("/var/lib/mysql/mysql/user.MYD")
>   package "mysql-server" do
>         action :install
>   end
>   service "mysqld" do
>         action [:start,:enable]
>   end
>   execute "creating 'mysqladmin' required files at '/var/lib/mysql'" do
>     command "/etc/init.d/mysqld restart >> /tmp/mysql.log"
>   end
>   execute "set_password" do
>     command "<set password>"
>   end
> end
> thanks
> Madhurranjan
> On Thu, Aug 18, 2011 at 1:52 PM, Raphael Bauduin < "> > wrote:
>>
>> Hi,
>>
>> I'm using the mysql recipe (
>> https://github.com/opscode/cookbooks/tree/master/mysql ) with vagrant
>> and ubuntu 10.04.
>> The problem I encounter is that this code
>>
>> execute "mysql-install-privileges" do
>>  command "/usr/bin/mysql -u root
>> #{node['mysql']['server_root_password'].empty? ? '' : '-p'
>> }#{node['mysql']['server_root_password']} < #{grants_path}"
>>  action :nothing
>>  subscribes :run, resources("template[#{grants_path}]"), :immediately
>> end
>>
>> is run when the mysql daemon is not yet ready. In my own recipe, I
>> have put this code to wait for mysqld:
>>
>> execute "wait for mysql" do
>>  action :run
>>  command "i=0 && while ! ps ax | grep mysqld | grep -v grep ; do echo
>> \"waiting.... $i\" >> /tmp/debug ; sleep 1; i=$((i+1)); [ $i -eq 29 ]
>> && break; done ;  sleep 5; exit 0"
>> end
>>
>> but this approach won't work as mysql-install-privileges is run by a
>> "subscribes :run".
>>
>> Is there a way to tell an execute block to wait for a certain
>> condition? Or am I doing something wrong here, as the recipe is
>> indicated as being tested with ubuntu 10.04?
>>
>> Thanks
>>
>> raphaël
>
>



--
Web database: http://www.myowndb.com
Free Software Developers Meeting: http://www.fosdem.org




Archive powered by MHonArc 2.6.16.

§