Show Table of Contents
2.5. Running the HTTP Server
After installing the
httpd package, we start the service using another resource declaration: service.
Edit the
httpd.pp manifest and add the highlighted lines:
class mymodule::httpd {
package { 'httpd':
ensure => installed,
}
service { 'httpd':
ensure => running,
enable => true,
require => Package["httpd"],
}
}
This achieves a couple of things:
- The
ensure => runningattribute checks if the service if running. If not, Puppet enables it. - The
enable => trueattribute sets the service to run when the system boots. - The
require => Package["httpd"]attribute defines an ordering relationship between one resource declaration and another. In this case, it ensures thehttpdservice starts after thehttpdpackage installs. This creates a dependency between the service and its respective package.
Run the
puppet apply command again to test the changes to our module:
# puppet apply mymodule/tests/init.pp --noop
Notice: Compiled catalog for puppet.example.com in environment production in 0.56 seconds
Notice: /Stage[main]/Mymodule::Httpd/Package[httpd]/ensure: current_value absent, should be present (noop)
Notice: /Stage[main]/Mymodule::Httpd/Service[httpd]/ensure: current_value stopped, should be running (noop)
Notice: Class[Mymodule::Httpd]: Would have triggered 'refresh' from 2 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.41 seconds
The highlighted line is the result of our new resource definition for the
httpd service.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.