Saturday, June 2, 2012

Puppet starting the service before package install

Here's an example of a simple manifest file that will install a package (ex. apache) and will ensure that that the service was started after install

package {'httpd':
ensure => installed,
source => '/var/tmp/httpd-2.2.3-53.el5.centos.i386.rpm',
}

service {'httpd':
ensure => running,
enable => true,
hasstatus => true,
hasrestart => true,
}



Seems legit. Let's apply the manifest


[root@learn tmp]# puppet apply httpd.install.pp
err: /Stage[main]//Service[httpd]/ensure: change from stopped to running failed: Could not start Service[httpd]: Execution of '/sbin/service httpd start' returned 1: at /var/tmp/httpd.install.pp:11
notice: /Stage[main]//Package[httpd]/ensure: created
notice: Finished catalog run in 31.04 seconds



hmmm.. it seems that puppet was starting the service before the install. Let's modify the file


package { 'httpd':
ensure => installed,
source => '/var/tmp/httpd-2.2.3-53.el5.centos.i386.rpm',
}

service { 'httpd':
require => Package['httpd'],
ensure => running,
enable => true,
hasstatus => true,
hasrestart => true,
}



Now let's apply the new manifest file


[root@learn tmp]# puppet apply httpd.install.pp
notice: /Stage[main]//Package[httpd]/ensure: created
notice: /Stage[main]//Service[httpd]/ensure: ensure changed 'stopped' to 'running'
notice: Finished catalog run in 34.10 seconds

[root@learn tmp]# chkconfig --list |grep httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
pe-httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

[root@learn tmp]# rpm -qa |grep httpd
pe-httpd-2.2.3-17.pe.el5
pe-httpd-passenger-2.2.11-11.pe.el5
httpd-2.2.3-63.el5.centos.1
[root@learn tmp]# service httpd status
httpd (pid 15355) is running...



Disclaimer: im still a puppetlabs newbie. :)

No comments: