Book Image

Infrastructure as Code (IAC) Cookbook

By : Stephane Jourdan, Pierre Pomès
Book Image

Infrastructure as Code (IAC) Cookbook

By: Stephane Jourdan, Pierre Pomès

Overview of this book

Para 1: Infrastructure as code is transforming the way we solve infrastructural challenges. This book will show you how to make managing servers in the cloud faster, easier and more effective than ever before. With over 90 practical recipes for success, make the very most out of IAC.
Table of Contents (18 chapters)
Infrastructure as Code (IAC) Cookbook
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
Index

Managing services


We've seen how to install system packages using the package resource. In this section, you'll discover how to manage system services, using a resource named service. We'll continue to build the LAMP server we started in the previous section by managing the Apache HTTP and MariaDB services right from Chef. This way we'll be able to manage any available service.

Getting ready

To work through this recipe, you will need the following:

  • A working Chef DK installation on the workstation

  • A working Chef client configuration on the remote host

  • The Chef code from the previous recipe

How to do it…

The structure of the service resource is very similar to the package resource. We want to do two actions with our services: enable them at boot and start them right away. This translates into a simple Chef resource with an array of actions:

service "service_name" do
  action [:enable, :start]
end

Enabling and starting Apache service

Add this service resource to the apache/recipes/default.rb file, just...