Hi, When I use an exec resource to create a file, a timeout may occur. As an example, I can run wget to get a file (not the most elegant solution but necessary sometimes), or run some other program that depends on the network to get some data that is necessary to create the file. This timeout itself is fine, I could increase the timeout, but there are still cases where I would want puppet to stop after this timeout. Problem is, what if the file was partially created? I use an exec resource with the creates attribute, so the next time puppet runs, it thinks that the exec resource has been satisfied, and it doesn''t run the command again. Then I''m left, for example, with a half-downloaded file. Is there some way to do cleanup after a timeout? I''m thinking something like the ability to run another shell command on timeout, or perhaps a way to specify that the "creates" file should be deleted if a timeout occurs. Does something like this exist? Regards, Erwin Bolwidt -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Dec 17, 2010, at 9:45 PM, Erwin Bolwidt wrote:> Hi, > > When I use an exec resource to create a file, a timeout may occur. As an example, I can run wget to get a file (not the most elegant solution but necessary sometimes), or run some other program that depends on the network to get some data that is necessary to create the file. > > This timeout itself is fine, I could increase the timeout, but there are still cases where I would want puppet to stop after this timeout. > > Problem is, what if the file was partially created? I use an exec resource with the creates attribute, so the next time puppet runs, it thinks that the exec resource has been satisfied, and it doesn''t run the command again.What I do is have the second command''s completion condition used as the condition for the first exec. Then I make sure the first exec will properly handle a partially downloaded file. The one time this isn''t easy, I embedded the whole thing in a shellscript that moves the completed file to the right location at the end. I personally use zsync a bit since I can use the old file to speed up the downloading when the file changes. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Hi, I think that the cleanest way to go about this is to create a bash / perl / python / whatever script that does the wget and watches the exit status of it, cleaning it up if it was unsuccessful. Then you would add this script to your puppet recipe as a "file" resource and execute this script in the "exec" resource. I do not think (somebody please correct me if I am wrong) that the puppet language has something specific for what you want to do, so your best bet would be using an external scripting language. It would also be the cleanest and most powerful / flexible way. The other choice would be writing your own resource using ruby and adding it to puppet but depending on how much you actually use this it could be too much overhead. On Dec 18, 9:24 am, Patrick <kc7...@gmail.com> wrote:> On Dec 17, 2010, at 9:45 PM, Erwin Bolwidt wrote: > > > Hi, > > > When I use an exec resource to create a file, a timeout may occur. As an example, I can run wget to get a file (not the most elegant solution but necessary sometimes), or run some other program that depends on the network to get some data that is necessary to create the file. > > > This timeout itself is fine, I could increase the timeout, but there are still cases where I would want puppet to stop after this timeout. > > > Problem is, what if the file was partially created? I use an exec resource with the creates attribute, so the next time puppet runs, it thinks that the exec resource has been satisfied, and it doesn''t run the command again. > > What I do is have the second command''s completion condition used as the condition for the first exec. Then I make sure the first exec will properly handle a partially downloaded file. > > The one time this isn''t easy, I embedded the whole thing in a shellscript that moves the completed file to the right location at the end. > > I personally use zsync a bit since I can use the old file to speed up the downloading when the file changes.-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Ken Barber
2010-Dec-18 19:40 UTC
Re: [Puppet Users] Cleanup after timeout in exec resource
Shame wget doesn''t do this for you. I''m sure there is a better tool to do .part files. Anyway, taking from kc7zzv''s excellent idea ... something as simple as the following might do as a work-around: exec {"wget-foo": command => "/usr/bin/wget http://mirror.ox.ac.uk/sites/mirror.centos.org/5.5/isos/x86_64/CentOS-5.5-x86_64-bin-8of8.iso -c -O /tmp/centos.iso.part && mv /tmp/centos.iso.part /tmp/centos.iso", creates => "/tmp/centos.iso", timeout => 30, } This way you are leveraging the partial download not throwing it away. If it doesn''t complete, it will continue where it left off from last run ... until the ''mv'' is finally reached. I''m not fond of this method generally because if the source changes puppet will do nothing. *shrug*. zsync/rsync are better answers I guess for huge files. I''d rather use the puppet file-server if the files are small enough. ken. On Saturday, December 18, 2010 8:24:27 AM UTC, kc7zzv wrote:> > > On Dec 17, 2010, at 9:45 PM, Erwin Bolwidt wrote: > > > Hi, > > > > When I use an exec resource to create a file, a timeout may occur. As an > example, I can run wget to get a file (not the most elegant solution but > necessary sometimes), or run some other program that depends on the network > to get some data that is necessary to create the file. > > > > This timeout itself is fine, I could increase the timeout, but there are > still cases where I would want puppet to stop after this timeout. > > > > Problem is, what if the file was partially created? I use an exec > resource with the creates attribute, so the next time puppet runs, it thinks > that the exec resource has been satisfied, and it doesn''t run the command > again. > > What I do is have the second command''s completion condition used as the > condition for the first exec. Then I make sure the first exec will properly > handle a partially downloaded file. > > The one time this isn''t easy, I embedded the whole thing in a shellscript > that moves the completed file to the right location at the end. > > I personally use zsync a bit since I can use the old file to speed up the > downloading when the file changes. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.