application config in recipe during configure event
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.
Support Staff 2 Posted by Jonathan Weiss on 02 Dec, 2011 10:38 AM
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?
3 Posted by Stefan Krause on 02 Dec, 2011 04:03 PM
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.
Support Staff 4 Posted by Jonathan Weiss on 02 Dec, 2011 10:00 PM
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?
5 Posted by Stefan Krause on 03 Dec, 2011 11:04 AM
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.
6 Posted by Stefan Krause on 14 Dec, 2011 10:28 PM
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.
Support Staff 7 Posted by Jonathan Weiss on 14 Dec, 2011 10:51 PM
which cloud and instance? same one?
8 Posted by Stefan Krause on 16 Dec, 2011 08:07 AM
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.logSupport Staff 9 Posted by Jonathan Weiss on 16 Dec, 2011 03:39 PM
Can I login into the instance in order to have access to the log files?
10 Posted by Stefan Krause on 16 Dec, 2011 07:32 PM
Yes, please.
11 Posted by adrien on 13 Jan, 2012 01:59 PM
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).
12 Posted by adrien on 17 Jan, 2012 05:56 PM
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.
13 Posted by Thomas Witt on 03 May, 2012 01:31 PM
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)
Support Staff 14 Posted by Jonathan Weiss on 03 May, 2012 01:52 PM
@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?
15 Posted by Thomas Witt on 03 May, 2012 02:05 PM
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?
Support Staff 16 Posted by Jonathan Weiss on 03 May, 2012 04:28 PM
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.
17 Posted by André Wendt on 05 Jun, 2012 07:33 AM
I have a similar problem: instance 23d1135cb36bebcb749394b0e8cc00a6 fails on setup because
node[:deploy]is empty. I stopped and started the instance twice, no luck. Another instance in the same cloud (f9e2298bcceea81ff513ca35882972da) is setting up just fine, and my tests were running the same cookbooks several times without any failures on setup.I didn't change the custom JSON between those setups.
The only difference I can think of between the instances that are setting up and the ones that fail setup is: The successful setup are all happening on instances that were created later. Is it possible that they are running an updated version of the Scalarium client? If it is, then I would just delete and re-create the instance.
This is urgent as I now have a cloud with 1 instance running updated cookbooks, a failed one and another one with outdated cookbooks.
Support Staff 18 Posted by Daniel Hüsch on 05 Jun, 2012 07:55 AM
The instances seem to be running the same agent version, but we found another difference. The instance that's failing has 'Auto Deploy' set to 'No'. Setting it to 'Yes' should add and populate the
node[:deploy]tree.19 Posted by André Wendt on 05 Jun, 2012 08:25 AM
Setting 'Auto Deploy' to 'Yes' worked, the instance set up alright. Thanks for the quick reply!