Puppet 3 file recurse terribly slow

夙愿已清 提交于 2019-12-12 11:11:46

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!