using pp to setup mysql

5 views
Skip to first unread message

Emil Tin

unread,
May 3, 2009, 6:57:36 AM5/3/09
to poolp...@googlegroups.com
i'm trying to convert my pp rails example to use mysql instead of sqlite.

here's what my my cloud.rb looks like:


first i tried using include_recipe "mysql::server" in my chef.rb, but for some reason that didn't install mysql at all. doing it in the clouds.rb file instead seems to works:

    has_package "mysql-client"
    has_package "mysql-server"
    has_service "mysql"

mysql gets installed, and i can use the mysql console on the instance.


however, there's a problem. to run rake migration tasks i need the mysql gem. but when i include
    has_gem_package "mysql"
in clouds.rb, the gem fails to build with the message:

*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

(full chef debug: output http://gist.github.com/105942)




another problem seems to be that when using mysql, rake db:create needs to be run initially, before rake db:migrate can be run. has_rails_deploy doesn't seem to do this?

i also don't understand why i need to point to the database.yml file inside has_rails_deploy when it's in the default location config/database.yml ?


any help appreciated! thanks!
emil tin



Ari Lerner

unread,
May 3, 2009, 12:55:09 PM5/3/09
to poolp...@googlegroups.com
Hey Emil,

See inline comments
On May 3, 2009, at 3:57 AM, Emil Tin wrote:

i'm trying to convert my pp rails example to use mysql instead of sqlite.

here's what my my cloud.rb looks like:


first i tried using include_recipe "mysql::server" in my chef.rb, but for some reason that didn't install mysql at all. doing it in the clouds.rb file instead seems to works:

    has_package "mysql-client"
    has_package "mysql-server"
    has_service "mysql"

mysql gets installed, and i can use the mysql console on the instance.

Not entirely certain why mysql doesn't get installed with the chef recipes. I'll check that out later today. Might e a good idea to ask the #chef guys if we aren't around. They are pretty darn knowledgeable about this kind of thing. 


however, there's a problem. to run rake migration tasks i need the mysql gem. but when i include
    has_gem_package "mysql"
in clouds.rb, the gem fails to build with the message:

*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

(full chef debug: output http://gist.github.com/105942)


This is a common error. You need has_package "mysql-devel" (I believe) for the gem.



another problem seems to be that when using mysql, rake db:create needs to be run initially, before rake db:migrate can be run. has_rails_deploy doesn't seem to do this?

i also don't understand why i need to point to the database.yml file inside has_rails_deploy when it's in the default location config/database.yml ?

This is so that it gets placed in the shared directory. If you don't point to it, it shouldn't try to move it.

Hope that helps!
Ari

Jørgen Orehøj Erichsen

unread,
May 3, 2009, 7:07:11 AM5/3/09
to poolp...@googlegroups.com
Hi Emil,

I think you need to add the libmysqlclient15-dev package as the native
MySQL ruby gem has some native dependencies found in that package.

/Jørgen

Ari Lerner

unread,
May 3, 2009, 12:58:00 PM5/3/09
to poolp...@googlegroups.com
Oh yes, I'm wrong:

it's 

has_package "libmysqlclient5-dev"

I should use google better

Hope that helps,
Ari

On May 3, 2009, at 3:57 AM, Emil Tin wrote:

Ian Kallen

unread,
May 3, 2009, 1:18:26 PM5/3/09
to poolp...@googlegroups.com
This looks like a chef issue, not a poolparty one. FWIW, my CentOS EC2
AMI's have the MySQL binaries and libraries burned in instead of
provisioned on demand (I'm not using pp for this stuff yet, just chef).
The primary reason was that I needed MySQL 5.1.34 RPMs (not on any well
known yum repos) and secondarily (pertinent to the issue in your gist)
the gem's build incantation needed to look like this

gem install mysql -- --with-mysql-lib=/usr/lib.mysql
--with-mysql-include=/usr/include/mysql

...if you can pass chef's gem resource custom build params, I couldn't
find examples of it or docs to reflect that. If you know how to
parameterize the gem resource, please post details!
-Ian

Emil Tin wrote:
> i'm trying to convert my pp rails example to use mysql instead of sqlite.
>
> here's what my my cloud.rb looks like:
> http://github.com/emiltin/poolparty_example/blob/4c5a6273c60c06078d311f32c8d1171ba70571ea/config/poolparty/clouds.rb
>
>
> first i tried using include_recipe "mysql::server" in my chef.rb, but
> for some reason that didn't install mysql at all. doing it in the
> clouds.rb file instead seems to works:
>
> has_package "mysql-client"
> has_package "mysql-server"
> has_service "mysql"
>
> mysql gets installed, and i can use the mysql console on the instance.
>
>
> however, there's a problem. to run rake migration tasks i need the
> mysql gem. but when i include
> has_gem_package "mysql"
> in clouds.rb, the gem fails to build with the message:
>
> *** extconf.rb failed ***
> Could not create Makefile due to some reason, probably lack of
> necessary libraries and/or headers. Check the mkmf.log file for more
> details. You may need configuration options.
>
> (full chef debug: output http://gist.github.com/105942)
> <http://gist.github.com/105942%29>
>
>
>
>
> another problem seems to be that when using mysql, rake db:create
> needs to be run initially, before rake db:migrate can be run.
> has_rails_deploy doesn't seem to do this?
>
> i also don't understand why i need to point to the database.yml file
> inside has_rails_deploy when it's in the default location
> config/database.yml ?
>
>
> any help appreciated! thanks!
> emil tin
>
>
>
>
> >


--
Ian Kallen
blog: http://www.arachna.com/roller/spidaman
tweetz: http://twitter.com/spidaman
vox: 415.505.5208

Emil Tin

unread,
May 3, 2009, 2:31:08 PM5/3/09
to poolp...@googlegroups.com
thanks guys. now i have mysql running.

but i'm left with the problem that rake db:migrate fails because rake db:create is never run, so the mysql db doesn't exist yet:

67.202.25.250 stderr => rake aborted!67.202.25.250 stderr => 
67.202.25.250 stderr => Unknown database 'my_app'67.202.25.250 stderr => 

this must be an issue with has_rails_deploy? or chef_deploy?



how can i make sure the rake db:create is called if the relevant db hasn't been created yet? as a workaround i think it wouldn't hurt to call rake db:create everytime.



-emil



ps: in facts it's not libmysqlclient5-dev, but libmysqlclient15-dev, as jørgen wrote..

Ari Lerner

unread,
May 3, 2009, 3:05:18 PM5/3/09
to poolp...@googlegroups.com, poolp...@googlegroups.com
You can add an exec that doesn't execute (has_exec "execname", action=> nothing) until after rails deploy. (notifies => "execname")

Sent from my iPhone

Emil Tin

unread,
May 3, 2009, 3:10:29 PM5/3/09
to poolp...@googlegroups.com

interesting, but would the migration still fail since it's done by the rails deploy?

Ari Lerner

unread,
May 3, 2009, 3:28:19 PM5/3/09
to poolp...@googlegroups.com
Yikes, you could do it after any has_ before the deploy

Sent from my iPhone

Emil Tin

unread,
May 3, 2009, 4:35:53 PM5/3/09
to poolp...@googlegroups.com


you mean i can it after any has_.....  but before the has_rails_deploy block?

i don't think i can do it before deploy, because the rails app (and a path to the current release) is needed to run rake db:migrate.

Ari Lerner

unread,
May 3, 2009, 6:54:26 PM5/3/09
to poolp...@googlegroups.com
Try adding to the deploy options

Sent from my iPhone

Emil Tin

unread,
May 3, 2009, 7:26:22 PM5/3/09
to poolp...@googlegroups.com
thanks for the suggestion. i'm not quite sure what you mean. i tried: 

    has_rails_deploy "my_app" do
      ...
      migration_command "rake db:create && rake db:migrate"
    end

but it doesn't have any effect.  i looked at the source for rails deploy and chef deploy, and it looks like options passed to rails deploy are not passed on to chef deploy. auser-poolparty-extensions-0.0.3/lib/extensions/rails_deploy.rb, line 46:

        dopts = options.choose {|k,v| [:repo, :user].include?(k)}
        has_chef_deploy dopts.merge(:name => "#{release_directory}")


if i modify the code to

        dopts = options.choose {|k,v| [:repo, :user, :migration_command].include?(k)}

the migration_command gets through to chef deploy, but still fails, since it's run as 

RAILS_ENV=production rake db:create && rake db:migrate

which fails because RAILS_ENV is not set when db:migrate runs, so it defaults to development and bombs out.


i guess i could create a custom rake task that would call the db creata and then migration, but that seems insane.


emil

Venkata Pingali

unread,
May 4, 2009, 11:46:23 AM5/4/09
to Poolpartyrb

I think PP has its strengths in the host management. Application
lifecycle requires a different set of capabilities.

An approach that might be more interesting is to figure out how
to make capistrano work with PP.
> > On May 3, 2009, at 1:35 PM, Emil Tin <e...@koblo.com> wrote:
>
> >> you mean i can it after any has_.....  but before the  
> >> has_rails_deploy block?
>
> >> i don't think i can do it before deploy, because the rails app (and  
> >> a path to the current release) is needed to run rake db:migrate.
>
> >> On 03/05/2009, at 21.28, Ari Lerner wrote:
>
> >>> Yikes, you could do it after any has_ before the deploy
>
> >>> Sent from my iPhone
>
> >>> On May 3, 2009, at 12:10 PM, Emil Tin <e...@koblo.com> wrote:
>
> >>>> interesting, but would the migration still fail since it's done  
> >>>> by the rails deploy?
>
> >>>> On 03/05/2009, at 21.05, Ari Lerner wrote:
>
> >>>>> You can add an exec that doesn't execute (has_exec "execname",  
> >>>>> action=> nothing) until after rails deploy. (notifies =>  
> >>>>> "execname")
>
> >>>>> Sent from my iPhone
>
> >>>>>>>>http://github.com/emiltin/poolparty_example/blob/4c5a6273c60c06078d31...
>
> >>>>>>>> first i tried using include_recipe "mysql::server" in my  
> >>>>>>>> chef.rb, but for some reason that didn't install mysql at  
> >>>>>>>> all. doing it in the clouds.rb file instead seems to works:
>
> >>>>>>>>     has_package "mysql-client"
> >>>>>>>>     has_package "mysql-server"
> >>>>>>>>     has_service "mysql"
>
> >>>>>>>> mysql gets installed, and i can use the mysql console on the  
> >>>>>>>> instance.
>
> >>>>>>>> however, there's a problem. to run rake migration tasks i  
> >>>>>>>> need the mysql gem. but when i include
> >>>>>>>>     has_gem_package "mysql"
> >>>>>>>> in clouds.rb, the gem fails to build with the message:
>
> >>>>>>>> *** extconf.rb failed ***
> >>>>>>>> Could not create Makefile due to some reason, probably lack of
> >>>>>>>> necessary libraries and/or headers.  Check the mkmf.log file  
> >>>>>>>> for more
> >>>>>>>> details.  You may need configuration options.
>
> >>>>>>>> (full chef debug: outputhttp://gist.github.com/105942)
Reply all
Reply to author
Forward
0 new messages