要求puppet在启动服务之前放置文件

要求puppet在启动服务之前放置文件,puppet,Puppet,我的木偶配置有问题。当我们运行puppet时,它会在放置www.conf文件之前启动php5 fpm服务。然后,我必须登录并重新启动服务,以便所有服务都能按预期运行 这就是我试图对php/manifests/init.pp文件所做的: file { 'www.conf': path => '/etc/php5/fpm/pool.d/www.conf', ensure => file, owner => root, group =>

我的木偶配置有问题。当我们运行puppet时,它会在放置www.conf文件之前启动php5 fpm服务。然后,我必须登录并重新启动服务,以便所有服务都能按预期运行

这就是我试图对php/manifests/init.pp文件所做的:

    file { 'www.conf':
    path => '/etc/php5/fpm/pool.d/www.conf',
    ensure => file,
    owner => root,
    group => root,
    source => 'puppet:///modules/php/www.conf',
    require => Package['php5-fpm'],
}

service { 'php5-fpm':
    ensure => running,
    enable => true,
    require => File['php.ini','www.conf'],
} 
以下是木偶输出:

notice: /Stage[first]/Apt_get::Update/Exec[apt-get update]/returns: executed successfully
notice: /Stage[second]/Tools/Package[python-software-properties]/ensure: ensure changed 'purged' to 'present'
notice: /Stage[second]/Tools/Package[imagemagick]/ensure: ensure changed 'purged' to 'present'
notice: /Stage[second]/Tools/Package[curl]/ensure: ensure changed 'purged' to 'present'
notice: /Stage[third]/Php/Exec[add_repo]/returns: executed successfully
notice: /Stage[third]/Php/Exec[update_repo]/returns: executed successfully
notice: /Stage[third]/Php/Package[php5-mysql]/ensure: ensure changed 'purged' to 'latest'
notice: /Stage[third]/Php/Package[php-apc]/ensure: ensure changed 'purged' to 'latest'
notice: /Stage[third]/Php/Package[php5-mcrypt]/ensure: ensure changed 'purged' to 'latest'
notice: /Stage[third]/Php/Package[php5-xdebug]/ensure: ensure changed 'purged' to 'latest'
notice: /Stage[third]/Php/Package[php5]/ensure: ensure changed 'purged' to 'latest'
notice: /Stage[third]/Php/Service[apache2]/ensure: ensure changed 'running' to 'stopped'
notice: /Stage[third]/Php/Package[php5-fpm]/ensure: ensure changed 'purged' to 'latest'
notice: /Stage[third]/Php/File[php.ini]/content: content changed '{md5}a199da053cb070fcd15210120e49cd20' to '{md5}9291336844ec35b4b45a84e16975a321'
notice: /Stage[third]/Php/Package[php-pear]/ensure: ensure changed 'purged' to 'latest'
notice: /Stage[third]/Php/Package[php-xml-parser]/ensure: ensure changed 'purged' to 'latest'  
notice: /Stage[third]/Php/Package[php5-curl]/ensure: ensure changed 'purged' to 'latest'
notice: /Stage[third]/Php/File[browscap.ini]/ensure: defined content as '{md5}1393b32a89ea6af06e8e419ac4d4944d'
 notice: /Stage[third]/Php/File[www.conf]/content: content changed '{md5}7f7f6459440a5944275303d06866cec2' to '{md5}68cd4723a3549ce1a81959a0fb104ff3'
notice: /Stage[third]/Php::Pear/Exec[pear-update-channel]/returns: executed successfully
notice: /Stage[third]/Php::Pear/Exec[pear-upgrade]/returns: executed successfully
notice: /Stage[third]/Php/Package[libssh2-1-dev]/ensure: ensure changed 'purged' to 'latest'
notice: /Stage[third]/Php::Pear/Exec[pear-config-set]/returns: executed successfully
notice: /Stage[third]/Php::Pear/Exec[pear-channel-discover-pear-phpunit-de]/returns: executed successfully
notice: /Stage[third]/Php::Pear/Exec[pear-channel-discover-components-ez-no]/returns: executed successfully
notice: /Stage[third]/Php::Pear/Exec[pear-channel-discover-pear-symfony-project-com]/returns: executed successfully
notice: /Stage[third]/Php::Pear/Exec[pear-clear-cache]/returns: executed successfully
notice: /Stage[third]/Php::Pear/Exec[pear-install]/returns: executed successfully

所以,我明白了。必须将notify添加到文件块,以便在文件更改时重新启动服务

file { 'www.conf':
    notify  => Service['php5-fpm'],
    path => '/etc/php5/fpm/pool.d/www.conf',
    ensure => file,
    owner => root,
    group => root,
    source => 'puppet:///modules/php/www.conf',
    require => Package['php5-fpm'],
}

或者您可以将服务上的“require”更改为“subscribe”

service { 'php5-fpm':
    ensure => running,
    enable => true,
    subscribe => File['php.ini','www.conf'],
}
这将达到同样的效果


Subscribe==require+refresh事件。

我认为同时需要多个资源的方法是提供一个列表():

然后,如果您还打算在
php.ini
www.conf
发生更改时重新启动php fpm服务,则可以将上述
require
更改为
subscribe

service { 'php5-fpm':
    ...
    subscribe => [ File['php.ini'], File['www.conf'] ],
}
service { 'php5-fpm':
    ...
    subscribe => [ File['php.ini'], File['www.conf'] ],
}