A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.aws.amazon.com/opsworks/latest/userguide/create-custom-configure.html below:

Configure Recipes - AWS OpsWorks

Configure Recipes

Important

The AWS OpsWorks Stacks service reached end of life on May 26, 2024 and has been disabled for both new and existing customers. We strongly recommend customers migrate their workloads to other solutions as soon as possible. If you have questions about migration, reach out to the AWS Support Team on AWS re:Post or through AWS Premium Support.

Configure recipes are assigned to the layer's Configure lifecycle event, which occurs on all of the stack's instances whenever an instance enters or leaves the online state. You use Configure recipes to adjust an instance's configuration to respond to the change, as appropriate. When you implement a Configure recipe, keep in mind that a stack configuration change might involve instances that have nothing to do with this layer. The recipe must be able to respond appropriately, which might mean doing nothing in some cases.

tomcat::configure

The tomcat::configure recipe is intended for a layer's Configure lifecycle event.


include_recipe 'tomcat::context'
# Optional: Trigger a Tomcat restart in case of a configure event, if relevant
# settings in custom JSON have changed (e.g. java_opts/JAVA_OPTS):
#include_recipe 'tomcat::container_config'

The tomcat::configure recipe is basically a metarecipe that runs two dependent recipes.

  1. The tomcat::context recipe create a web app context configuration file.

    This file configures the JDBC resources that applications use to communicate with the MySQL instance, as discussed in the next section. Running this recipe in response to a configure event allows the layer to update the web app context configuration file if the database layer has changed.

  2. The tomcat::container_config Setup recipe is run again to capture any changes in the container configuration.

The include for tomcat::container_config is commented out for this example. If you want to use custom JSON to modify Tomcat settings, you can remove the comment. A Configure lifecycle event then runs tomcat::container_config, which updates the Tomcat related configuration files, as described in tomcat::container_config and restarts the Tomcat service.

tomcat::context

The Tomcat cookbook enables applications to access a MySQL database server, which can be running on a separate instance, by using a J2EE DataSource object. With Tomcat, you can enable the connection by creating and installing a web app context configuration file for each application. This file defines the relationship between the application and the JDBC resource that the application will use to communicate with the database. For more information, see The Context Container.

The tomcat::context recipe's primary purpose is to create this configuration file.


include_recipe 'tomcat::service'

node[:deploy].each do |application, deploy|
  context_name = deploy[:document_root].blank? ? application : deploy[:document_root]

  template "context file for #{application} (context name: #{context_name})" do
    path ::File.join(node['tomcat']['catalina_base_dir'], 'Catalina', 'localhost', "#{context_name}.xml")
    source 'webapp_context.xml.erb'
    owner node['tomcat']['user']
    group node['tomcat']['group']
    mode 0640
    backup false
    only_if { node['datasources'][context_name] }
    variables(:resource_name => node['datasources'][context_name], :webapp_name => application)
    notifies :restart, resources(:service => 'tomcat')
  end
end

In addition to Tomcat cookbook attributes, this recipe uses the stack configuration and deployment attributes that OpsWorks Stacks installs with the Configure event. The OpsWorks Stacks service adds attributes to each instance's node object that contain the information that recipes would typically obtain by using data bags or search and installs the attributes on each instance. The attributes contain detailed information about the stack configuration, deployed apps, and any custom data that a user wants to include. Recipes can obtain data from stack configuration and deployment attributes by using standard Chef node syntax. For more information, see Stack Configuration and Deployment Attributes. With Chef 11.10 stacks, you also can use Chef search to obtain stack configuration and deployment data. For more information, see Using Chef Search.

deploy attributes refers to the [:deploy] namespace, which contains deployment-related attributes that are defined through the console or API, or generated by the OpsWorks Stacks service. The deploy attribute includes an attribute for each deployed app, named with the app's short name. Each app attribute contains a set of attributes that characterize the app, such as the document root ([:deploy][:appname][:document_root]).

The context recipe first ensures that the service is defined for this Chef run by calling tomcat::service. It then defines a context_name variable which represents the configuration file's name, excluding the .xml extension. If you use the default document root, context_name is set to the app's short name. Otherwise, it is set to the specified document root. The example discussed in Create a Stack and Run an Application sets the document root to "ROOT", so the context is ROOT and the configuration file is named ROOT.xml.

The bulk of the recipe goes through the list of deployed apps and for each app, uses the webapp_context.xml.erb template to create a context configuration file. The example deploys only one app, but the definition of the deploy attribute requires you to treat it as a list of apps regardless.

The webapp_context.xml.erb template is not operating-system specific, so it is located in the templates directory's default subdirectory.

The recipe creates the configuration file as follows:

The webapp_context.xml.erb template consists of a Context element that contains a Resource element with its own set of attributes.

The Resource attributes characterize the context configuration:

For more information on this configuration file, see the Tomcat wiki's Using DataSources topic.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4