问题
I'm using Puppet 3 on Amazon Linux 2012.09, one of my manifests sets up and reconfigs some directories. One of the tasks is just changing the folder owner and group recursivelt to another user - however, this takes over a 60 seconds to complete and there is barely anything in the directory - the chown myuser:myuser /var/lib/jenkins in the terminal take less than a second.
My question is: Is there a better/faster way to change directory ownership recursively in Puppet?
Thanks
file {'/var/lib/jenkins':
ensure => 'directory',
owner => myuser,
group => myuser,
recurse => true,
require => Package['jenkins'],
}
回答1:
I see this slowness too, and it appears to be due to Puppet checking each file under /var/lib/jenkins
individually to ensure it has the correct owner permissions, which takes time since there's a lot of files under $JENKINS_HOME
.
I worked around it on our Jenkins server by instead running a simple chown -R
command (with exec
) whenever the top-level directory is not owned by the desired user:
define modify_owner() {
exec { "modify_owner_${title}" :
command => "/bin/chown -R ${user}:${user} '${title}'",
onlyif => "/usr/bin/stat -c %U '${title}' | grep '^${default_user}$'"
}
}
modify_owner { ['/var/lib/jenkins', '/var/log/jenkins', '/var/cache/jenkins']: }
$user
/$user
is the owner/group combo I want these directories to be owned by. This brought my Puppet times back down to normal levels.
(Note: I used stat -c %U
but you may need to tweak the exact formatting options depending on your OS. This command printed the owner's textual name and worked for me on Linux.)
来源:https://stackoverflow.com/questions/15924138/puppet-3-file-recurse-terribly-slow