Skip to content

Commit f2bc2a5

Browse files
committed
Merge pull request #9 from CowboysFan/cart_spec_guide
Migrating cart spec guide topics
2 parents 98ab980 + 240c9e3 commit f2bc2a5

21 files changed

+1883
-0
lines changed

_build_cfg.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,30 @@ Topics:
3333
File: configuring_client_tools
3434
- Name: Updating Client Tools
3535
File: updating_client_tools
36+
37+
---
38+
Name: Reference for Developing Cartridges
39+
Dir: cartridge_specification_guide
40+
Topics:
41+
- Name: Managed Files
42+
File: managed_files
43+
- Name: Locking Cartridges
44+
File: locking_cartridges
45+
- Name: Exposing Services
46+
File: exposing_services
47+
- Name: Creating Template Directories for Language Cartridges
48+
File: creating_template_directories_for_language_cartridges
49+
- Name: Cartridge Scripts
50+
File: cartridge_scripts
51+
- Name: Environment Variables
52+
File: environment_variables
53+
- Name: Cartridge Events
54+
File: cartridge_events
55+
- Name: OpenShift Build Process
56+
File: openshift_build_process
57+
- Name: Backing Up and Restoring Cartridges
58+
File: backing_up_and_restoring_cartridges
59+
- Name: Upgrading Custom and Community Cartridges
60+
File: upgrading_custom_and_community_cartridges
61+
- Name: OpenShift Cartridge Reference
62+
File: openshift_cartridge_reference
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
OpenShift Documentation Project <dev@lists.openshift.redhat.com>
2+
DOC_BRANCH_VERSION
3+
:data-uri:
4+
:icons:
5+
6+
[[backing_up_and_restoring_cartridges]]
7+
== Backing Up and Restoring Cartridges
8+
9+
OpenShift provides +snapshot+ and +restore+ features for user applications. These features enable OpenShift application developers to:
10+
11+
12+
* Snapshot the current state of an application to create a backup.
13+
* Restore an application from an archived state.
14+
* Copy or rename an application by taking a snapshot, creating a new application, then restoring the snapshot data to the new application.
15+
16+
[[snapshot]]
17+
=== Snapshot
18+
19+
When an application developer runs the +rhc snapshot save+ command, OpenShift creates an archive of the application and performs the following steps:
20+
21+
. Stops the application by running the +gear stop+ command.
22+
. Runs the +control pre-snapshot+ command for each cartridge on the gear. You can control cartridge serialization in the snapshot by implementing the +control pre-snapshot+ command in conjunction with exclusions. For example, you can snapshot to a database dump instead of a database file.
23+
. Builds a list of exclusions from the [variable]#snapshot_exclusions## entry in the [filename]#$cartridge_name/metadata/managed_files.yml# file for each cartridge on the gear.
24+
. Creates an archive of the application in [filename]#tar.gz# format and writes it to [literal]#stdout# for use by the client tools. In addition to the files listed in the [variable]#snapshot_exclusions# entry in the [filename]#managed_files.yml# file, OpenShift excludes the following files:
25+
26+
* Selected gear user files: [filename]#.tmp#, [filename]#.ssh#, [filename]#.sandbox#.
27+
28+
29+
* Application state file: [filename]#app-root/runtime/.state#.
30+
31+
32+
* Bash history file: [filename]#$OPENSHIFT_DATA_DIR/.bash_history#.
33+
34+
35+
. Runs the +control post-snapshot+ command for each cartridge on the gear. Use this script to cleanup after the snapshot runs.
36+
37+
38+
. Will either stop or start the gear based on the state of the application before the snapshot.
39+
40+
*Snapshot Exclusions*
41+
42+
Use the optional [variable]#snapshot_exclusions# entry in the [filename]#$cartridge_name/metadata/managed_files.yml# file to list files to exclude from the snapshot and restore process. File patterns originate from the [variable]#OPENSHIFT_HOMEDIR# directory, not the cartridge directory. Do not exclude files that your cartridge requires to operate.
43+
44+
45+
46+
.snapshot_exclusions Entry
47+
----
48+
snapshot_exclusions Entry
49+
snapshot_exclusions:
50+
- mydir/*
51+
----
52+
53+
OpenShift uses the +tar+ command when performing snapshots. See the +tar+ man page +--exclude-from+ option for more information.
54+
55+
[[restore]]
56+
=== Restore
57+
58+
When an application developer runs the +rhc snapshot restore+ command, OpenShift restores the application from an archive in the following steps:
59+
60+
61+
. Prepares the application for restoration.
62+
63+
* If the archive contains a Git repository, OpenShift runs the +gear pre-receive+ command.
64+
65+
66+
* If the archive does not contain a Git repository, OpenShift runs the +gear stop+ command.
67+
68+
. Runs the +control pre-restore+ command for each cartridge on the gear. This enables you to control the restoration of your cartridge, for example by deleting an old database dump.
69+
. Builds a list of file name changes to apply during the restoration from the [variable]#restore_transforms## entry in the [filename]#$cartridge_name/metadata/managed_files.yml# file for each cartridge on the gear.
70+
. Extracts the archive into the gear user's home directory, overwriting existing files and applying the file name changes listed in the [variable]#restore_transforms# entry in the [filename]#managed_files.yml# file.
71+
. Runs the +control post-restore+ command for each cartridge on the gear. Use this script to load a database flat file into the running database.
72+
. Resumes the application.
73+
74+
* If the archive contains a Git repository, OpenShift runs the +gear postreceive+ command.
75+
* If the archive does not contain a Git repository, OpenShift runs the +gear start+ command.
76+
77+
. Will either stop or start the gear based on the state of the application before restoring.
78+
79+
*Restoring with Transformed File Names*
80+
81+
Use the optional [variable]#restore_transforms# entry in the [filename]#$cartridge_name/metadata/managed_files.yml# file to provide scripts that transform file names when OpenShift restores an application. This entry enables you to restore older snapshots to a newer cartridge with file name changes.
82+
83+
84+
.restore_transforms Entry
85+
----
86+
restore_transforms:
87+
- s|${OPENSHIFT_GEAR_NAME}/data|app-root/data|
88+
----
89+
90+
OpenShift uses the +tar+ command when restoring a gear. See the +tar+ man page +--transform+ option for more information.
91+
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
OpenShift Documentation Project <dev@lists.openshift.redhat.com>
2+
DOC_BRANCH_VERSION
3+
:data-uri:
4+
:icons:
5+
6+
[[cartridge_events]]
7+
== Cartridge Events
8+
9+
OpenShift provides a publish and subscribe system that enables a cartridge to act when a developer adds or removes another cartridge in an application.
10+
11+
The _Publishes_ and _Subscribes_ elements in the [filename]#$cartridge_name/metadata/manifest.yml# file detail support for cartridge events.
12+
13+
[[cartridge_event_publishing]]
14+
=== Cartridge Event Publishing
15+
16+
When OpenShift adds a cartridge to an application, it uses entries in the _Publishes_ section of the [filename]#$cartridge_name/metadata/manifest.yml# file to construct events sent to other cartridges in the application. Define publish events in the [filename]#manifest.yml# file using the following format:
17+
18+
----
19+
Publishes:
20+
<event_name>:
21+
Type: "<event type>"
22+
----
23+
24+
.PHP Cartridge Publishes Entry
25+
----
26+
Publishes:
27+
get-php-ini:
28+
Type: "FILESYSTEM:php-ini"
29+
publish-http-url:
30+
Type: "NET_TCP:httpd-proxy-info"
31+
publish-gear-endpoint:
32+
Type: "NET_TCP:gear-endpoint-info"
33+
----
34+
35+
For each _Publishes_ entry, OpenShift runs a script named [filename]#$cartridge_name/hooks/$event_name#.
36+
37+
OpenShift joins lines of output that the [filename]#hooks/$event_name# script writes to [literal]#stdout# with single spaces, then inputs the result to subscriber scripts in other cartridges that match the [variable]#Type# of the publish event. The input to matching subscriber scripts is prefaced with [filename]#hooks/<event_name> <gear_name> <namespace> <gear_uuid>#.
38+
39+
[[cartridge_event_subscriptions]]
40+
=== Cartridge Event Subscriptions
41+
42+
When OpenShift adds a cartridge to an application, it uses entries in the _Subscribes_ section of the [filename]#$cartridge_name/metadata/manifest.yml# file in other cartridges to determine what actions to take for those other cartridges. Define subscribe events in the [filename]#manifest.yml# file using the following format:
43+
44+
----
45+
Subscribes:
46+
<event_name>:
47+
Type: "<event type>"
48+
----
49+
50+
.PHP Cartridge Subscribes Entry
51+
----
52+
Subscribes:
53+
set-env:
54+
Type: "ENV:*"
55+
Required: false
56+
set-mysql-connection-info:
57+
Type: "NET_TCP:db:mysql"
58+
Required: false
59+
set-postgres-connection-info:
60+
Type: "NET_TCP:db:postgres"
61+
Required: false
62+
set-doc-url:
63+
Type: "STRING:urlpath"
64+
Required: false
65+
----
66+
67+
When OpenShift processes a cartridge publish script, it inputs the result to subscriber scripts in other cartridges that match the [variable]#Type# of the publish event. The input to matching subscriber scripts is prefaced with [filename]#$cartridge_name/hooks/<event_name> <gear_name> <namespace> <gear_uuid>#.
68+
69+
For each matching _Subscribes_ entry, OpenShift runs a script named [filename]#$cartridge_name/hooks/$event_name#. OpenShift must send and process entries marked with +Required: true+.
70+
71+
The publisher script determines the format of the information input to the subscriber script. Ensure that subscriber script can parse the input correctly.
72+
73+
[[cartridge_event_example]]
74+
=== Cartridge Event Example
75+
In this example, an application developer adds a MySQL database cartridge to a PHP application. The publish and subscribe relationship between the cartridges enables the PHP cartridge to set environment variables on its gear so it can connect to the new MySQL cartridge, which is on a different gear.
76+
77+
*MySQL Cartridge as Publisher*
78+
79+
The MySQL cartridge lists a [variable]#publish-mysql-connection-info# event in the _Publishes_ section of its [filename]#mysql/metadata/manifest.yml# file:
80+
81+
----
82+
Publishes:
83+
publish-mysql-connection-info:
84+
Type: "NET_TCP:db:mysql"
85+
----
86+
87+
The MySQL cartridge implements a script in [filename]#mysql/hooks/publish-mysql-connection-info#.
88+
89+
*PHP Cartridge as Subscriber*
90+
91+
The PHP cartridge lists a [variable]#set-mysql-connection-info# event in the _Subscribes_ section of its [filename]#php/metadata/manifest.yml# file:
92+
93+
----
94+
Subscribes:
95+
set-mysql-connection-info:
96+
Type: "NET_TCP:db:mysql"
97+
----
98+
99+
100+
The PHP cartridge implements a script in [filename]#php/hooks/set-mysql-connection-info#.
101+
102+
*Cartridge Event Communication Process*
103+
104+
OpenShift matches the event [variable]#Type# in the PHP cartridge's _Subscribes_ list to the event [variable]#Type# in the MySQL cartridge's _Publishes_ list. In this example, the event [variable]#Type# is "NET_TCP:db:mysql".
105+
106+
The MySQL cartridge's [filename]#publish-mysql-connection-info# script outputs the username, host, port, URL, and password required to connect to the MySQL instance:
107+
108+
----
109+
OPENSHIFT_MYSQL_DB_USERNAME=username;
110+
OPENSHIFT_MYSQL_DB_PASSWORD=password;
111+
OPENSHIFT_MYSQL_DB_HOST=hostname;
112+
OPENSHIFT_MYSQL_DB_PORT=port;
113+
OPENSHIFT_MYSQL_DB_URL=url;
114+
----
115+
116+
OpenShift sends the output of the MySQL cartridge's [filename]#publish-mysql-connection-info# to the PHP cartridge's [filename]#set-mysql-connection-info# script using the following format:
117+
118+
----
119+
hooks/publish-mysql-connection-info gear_name namespace gear_uuid 'OPENSHIFT_MYSQL_DB_USERNAME=username;OPENSHIFT_MYSQL_DB_PASSWORD=password;OPENSHIFT_MYSQL_DB_HOST=hostname;OPENSHIFT_MYSQL_DB_PORT=port;OPENSHIFT_MYSQL_DB_URL=url;'
120+
----
121+
122+
Note that the publisher script determines the format of the information input to the subscriber script. When writing subscriber scripts, ensure that they parse the input correctly.
123+

0 commit comments

Comments
 (0)