On 12/06/2009, at 6:56 AM, Jeppe Nejsum Madsen wrote: Hi,
So, next step is to try to speed up my recipes and I'm running into a few areas where I don't think I fully understand how things are supposed to work:
remote_file "war" do path "/usr/share/jetty6/webapps/ROOT.war" owner "jetty" mode 0640 source node[:war] notifies :restart, resources(:service => "jetty6") end
I would assume Chef would either a) Start the jetty6 service if it was not running or b) restart the jetty6 service if it was running already And only do this if the remote file has changed.
Restart only fires if the service is currently running - sorry for pasting this code in line, but it helps me illustrate.
def action_restart if @current_resource.running Chef::Log.debug("#{@new_resource}: attempting to restart") status = restart_service() if status Chef::Log.info("#{@new_resource}: restarted successfully") end end end
If the service is actually running, in priority, the following things are checked: - If the resource has a 'restart_command' parameter set, run that. - If the resource supports :restart, i.e.; through "supports [ :status, :restart ]" - Otherwise just stop, sleep, then start the service again.
def restart_service if @new_resource.restart_command run_command(:command => @new_resource.restart_command) elsif @new_resource.supports[:restart] run_command(:command => "#{@init_command} restart") else stop_service sleep 1 start_service end end
First it seems that, if the service is not running already, it is not started??
[Thu, 11 Jun 2009 20:43:37 +0200] DEBUG: remote_file[fz_war] changed from f18463d301b65a6c161669d0de190293f78480b3ed88590215ea30947cf8dfbf to 1792af24a3aa7829dbf15340ad54d7a7af9db272fa769e4572f03e783c4c3da5 [Thu, 11 Jun 2009 20:43:37 +0200] INFO: Updating remote_file[fz_war] at /usr/share/jetty6/webapps/ROOT.war [Thu, 11 Jun 2009 20:43:37 +0200] INFO: Backing up remote_file[fz_war] to /usr/share/jetty6/webapps/ROOT.war.chef-20090611204337 [Thu, 11 Jun 2009 20:43:38 +0200] INFO: Removing backup of remote_file[fz_war] at /usr/share/jetty6/webapps/ROOT.war.chef-20090611181740 [Thu, 11 Jun 2009 20:43:38 +0200] INFO: remote_file[fz_war] sending restart action to service[jetty6] (delayed) [Thu, 11 Jun 2009 20:43:38 +0200] DEBUG: service[jetty6] using Chef::Provider::Service::Debian [Thu, 11 Jun 2009 20:43:38 +0200] DEBUG: service[jetty6] does not support status and you have not specified a status command, falling back to process table inspection [Thu, 11 Jun 2009 20:43:38 +0200] DEBUG: service[jetty6]: attempting to match jetty6 ((?-mix:jetty6)) against process table [Thu, 11 Jun 2009 20:43:38 +0200] DEBUG: service[jetty6]: ps -ef exited and parsed successfully, process running: false [Thu, 11 Jun 2009 20:43:38 +0200] INFO: Chef Run complete in 24.356492 seconds
If the service is already running it is restarted ok:
[Thu, 11 Jun 2009 20:53:46 +0200] INFO: remote_file[fz_war] sending restart action to service[jetty6] (delayed) [Thu, 11 Jun 2009 20:53:46 +0200] DEBUG: service[jetty6] using Chef::Provider::Service::Debian [Thu, 11 Jun 2009 20:53:46 +0200] DEBUG: service[jetty6] does not support status and you have not specified a status command, falling back to process table inspection [Thu, 11 Jun 2009 20:53:46 +0200] DEBUG: service[jetty6]: attempting to match jetty6 ((?-mix:jetty6)) against process table [Thu, 11 Jun 2009 20:53:46 +0200] DEBUG: service[jetty6]: ps -ef exited and parsed successfully, process running: true [Thu, 11 Jun 2009 20:53:46 +0200] DEBUG: service[jetty6]: attempting to restart [Thu, 11 Jun 2009 20:53:46 +0200] DEBUG: Executing /etc/init.d/jetty6 restart [Thu, 11 Jun 2009 20:54:28 +0200] DEBUG: ---- Begin output of /etc/init.d/jetty6 restart ----
Second, it seems that the notification always takes place, even if the remote file didn't change:
A notification should only be triggered if the resource in question actually changed. Are you certain that the file is not being updated every time?
Thu, 11 Jun 2009 20:44:35 +0200] DEBUG: /fz-1.war 100% done (9736249 of 9736249) [Thu, 11 Jun 2009 20:44:36 +0200] INFO: remote_file[fz_war] sending restart action to service[jetty6] (delayed) [Thu, 11 Jun 2009 20:44:36 +0200] DEBUG: service[jetty6] using Chef::Provider::Service::Debian [Thu, 11 Jun 2009 20:44:36 +0200] DEBUG: service[jetty6] does not support status and you have not specified a status command, falling back to process table inspection [Thu, 11 Jun 2009 20:44:36 +0200] DEBUG: service[jetty6]: attempting to match jetty6 ((?-mix:jetty6)) against process table [Thu, 11 Jun 2009 20:44:36 +0200] DEBUG: service[jetty6]: ps -ef exited and parsed successfully, process running: false [Thu, 11 Jun 2009 20:44:36 +0200] INFO: Chef Run complete in 23.318144 seconds
Did I misunderstand something about how notification & services are supposed to work??
2) Given this recipe:
service "mountec2vol" do supports :status => true, :restart => true action [ :enable, :start ] end
It seems Chef is running the "status" command twice. Is this necessary?
This isn't something I've encountered, but I'll look into it. Looks like possibly the two actions are causing the provider to reload.
[Thu, 11 Jun 2009 16:41:52 +0200] DEBUG: Processing service[mountec2vol] [Thu, 11 Jun 2009 16:41:52 +0200] DEBUG: service[mountec2vol] using Chef::Provider::Service::Debian [Thu, 11 Jun 2009 16:41:52 +0200] DEBUG: service[mountec2vol] supports status, running [Thu, 11 Jun 2009 16:41:52 +0200] DEBUG: Executing /etc/init.d/mountec2vol status [Thu, 11 Jun 2009 16:42:00 +0200] DEBUG: ---- Begin output of /etc/init.d/mountec2vol status ---- [Thu, 11 Jun 2009 16:42:00 +0200] DEBUG: STDOUT: ATTACHMENT vol-98f316f1 i-8b4f4cff /dev/sdh attache2009-06-11T13:33:56+0000 [Thu, 11 Jun 2009 16:42:00 +0200] DEBUG: STDERR: [Thu, 11 Jun 2009 16:42:00 +0200] DEBUG: ---- End output of /etc/init.d/mountec2vol status ---- [Thu, 11 Jun 2009 16:42:00 +0200] DEBUG: Ran /etc/init.d/mountec2vol status returned 0 [Thu, 11 Jun 2009 16:42:00 +0200] DEBUG: service[mountec2vol]: not enabling, already enabled [Thu, 11 Jun 2009 16:42:00 +0200] DEBUG: service[mountec2vol] using Chef::Provider::Service::Debian [Thu, 11 Jun 2009 16:42:00 +0200] DEBUG: service[mountec2vol] supports status, running [Thu, 11 Jun 2009 16:42:00 +0200] DEBUG: Executing /etc/init.d/mountec2vol status [Thu, 11 Jun 2009 16:42:08 +0200] DEBUG: ---- Begin output of /etc/init.d/mountec2vol status ---- [Thu, 11 Jun 2009 16:42:08 +0200] DEBUG: STDOUT: ATTACHMENT vol-98f316f1 i-8b4f4cff /dev/sdh attache2009-06-11T13:33:56+0000 [Thu, 11 Jun 2009 16:42:08 +0200] DEBUG: STDERR: [Thu, 11 Jun 2009 16:42:08 +0200] DEBUG: ---- End output of /etc/init.d/mountec2vol status ---- [Thu, 11 Jun 2009 16:42:08 +0200] DEBUG: Ran /etc/init.d/mountec2vol status returned 0 [Thu, 11 Jun 2009 16:42:08 +0200] DEBUG: service[mountec2vol]: not starting, already running
Thanks!
-- AJ Christensen, Software Engineer
|