在开始服务之前要求木偶放置文件

时间:2013-06-26 01:52:26

标签: 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 => 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

3 个答案:

答案 0 :(得分:4)

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

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

这将达到同样的效果。

订阅==要求+刷新活动。

答案 1 :(得分:2)

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

service { 'php5-fpm':
    ensure => running,
    enable => true,
    require => [ File['php.ini'], File['www.conf'] ],
}

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

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

答案 2 :(得分:1)

所以,我明白了。不得不向文件块添加通知,以便知道在文件更改时重新启动服务。

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'],
}