run Exec only if another Exec ran

≯℡__Kan透↙ 提交于 2019-12-12 02:09:08

问题


how can I configure a Exec to run only if another Exec ran?

I have a manifest like this:

file { $target:
    ensure => directory
}

exec { "unzip foobar.zip -C ${target}": 
    unless => "file ${target}/some-file-form-archive"
}

exec { "chown -R $user ${target}":
    onlyif => ???
}

I would like the chown to run only if unzip foobar.zip ran. Of course I could start checking whether some-file-from-archive is already owned by $user, but somehow it does not seem right.


回答1:


There's an answer here already: http://ask.puppetlabs.com/question/14726/run-exec-only-if-another-exec-ran/

Changing the manifest like this fixes my problem:

exec { 'unpack file':
  command => "unzip foobar.zip -C ${target}",
  path        => '/usr/bin',
  creates    => "${target}/some-file-form-archive",
  require    => File[$target, '<archive>'],
  notify      => Exec[fix archive],
}

exec { 'fix archive':
  command => "chown -R ${user} ${target}",
  path => '/bin',
  refreshonly => true,
}

UPDATE 28.11.2014

motivated by Felix Frank's comment i tried out something else. instead of notify/refreshonly you can ensure all resource in a file-tree are owned by a user like this:

exec { 'fix archive':
  command => "chown -R ${user} ${target}",
  path => '/bin',
  unless => "test 0 -eq $(find ${target} \\! -user ${user} | wc -l)"
}

this way owner is ensured to be $user even if it was changed after unpack file ran.



来源:https://stackoverflow.com/questions/27150839/run-exec-only-if-another-exec-ran

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