All pastes #2133566 Raw Edit

Mine

public text v1 · immutable
#2133566 ·published 2012-03-29 15:44 UTC
rendered paste body
Patrick G.
7:53 AM
I have my cookbook pretty much there but discovered some really frustrating things about chef
wondering if perhaps you could gander at it?
what I am trying to do is have a recipe that using the template an attributes, changes the my.cnf file to better values. One of those values is changing the innodb log file size
problem with that is that, instead of just restarting mysql you have to stop mysql, remove the old log file, then start mysql
the part where the template is generated normally does the restart
but that doesn't work
so what I try to do is stop the server, remove the file, then have the template call just *start* (not restart) the server
Jon-Paul S.
7:56 AM
I am looking at an urgent problem now. I will likely be an hour before I can get to you. Carry on typing up the problem, and I'll get to it when I can.
Patrick G.
7:56 AM
ok
Patrick G.
7:57 AM
one big monkey wrench is that the template call, even though in the code happens in a sequence that looks like it happens after the removal of the log file, actually happens after everything else according to the log, as if the template call is asyncronous
and if I changed the "notifies" to "start", that start never happens even though the log says it does
Jon-Paul S.
9:24 AM
Sorry - that took a bit longer than expected.
Jon-Paul S.
9:25 AM
OK - so this sounds like it is an issue with delayed notifications and such. Do you have a branch/repository that I can take a look at?
Patrick G.
9:30 AM
yeah
dbaas-chef, mysql-optimisations branch
Jon-Paul S.
10:01 AM
OK - I think I get what is happening with your cookbook.
I think the problem you are seeing is related to the fact that there are 2 passes through a cookbook.
Patrick G.
10:01 AM
ah
I didn't know that
I treat these as scripts
Jon-Paul S.
10:01 AM
The first will execute the ruby code and create a list of resources.
The second will execute the resources.
Patrick G.
10:01 AM
hence the templates
Jon-Paul S.
10:02 AM
So the way chef is intended to work is to have you build a set of resources that represent desired state of the system, then it will execute those resources to effect the changes necessary.
Patrick G.
10:03 AM
I wish there was a way to have a template call do a stop mysql- do something I want it to do - start mysql
vs. atomic restart
Jon-Paul S.
10:04 AM
Yes. And that can be done using notifies :immediately...
Jon-Paul S.
10:05 AM
I'll have a little more of a think, but we want a resource that checks the logfile size, notifies a stop if incorrect. Then a resource that creates the logfiles, and notifies a start if it creates them. Maybe. Have to think about it a little more...
Patrick G.
10:06 AM
really... ?
Jon-Paul S.
10:06 AM
It doesn't help that I don't know what the ib_logfiless are or where they come from...
Patrick G.
10:06 AM
vs. explicit code that does that
I'm so close with this
ib_logfile - undo log
transaction log...
just think of it as that
there are two of them to make rotation painless
Jon-Paul S.
10:07 AM
So they are pre-existing allocated files that mysql uses a byte-pointer in or such...
Patrick G.
10:07 AM
so, innodb is particular
you change the log file size, it won't restart with the old files
they are current 5MB which is terrible default
I want 500MB
Jon-Paul S.
10:08 AM
Ah - got it.
Patrick G.
10:08 AM
well, right now, 5MB is the setting, so if we change it in the my.cnf, server won't restart because the 5MB files are there
Jon-Paul S.
10:08 AM
So it says - "there are files there, and they are the wrong size, therefore I won't start"
Patrick G.
10:08 AM
key is to delete them and then it restarts and recreates them at 500MB
exactly
Jon-Paul S.
10:08 AM
And the filename isn't configurable?
because then you could just use a different/non-existing filename for the restart, and have something that deletes the old 5MB files after the restart...
Side-steps the issue till we can have a good think about a beter solution for them...
Patrick G.
10:09 AM
no
that one is not
Jon-Paul S.
10:10 AM
Doh! Never is that easy 
Patrick G.
10:10 AM
data file you could get away with it
but not log files
Jon-Paul S.
10:12 AM
OK. I at least understand the problem, and I will see if I can think of something that will solve it for you. Gimme a few mins
Patrick G.
10:12 AM
yeah, there is nothing via google search on this
Jon-Paul S.
11:12 AM
So it feels to me like the mysql restart should be wrapped in a definition
Sorry - I mean provider (as it will need to take notifications).
Patrick G.
11:14 AM
I think I would have something that at the os level does: stop mysq; <do your thing> start mysql;
I don't know enough about chef to know where that happens
or how.
Jon-Paul S.
11:14 AM
It may be that bundling a script to wrap the mysql restart is the best thing - you can pass it the expected logfile size...
and write in a language you are comfortable with 
Patrick G.
11:15 AM
do you mean that script would call 'stop mysql; <do thing>; start mysql' ?
Jon-Paul S.
11:16 AM
The other thing is - you can use "ruby_block" http://wiki.opscode.com/display/chef/Resources#Resources-RubyBlock to make your ruby get executed in-line with the resources...
Patrick G.
11:16 AM
hmmm...
Jon-Paul S.
11:16 AM
but yes, it might be the most expedient solution...
Patrick G.
11:16 AM
yes, I like that option
expedients is what I want 
s/ts/t/
Jon-Paul S.
11:17 AM
(to create a script as a file or template provided by the cookbook and executed within a script resource)
http://wiki.opscode.com/display/chef/Resources#Resources-Script
So if you use the script or ruby_block approach, then you should ensure that it only executes when necessary, so performing an only_if <logfile size != expected>
Patrick G.
11:19 AM
ok
Jon-Paul S.
11:19 AM
See here for details: http://wiki.opscode.com/display/chef/Resources#Resources-ConditionalExecution
Patrick G.
11:19 AM
I also want to check the avalue I have in the attributes file vs. how I have it now with explicit value
if it's different than the file being written, then remove the log file
Jon-Paul S.
11:20 AM
Sure.
Patrick G.
11:21 AM
in the template I use: <%= node['mysql']['tunable']['innodb_log_file_size'] %>
now, I use 500M, but I'll have to change it to 5000....k
and make it a string
gah.
that's ok though
just like I do things like default['mysql']['tunable']['innodb_buffer_pool_size'] = (node[:memory][:total].to_i * 0.7).to_i.to_s + 'K'
oh I miss Perl
Jon-Paul S.
11:22 AM
The alternative is to write a function in ruby to do the conversion and call it instead.
Patrick G.
11:22 AM
I'll do the block
Jon-Paul S.
11:22 AM
Ruby comes from perl. I bet there is a ton of stuff like that in standard libraries...
Patrick G.
11:22 AM
that is the easiest for me
what I like is that I can go between strings and numbers without casting
in perl, you can even do things like '500blah' + 2 and it'd give you 502
I'm just old and set in my ways
but I once I figure out the idio syncracies of ruby I'll be ok
Jon-Paul S.
11:24 AM
You can convert an integer to a string by using "#{var_name}"
Patrick G.
11:24 AM
ah
that is good to know
thank you
see, I told you I'd be asking you questions 
Jon-Paul S.
11:25 AM
That can be used to turn the ouput of anything into a string...
I think it effectively runs to_s on the resulting object
Patrick G.
11:25 AM
so, once this works, I create a deploy ticket, associate it with the other nova ticket that tells the story of last week
now, there is another issue
so, if I do something like:
conditional block to stop mysql if logfile change;
template (template has a notifies restart);
conditional block to start mysql if logfile change;
the template part would fail if the first block ran because mysql is stopped
how can I get the restart to be conditional?
have it only notify restart if there was no log file change?
in other words, the restart I do is manual and specific if log file changes, otherwise normal template rewrite and restart of mysql
Jon-Paul S.
11:29 AM
It is possible.
Patrick G.
11:29 AM
or, restart only if already running...
Jon-Paul S.
11:30 AM
You can put the notifies within an if block...
Patrick G.
11:30 AM
ok
I was thinking of having a file in tmp that says "hey, we're in the middle of resizing log file"
if block could be if that file doesn't exist
Jon-Paul S.
11:31 AM
template value_for_platform([ "centos", "redhat", "suse" , "fedora" ] => {"default" => "/etc/my.cnf"}, "default" => "/etc/mysql/my.cnf") do
  source "my.cnf.erb"
  owner "root"
  group "root"
  mode "0644"
  if not :log_file_resizing
    notifies :start, resources(:service => "mysql"), :immediately
  end
