<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue-Light, Helvetica Neue Light, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px"><div class="" id="yui_3_16_0_1_1439221941996_18380"><span class="" id="yui_3_16_0_1_1439221941996_18382">Hi all,</span></div><div class="" id="yui_3_16_0_1_1439221941996_18380"><span class=""><br></span></div><div class="" id="yui_3_16_0_1_1439221941996_18380" dir="ltr"><span class="" id="yui_3_16_0_1_1439221941996_18715">(I've been away for a couple of weeks and I tried to send this before I left. I didn't see it come through so m</span>y apologies if this is the second time you've seen this.)</div><div class="" id="yui_3_16_0_1_1439221941996_18380" dir="ltr"><br></div><div class="" id="yui_3_16_0_1_1439221941996_18390"><span class="" id="yui_3_16_0_1_1439221941996_18392">I recall markvan mentioning a while ago that there was a need for </span>services to restart when the underlying package changed but the config <span class="" id="yui_3_16_0_1_1439221941996_18400">file didn't. We've got something in place and working that does </span>exactly that. I'd like to get y'all's opinion if it's an ugly kludge or something useful that we might want to refine and contribute back.</div><div class="" id="yui_3_16_0_1_1439221941996_18410"><span class="" id="yui_3_16_0_1_1439221941996_18412"></span><br id="yui_3_16_0_1_1439221941996_18414" class=""></div><div class="" id="yui_3_16_0_1_1439221941996_18416"><span class="" id="yui_3_16_0_1_1439221941996_18418">The basic approach is to look up a given package's version at recipe </span>compile time, and then again at runtime. If the two values are different, then we notify the service to stop. We rely on the main recipe to make sure that the service is started. This avoids multiple restarts if both the package and the config change.</div><div class="" id="yui_3_16_0_1_1439221941996_18436"><span class="" id="yui_3_16_0_1_1439221941996_18438"></span><br id="yui_3_16_0_1_1439221941996_18440" class=""></div><div class="" id="yui_3_16_0_1_1439221941996_18442"><span class="" id="yui_3_16_0_1_1439221941996_18444">For example, we have a library module that contains a routine that </span>does the equivalent of 'rpm -q a <name>'. If the package isn't installed yet, then the library routine will just return an empty string and that'll be different from the post install version.</div><div class="" id="yui_3_16_0_1_1439221941996_18458"><span class="" id="yui_3_16_0_1_1439221941996_18460"></span><br id="yui_3_16_0_1_1439221941996_18462" class=""></div><div class="" id="yui_3_16_0_1_1439221941996_18464"><span class="" id="yui_3_16_0_1_1439221941996_18466">In the recipe itself, we then have the following: (This is from our </span>glance recipe.)</div><div class="" id="yui_3_16_0_1_1439221941996_18472"><span class="" id="yui_3_16_0_1_1439221941996_18474"></span><br id="yui_3_16_0_1_1439221941996_18476" class=""></div><div class="" id="yui_3_16_0_1_1439221941996_18478"><span class="" id="yui_3_16_0_1_1439221941996_18480"># Get access to the library routine that can look up package</span></div><div class="" id="yui_3_16_0_1_1439221941996_18482"><span class="" id="yui_3_16_0_1_1439221941996_18484"># versions. Note that we're including it twice. The first time is</span></div><div class="" id="yui_3_16_0_1_1439221941996_18486"><span class="" id="yui_3_16_0_1_1439221941996_18488"># so that we can get the preinstall version during the compile phase.</span></div><div class="" id="yui_3_16_0_1_1439221941996_18490"><span class="" id="yui_3_16_0_1_1439221941996_18492"># The second include is so that we can check the package version</span></div><div class="" id="yui_3_16_0_1_1439221941996_18494"><span class="" id="yui_3_16_0_1_1439221941996_18496"># during the run-time phase. Yes, we could have done the preinstall check</span></div><div class="" id="yui_3_16_0_1_1439221941996_18498"><span class="" id="yui_3_16_0_1_1439221941996_18500"># at run time and just had one include, but that rubyblock of code is</span></div><div class="" id="yui_3_16_0_1_1439221941996_18502"><span class="" id="yui_3_16_0_1_1439221941996_18504"># more complicated than doing the include.</span></div><div class="" id="yui_3_16_0_1_1439221941996_18506"><span class="" id="yui_3_16_0_1_1439221941996_18508">class ::Chef::Recipe # rubocop:disable Documentation,ClassAndModuleChildren</span></div><div class="" id="yui_3_16_0_1_1439221941996_18510"><span class="" id="yui_3_16_0_1_1439221941996_18512"> include <our special module></span></div><div class="" id="yui_3_16_0_1_1439221941996_18514"><span class="" id="yui_3_16_0_1_1439221941996_18516">end</span></div><div class="" id="yui_3_16_0_1_1439221941996_18518"><span class="" id="yui_3_16_0_1_1439221941996_18520"></span><br id="yui_3_16_0_1_1439221941996_18522" class=""></div><div class="" id="yui_3_16_0_1_1439221941996_18524"><span class="" id="yui_3_16_0_1_1439221941996_18526">class ::Chef # rubocop:disable ClassAndModuleChildren</span></div><div class="" id="yui_3_16_0_1_1439221941996_18528"><span class="" id="yui_3_16_0_1_1439221941996_18530"> class Resource</span></div><div class="" id="yui_3_16_0_1_1439221941996_18532"><span class="" id="yui_3_16_0_1_1439221941996_18534"> class RubyBlock # rubocop:disable Documentation</span></div><div class="" id="yui_3_16_0_1_1439221941996_18536"><span class="" id="yui_3_16_0_1_1439221941996_18538"> include <our special module></span></div><div class="" id="yui_3_16_0_1_1439221941996_18540"><span class="" id="yui_3_16_0_1_1439221941996_18542"> end</span></div><div class="" id="yui_3_16_0_1_1439221941996_18544"><span class="" id="yui_3_16_0_1_1439221941996_18546"> end</span></div><div class="" id="yui_3_16_0_1_1439221941996_18548"><span class="" id="yui_3_16_0_1_1439221941996_18550">end</span></div><div class="" id="yui_3_16_0_1_1439221941996_18552"><span class="" id="yui_3_16_0_1_1439221941996_18554">...</span></div><div class="" id="yui_3_16_0_1_1439221941996_18556"><span class="" id="yui_3_16_0_1_1439221941996_18558"><package install commands></span></div><div class="" id="yui_3_16_0_1_1439221941996_18560"><span class="" id="yui_3_16_0_1_1439221941996_18562">...</span></div><div class="" id="yui_3_16_0_1_1439221941996_18564"><span class="" id="yui_3_16_0_1_1439221941996_18566"># trigger_pkg is the package that we want to check and was picked it up</span></div><div class="" id="yui_3_16_0_1_1439221941996_18568"><span class="" id="yui_3_16_0_1_1439221941996_18570"># from an attribute. We'll call our library routine (this is at compile</span></div><div class="" id="yui_3_16_0_1_1439221941996_18572"><span class="" id="yui_3_16_0_1_1439221941996_18574"># time) and stash the preinstall version.</span></div><div class="" id="yui_3_16_0_1_1439221941996_18576"><span class="" id="yui_3_16_0_1_1439221941996_18578">node.default['openstack']['image']['preinstall'] =</span></div><div class="" id="yui_3_16_0_1_1439221941996_18580"><span class="" id="yui_3_16_0_1_1439221941996_18582"> pkg_version(trigger_pkg)</span></div><div class="" id="yui_3_16_0_1_1439221941996_18584"><span class="" id="yui_3_16_0_1_1439221941996_18586"></span><br id="yui_3_16_0_1_1439221941996_18588" class=""></div><div class="" id="yui_3_16_0_1_1439221941996_18590"><span class="" id="yui_3_16_0_1_1439221941996_18592"># Check the installed version at runtime, after the pkg commands</span></div><div class="" id="yui_3_16_0_1_1439221941996_18594"><span class="" id="yui_3_16_0_1_1439221941996_18596"># have actually run. If there's a change in the version, then tell</span></div><div class="" id="yui_3_16_0_1_1439221941996_18598"><span class="" id="yui_3_16_0_1_1439221941996_18600"># glance to shutdown. It'll get restarted later on and pick up the</span></div><div class="" id="yui_3_16_0_1_1439221941996_18602"><span class="" id="yui_3_16_0_1_1439221941996_18604"># new binaries.</span></div><div class="" id="yui_3_16_0_1_1439221941996_18606"><span class="" id="yui_3_16_0_1_1439221941996_18608">ruby_block 'glance postinstall' do</span></div><div class="" id="yui_3_16_0_1_1439221941996_18610"><span class="" id="yui_3_16_0_1_1439221941996_18612"> block do</span></div><div class="" id="yui_3_16_0_1_1439221941996_18614"><span class="" id="yui_3_16_0_1_1439221941996_18616"> postinstall_version = pkg_version(trigger_pkg)</span></div><div class="" id="yui_3_16_0_1_1439221941996_18618"><span class="" id="yui_3_16_0_1_1439221941996_18620"> preinstall_version = node['openstack']['image']['preinstall']</span></div><div class="" id="yui_3_16_0_1_1439221941996_18622"><span class="" id="yui_3_16_0_1_1439221941996_18624"> Chef::Log.info "preinstall version: #{preinstall_version}"</span></div><div class="" id="yui_3_16_0_1_1439221941996_18626"><span class="" id="yui_3_16_0_1_1439221941996_18628"> Chef::Log.info "postinstall version:#{postinstall_version}"</span></div><div class="" id="yui_3_16_0_1_1439221941996_18630"><span class="" id="yui_3_16_0_1_1439221941996_18632"> if preinstall_version != postinstall_version</span></div><div class="" id="yui_3_16_0_1_1439221941996_18634"><span class="" id="yui_3_16_0_1_1439221941996_18636"> Chef::Log.info 'Stopping glance services'</span></div><div class="" id="yui_3_16_0_1_1439221941996_18638"><span class="" id="yui_3_16_0_1_1439221941996_18640"> resources(service: 'glance-api').run_action(:stop)</span></div><div class="" id="yui_3_16_0_1_1439221941996_18642"><span class="" id="yui_3_16_0_1_1439221941996_18644"> resources(service: 'glance-registry').run_action(:stop)</span></div><div class="" id="yui_3_16_0_1_1439221941996_18646"><span class="" id="yui_3_16_0_1_1439221941996_18648"> else</span></div><div class="" id="yui_3_16_0_1_1439221941996_18650"><span class="" id="yui_3_16_0_1_1439221941996_18652"> Chef::Log.info 'No need to stop glance services'</span></div><div class="" id="yui_3_16_0_1_1439221941996_18654"><span class="" id="yui_3_16_0_1_1439221941996_18656"> end</span></div><div class="" id="yui_3_16_0_1_1439221941996_18658"><span class="" id="yui_3_16_0_1_1439221941996_18660"> end</span></div><div class="" id="yui_3_16_0_1_1439221941996_18662"><span class="" id="yui_3_16_0_1_1439221941996_18664">end</span></div><div class="" id="yui_3_16_0_1_1439221941996_18666"><span class="" id="yui_3_16_0_1_1439221941996_18668"></span><br id="yui_3_16_0_1_1439221941996_18670" class=""></div><div class="" id="yui_3_16_0_1_1439221941996_18672"><span class="" id="yui_3_16_0_1_1439221941996_18674"></span><br id="yui_3_16_0_1_1439221941996_18676" class=""></div><div class="" id="yui_3_16_0_1_1439221941996_18678"><span class="" id="yui_3_16_0_1_1439221941996_18680">That's the basics. Is this worth pursuing? If it seems reasonable then </span>I'll be happy to write up a spec, including any suggestions y'all may have. I.e. there may be some really braindead stuff in there just from my ignorance and flailing around just to make it work. I'm definitely open to suggestions.</div><div class="" dir="ltr" id="yui_3_16_0_1_1439221941996_18694"><span class=""><br></span></div><div class="" dir="ltr" id="yui_3_16_0_1_1439221941996_18694"><span class="">Ken</span></div></div></body></html>