application config in recipe during configure event

Stefan Krause's Avatar

Stefan Krause

30 Nov, 2011 01:00 PM via web

I have a recipe:

include_recipe "deploy"

node[:deploy].each do |application, deploy|
  # this will not be executed
end

The each block will not be executed despite one application is deployed. How do I get the configuration of the deployed apps during the execution of a configure event. Even if the recipe is been executed manually via the scalarium web interface node[:deploy] seems to be empty.

In order to make the case more clear I give you some more context.

I have a rails application that needs to access one or more redundant search servers. The list of available search servers is configured in a file config/search.yml in the application directory. The content depends on the actual cloud configuration.

I have a custom recipe myapp::configure that takes the current list of instances with the role 'search' and writes this to the shared/config/search.yml of every installed application.

In the deploy/before_symlink.rb callback of the application a symbolic link will be created:

cd #{release_path}/config && ln -nfs ../../../shared/config/search.yml search.yml

This way every new deployment will link to the current configuration that is contained in shared/config/search.yml.

When the cloud configuration changes the content of shared/config/search.yml has to be updated and all applications have to be restarted. As far as I understood I have to put the custom recipe into the run list for the configure event. Here is the simplified content of the recipe (made after the redis::configure_client example from the knowledge base):

include_recipe "deploy"

node[:deploy].each do |application, deploy|
  execute "restart Rails app #{application}" do
    cwd deploy[:current_path]
    command node[:scalarium][:rails_stack][:restart_command]
    action :nothing
  end

  template "#{deploy[:deploy_to]}/shared/config/search.yml" do
    source "search.yml.erb"
    variables(:hosts => node[:scalarium][:roles][:search][:instances].keys)
    mode "0660"
    group deploy[:group]
    owner deploy[:user]
    notifies :run, resources(:execute => "restart Rails app #{application}")
    only_if { File.exists?("#{deploy[:deploy_to]}/shared/config/") }
  end
end

It seems as the node[:deploy] hash is empty during the execution of the recipe at the configure event.

So here are my questions:

Where should I put the recipe in order to have it run at the first deploy during the setup of the app server instance and to have it run at every configuration change.

How do I get the list of deployed applications in each of these cases in order to put the search.yml into each of their shared/config directories and in order to trigger a restart of each of those applications.

If you have a better idea how to achieve my dynamic search server configuration then I would like to get a hint.

  1. Support Staff 2 Posted by Jonathan Weiss on 02 Dec, 2011 10:38 AM

    Jonathan Weiss's Avatar

    Your approach is totally correct.

    Putting the recipe on configure should be enough as immediately after the setup, all instances get a configure. Alternatively you can also put in on setup.

    It is very strange that node[:deploy] is empty. Usually node[:deploy] lists on configure and setup all applications and on deploy only the only actually being deployed right now.

    Are you overriding node[:deploy] somehow? Either in attributes or custom JSON?
    If this would be broken globally many installations would not work so I assume it is somehow related to your recipes/attributes/custom JSON.

    On which Cloud / role / instance is this happening?

  2. 3 Posted by Stefan Krause on 02 Dec, 2011 04:03 PM

    Stefan Krause's Avatar

    clouds/a08aa20cce27a913c2be7c7a72b903ae

    There is just one instance defined. The recipe defined at the rails application server's configure event gets an empty node[:deploy]. The same happens, when I launch the recipe via the Actions->ExecuteRecipes menu.

  3. Support Staff 4 Posted by Jonathan Weiss on 02 Dec, 2011 10:00 PM

    Jonathan Weiss's Avatar

    I can't image the sent down JSON to really have an empty node[:deploy] - have you looked into the actual json file in /root/scalarium-agent/log/chef?

    If the data is in there is has to be related to your recipes. Can I trigger configure-events tomorrow for testing?

  4. 5 Posted by Stefan Krause on 03 Dec, 2011 11:04 AM

    Stefan Krause's Avatar

    Yes, it's ok to test run the configure recipes. Please give me a note, when you're done. So I can check if everything is still running smoothly. It is a demo cloud that is not used for real customer tenants.

  5. 6 Posted by Stefan Krause on 14 Dec, 2011 10:28 PM

    Stefan Krause's Avatar

    now I have another situation, where node[:deploy] seems to be empty. I think it is a general problem. I run the configure recipe manually and the node[:deploy] seems to be empty.

  6. Support Staff 7 Posted by Jonathan Weiss on 14 Dec, 2011 10:51 PM

    Jonathan Weiss's Avatar

    which cloud and instance? same one?

  7. 8 Posted by Stefan Krause on 16 Dec, 2011 08:07 AM

    Stefan Krause's Avatar

    No, it was a different cloud, but the same recipe. Now I manually executed the recipe at the same cloud. node[:deploy] was empty, too.

    cloud: a08aa20cce27a913c2be7c7a72b903ae
    (single) instance: 55dbcede2e66a67091891924ee92b6aa

    I used "Execute Recipies" from the cloud actions menu.

    the log files from this execution are:

    /root/scalarium-agent/log/chef/2011-12-16-07-55-25.json /root/scalarium-agent/log/chef/2011-12-16-07-55-25.log

  8. Support Staff 9 Posted by Jonathan Weiss on 16 Dec, 2011 03:39 PM

    Jonathan Weiss's Avatar

    Can I login into the instance in order to have access to the log files?

  9. 10 Posted by Stefan Krause on 16 Dec, 2011 07:32 PM

    Stefan Krause's Avatar

    Yes, please.

  10. 11 Posted by adrien on 13 Jan, 2012 01:59 PM

    adrien's Avatar

    Hi, i also have a configure recipe having the same problem.

    In the recipe, the node[:deploy] has data only when the recipe is executed with the deploy event (When i use "Execute recipes" this is empty and my code isn't executed).

  11. 12 Posted by adrien on 17 Jan, 2012 05:56 PM

    adrien's Avatar

    When i use the "Trigger configure" on the instance view, it works fine.

    I checked the log, and when i use "Execute recipe" with my configure, the json data contains everything except the :deploy dictionnary.

  12. 13 Posted by Thomas Witt on 03 May, 2012 01:31 PM

    Thomas Witt's Avatar

    Any progress on this issue? I am having the same Problem. The initial deploy doesn't execute my code, resulting in a broken rails app after restart. Only after a manual deploy the deploy recipe will be executed correctly. This makes the auto healing of scalarium for this server unusable.

    (Cloud ID: 33c910bea9303a5664c2e15d90984253)

  13. Support Staff 14 Posted by Jonathan Weiss on 03 May, 2012 01:52 PM

    Jonathan Weiss's Avatar

    @Thomas: What you describe sounds like a very different thing. The above problem is about differences between "configure" and "execute recipes".

    Did you register your recipe also on setup or only on deploy?

  14. 15 Posted by Thomas Witt on 03 May, 2012 02:05 PM

    Thomas Witt's Avatar

    nope, they're only registered on deploy. But because I turned "deploy applications on boot" to on, I thought the deploy recipes will also be run at the initial deploy on boot time?

  15. Support Staff 16 Posted by Jonathan Weiss on 03 May, 2012 04:28 PM

    Jonathan Weiss's Avatar

    No, you have to register them on setup too. Currently only the scalarium deploy ones will be executed on setup too.

    We will clean this up in the future but this is not trivial as many customers depend on the current implementation.

Reply to this discussion

Internal reply

Formatting help or Preview

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.