有一种方法来运行一个configtest实用程序(例如apache2ctl -t)之前尝试重新启动服务,当其中一个configuration文件更改?
这里的用例是我想要在apacheconfiguration中对configuration错误进行恢复(因为apache只是在看到configuration错误时才停下来,让我停止apache)
您可以使用require => Exec[]和菊花链连接exec以要求更改configuration。
如果Exec失败(退出状态!= 0),那么后续的任务也会失败。 我做类似的事情来执行ssh-keygen,然后在创build新用户时在.ssh上设置特殊权限。
例:
# Ensure the .ssh directory exists for each user file { "${dot_ssh_dir}": ensure => directory, owner => $title, mode => 700, require => File["${home_dir}"], } # Run ssh-keygen (ONLY if id_rsa doesn't exist) exec { "${title} ssh-keygen": command => "ssh-keygen -f ./id_rsa -q -N ''", cwd => $dot_ssh_dir, user => $title, creates => "${keyfile_private}", path => ['/usr/bin', '/usr/sbin/', '/usr/local/sbin'], require => File[$dot_ssh_dir], } # AuthorizedKeys should be 600 file { "${authorized_keys}": source => "${keyfile_public}", ensure => present, mode => 600, owner => $title, group => 'sftpusers', require => Exec["${title} ssh-keygen"], }