이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 6. Using Cartridge Scripts


Cartridge scripts act as the application programming interface (API) for a cartridge. Use these scripts to contain the required code for single version software that configures easily. For complex configurations and software with multiple versions, use these scripts as shim code to set up the required environment and run additional scripts. You can also create symbolic links from these scripts.
Cartridge scripts are located in the $cartridge_name/bin/ directory, and run from the cartridge's home directory.
Expand
Table 6.1. Required Scripts
Script Name Usage
setup Creates and configures files that OpenShift Enterprise copies from the cartridge repository to the gear's directory. Runs for the initial installation and every upgrade.
control Enables OpenShift Enterprise or the application developer to control the state of a cartridge and its packaged software.
Expand
Table 6.2. Optional Scripts
Script Name Usage
teardown Prepares the gear for cartridge removal.
install Creates and configures files that OpenShift Enterprise copies from the cartridge repository to the gear's directory. Runs only on the first installation of the cartridge.
post-install Configures the cartridge after the cartridge starts. Runs only on the first installation of the cartridge.
metrics Gathers cartridge level metrics.

6.1. Embedded Ruby (ERB) Processing

Embedded Ruby (ERB) is a templating system that embeds Ruby into a text document. To provide more flexible configuration and environment variable options, OpenShift Enterprise enables you to provide certain values as ERB templates. For more information on ERB templates, see http://ruby-doc.org/stdlib-1.9.3/libdoc/erb/rdoc/ERB.html.
OpenShift Enterprise renders ERB templates at safe_level 2 and processes them in two passes. For more information on Ruby safe levels, see http://www.ruby-doc.org/docs/ProgrammingRuby/html/taint.html.

ERB Processing Passes

  1. The first pass processes entries in the $cartridge_name/env/ directory. This pass is mandatory, and occurs before OpenShift Enterprise runs the $cartridge_name/bin/setup script.
  2. The second pass processes entries specified in the process_templates entry of the $cartridge_name/metadata/managed_files.yml file. This pass occurs after OpenShift Enterprise runs the $cartridge_name/bin/setup script, but before it runs the $cartridge_name/bin/install script. This enables the setup script to create or modify ERB templates as required, and for the install script to use the processed values.

Example 6.1. Environment Variable Template

For OpenShift Enterprise release 2.0, an env/OPENSHIFT_MONGODB_DB_LOG_DIR.erb file contains:
<%= ENV['OPENSHIFT_MONGODB_DIR'] %>/log/
Copy to Clipboard Toggle word wrap
For OpenShift Enterprise release 2.1 and later, an env/OPENSHIFT_MONGODB_DB_LOG_DIR.erb file contains:
<%= ENV['OPENSHIFT_LOG_DIR'] %>
Copy to Clipboard Toggle word wrap
The value of LOG_DIR for each cartridge is set to the same value as OPENSHIFT_LOG_DIR.
From that ERB file, OpenShift Enterprise creates an env/OPENSHIFT_MONGODB_DB_LOG_DIR environment variable containing:
/var/lib/openshift/aa9e0f66e6451791f86904eef0939e/mongodb/log/
Copy to Clipboard Toggle word wrap

Example 6.2. php.ini Configuration Template

A conf/php.ini.erb file contains:
upload_tmp_dir = "<%= "#{ENV['OPENSHIFT_PHP_DIR']}tmp/" %>"
session.save_path = "<%= "#{ENV['OPENSHIFT_PHP_DIR']}sessions/" %>"
Copy to Clipboard Toggle word wrap
From that ERB file, OpenShift Enterprise creates a conf/php.ini file containing:
upload_tmp_dir = "/var/lib/openshift/aa9e0f66e6451791f86904eef0939e/php/tmp/"
session.save_path = "/var/lib/openshift/aa9e0f66e6451791f86904eef0939e/php/sessions/"
Copy to Clipboard Toggle word wrap
Other possible uses for ERB templates are includes values in httpd configuration files, database configuration values for storing persistent data in the OPENSHIFT_DATA_DIR directory, and the application name value in the pom.xml file.
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat