Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Puppet does not start a service (varnish) when puppet apply is run

I have a puppet manifest which states that the service "varnish" should be running, but it is not.

I have another service defined, apache2, which works fine, and get started whenever I run 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:~$ 

Apply puppet:

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

But varnish does not start.

This is the manifest file:

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

}

Thanks!

like image 700
marianov Avatar asked Jan 30 '13 15:01

marianov


3 Answers

Answering my own question:

According to this: https://projects.puppetlabs.com/issues/12773 the problem lies in Ubuntu init scripts, or the "service" command not returning a proper exit code.

The solution is to set a custom status check using grep and service.

  service { "varnish":
    ensure => running,
    enable  => true,
    hasrestart => true,
    hasstatus => true,
    status => '/usr/sbin/service  varnish status | grep "is running"',
    require => Package["varnish"],
  }
like image 69
marianov Avatar answered Nov 10 '22 17:11

marianov


The docs say that puppet expects the initscript of the service to have a "status" command that returns 0 if the service is running and a non-zero value otherwise. This is the default behavior of puppet. Try to do a

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

In case your initscript doesn't give you desired return types set "hasstatus => false" within the service directive block and give it a try.

like image 4
naugustine Avatar answered Nov 10 '22 17:11

naugustine


This is working fine:

  service { $service:
    ensure     => running,
    enable     => true,
    status     => "/usr/sbin/service  ${service} status",
    require    => Package["$service"],
  }
like image 1
Dušan Šušić Avatar answered Nov 10 '22 19:11

Dušan Šušić