运行puppet apply时,Puppet不会启动服务(清漆)

时间:2013-01-30 15:19:45

标签: deployment automation puppet

我有一个木偶清单,声明服务“清漆”应该运行,但事实并非如此。

我有另一个定义的服务,apache2,工作正常,每当我运行puppet apply时就开始使用。

vagrant@lucid32:~$ sudo netstat -tunelp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       User       Inode       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      0          3749        605/sshd        
tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN      1000       5169        1110/0          
tcp        0      0 0.0.0.0:48828           0.0.0.0:*               LISTEN      0          3445        552/rpc.statd   
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      0          3228        484/portmap     
tcp6       0      0 :::22                   :::*                    LISTEN      0          3751        605/sshd        
tcp6       0      0 ::1:6010                :::*                    LISTEN      1000       5168        1110/0          
udp        0      0 0.0.0.0:68              0.0.0.0:*                           0          4179        917/dhclient    
udp        0      0 0.0.0.0:68              0.0.0.0:*                           0          3277        558/dhclient3   
udp        0      0 0.0.0.0:728             0.0.0.0:*                           0          3430        552/rpc.statd   
udp        0      0 0.0.0.0:111             0.0.0.0:*                           0          3227        484/portmap     
udp        0      0 0.0.0.0:54265           0.0.0.0:*                           0          3442        552/rpc.statd   
udp        0      0 10.0.2.15:123           0.0.0.0:*                           102        4259        904/ntpd        
udp        0      0 127.0.0.1:123           0.0.0.0:*                           0          4208        904/ntpd        
udp        0      0 0.0.0.0:123             0.0.0.0:*                           0          4203        904/ntpd        
udp6       0      0 fe80::a00:27ff:feb5:123 :::*                                0          4210        904/ntpd        
udp6       0      0 ::1:123                 :::*                                0          4209        904/ntpd        
udp6       0      0 :::123                  :::*                                0          4204        904/ntpd        
vagrant@lucid32:~$ 

申请傀儡:

vagrant@lucid32:~$ sudo puppet apply --verbose /vagrant/manifests/default.pp 
info: Applying configuration version '1359558916'
notice: /Stage[main]/Apachevarnish/Service[apache2]/ensure: ensure changed 'stopped' to 'running'
notice: Finished catalog run in 0.15 seconds

但是清漆没有启动。

这是清单文件:

  class apachevarnish {


  Package { ensure => "installed" }

  package { "apache2": }
  package { "varnish": }

  file { '/etc/hosts':
    ensure => link,
    target => "/vagrant/hosts",
    force  => true
  }

  file { '/var/www':
    ensure => link,
    target => "/vagrant",
    notify => Service['apache2'],
    force  => true
  }

  file { '/etc/varnish':
    ensure => link,
    target => "/vagrant/etc/varnish",
    # notify => Service['varnish'],
    force  => true
  }


  service { "varnish":
    ensure => running,
    require => Package["varnish"],
  }


  service { "apache2":
    ensure => running,
    require => Package["apache2"],
  }

}

谢谢!

3 个答案:

答案 0 :(得分:13)

回答我自己的问题:

根据这个:https://projects.puppetlabs.com/issues/12773问题在于Ubuntu init脚本,或者“service”命令没有返回正确的退出代码。

解决方案是使用grep和service设置自定义状态检查。

  service { "varnish":
    ensure => running,
    enable  => true,
    hasrestart => true,
    hasstatus => true,
    status => '/usr/sbin/service  varnish status | grep "is running"',
    require => Package["varnish"],
  }

答案 1 :(得分:4)

文档说puppet希望服务的initscript具有“status”命令,如果服务正在运行则返回0,否则返回非零值。这是puppet的默认行为。尝试做一个

$> sudo service <service_name> status
$> echo $? //Make sure you are getting the correct return values that puppet expects.

如果你的initscript没有给你想要的返回类型,请在服务指令块中设置“ hasstatus =&gt; false” 并试一试。

答案 2 :(得分:1)

这很好用:

  service { $service:
    ensure     => running,
    enable     => true,
    status     => "/usr/sbin/service  ${service} status",
    require    => Package["$service"],
  }