end
Hide full text
and set log_file_resizing somewhere...
Patrick G.
11:31 AM
very nice
Jon-Paul S.
11:32 AM
or whatever is going to work 
Patrick G.
11:32 AM
you have saved me hours of work with your advice!
Jon-Paul S.
11:32 AM
You can see that done in the creation of the mysql ervice - the if block changes the resource based on the os.
Patrick G.
11:32 AM
I was flailing last night.
Jon-Paul S.
11:32 AM
That leads to the double run - create the resources, execute the resources...
So think of all of your coding in the cookbook to result in the resources, not the effect on the OS
(if that makes sense)
Patrick G.
11:33 AM
I think
the former being things like 'template' and 'block' ?
Jon-Paul S.
11:34 AM
exactly
Patrick G.
11:34 AM
what do I refer to that as - a template call?
Jon-Paul S.
11:34 AM
The list of resources is here: http://wiki.opscode.com/display/chef/Resources
Patrick G.
11:34 AM
ok "resources"
Jon-Paul S.
11:35 AM
Yes. This wiki page gives a good description of how things work: http://wiki.opscode.com/display/chef/Anatomy+of+a+Chef+Run
Patrick G.
11:36 AM
Ok, I'll take time to read that
work can be a chicken-and-egg because to learn things you need time but time is that thing that is so scarce