-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrating cart spec guide topics #9
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
cartridge_specification_guide/backing_up_and_restoring_cartridges.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
OpenShift Documentation Project <dev@lists.openshift.redhat.com> | ||
DOC_BRANCH_VERSION | ||
:data-uri: | ||
:icons: | ||
|
||
[[backing_up_and_restoring_cartridges]] | ||
== Backing Up and Restoring Cartridges | ||
|
||
OpenShift provides +snapshot+ and +restore+ features for user applications. These features enable OpenShift application developers to: | ||
|
||
|
||
* Snapshot the current state of an application to create a backup. | ||
* Restore an application from an archived state. | ||
* Copy or rename an application by taking a snapshot, creating a new application, then restoring the snapshot data to the new application. | ||
|
||
[[snapshot]] | ||
=== Snapshot | ||
|
||
When an application developer runs the +rhc snapshot save+ command, OpenShift creates an archive of the application and performs the following steps: | ||
|
||
. Stops the application by running the +gear stop+ command. | ||
. 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. | ||
. 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. | ||
. 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: | ||
|
||
* Selected gear user files: [filename]#.tmp#, [filename]#.ssh#, [filename]#.sandbox#. | ||
|
||
|
||
* Application state file: [filename]#app-root/runtime/.state#. | ||
|
||
|
||
* Bash history file: [filename]#$OPENSHIFT_DATA_DIR/.bash_history#. | ||
|
||
|
||
. Runs the +control post-snapshot+ command for each cartridge on the gear. Use this script to cleanup after the snapshot runs. | ||
|
||
|
||
. Will either stop or start the gear based on the state of the application before the snapshot. | ||
|
||
*Snapshot Exclusions* | ||
|
||
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. | ||
|
||
|
||
|
||
.snapshot_exclusions Entry | ||
---- | ||
snapshot_exclusions Entry | ||
snapshot_exclusions: | ||
- mydir/* | ||
---- | ||
|
||
OpenShift uses the +tar+ command when performing snapshots. See the +tar+ man page +--exclude-from+ option for more information. | ||
|
||
[[restore]] | ||
=== Restore | ||
|
||
When an application developer runs the +rhc snapshot restore+ command, OpenShift restores the application from an archive in the following steps: | ||
|
||
|
||
. Prepares the application for restoration. | ||
|
||
* If the archive contains a Git repository, OpenShift runs the +gear pre-receive+ command. | ||
|
||
|
||
* If the archive does not contain a Git repository, OpenShift runs the +gear stop+ command. | ||
|
||
. 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. | ||
. 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. | ||
. 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. | ||
. 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. | ||
. Resumes the application. | ||
|
||
* If the archive contains a Git repository, OpenShift runs the +gear postreceive+ command. | ||
* If the archive does not contain a Git repository, OpenShift runs the +gear start+ command. | ||
|
||
. Will either stop or start the gear based on the state of the application before restoring. | ||
|
||
*Restoring with Transformed File Names* | ||
|
||
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. | ||
|
||
|
||
.restore_transforms Entry | ||
---- | ||
restore_transforms: | ||
- s|${OPENSHIFT_GEAR_NAME}/data|app-root/data| | ||
---- | ||
|
||
OpenShift uses the +tar+ command when restoring a gear. See the +tar+ man page +--transform+ option for more information. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
OpenShift Documentation Project <dev@lists.openshift.redhat.com> | ||
DOC_BRANCH_VERSION | ||
:data-uri: | ||
:icons: | ||
|
||
[[cartridge_events]] | ||
== Cartridge Events | ||
|
||
OpenShift provides a publish and subscribe system that enables a cartridge to act when a developer adds or removes another cartridge in an application. | ||
|
||
The _Publishes_ and _Subscribes_ elements in the [filename]#$cartridge_name/metadata/manifest.yml# file detail support for cartridge events. | ||
|
||
[[cartridge_event_publishing]] | ||
=== Cartridge Event Publishing | ||
|
||
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: | ||
|
||
---- | ||
Publishes: | ||
<event_name>: | ||
Type: "<event type>" | ||
---- | ||
|
||
.PHP Cartridge Publishes Entry | ||
---- | ||
Publishes: | ||
get-php-ini: | ||
Type: "FILESYSTEM:php-ini" | ||
publish-http-url: | ||
Type: "NET_TCP:httpd-proxy-info" | ||
publish-gear-endpoint: | ||
Type: "NET_TCP:gear-endpoint-info" | ||
---- | ||
|
||
For each _Publishes_ entry, OpenShift runs a script named [filename]#$cartridge_name/hooks/$event_name#. | ||
|
||
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>#. | ||
|
||
[[cartridge_event_subscriptions]] | ||
=== Cartridge Event Subscriptions | ||
|
||
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: | ||
|
||
---- | ||
Subscribes: | ||
<event_name>: | ||
Type: "<event type>" | ||
---- | ||
|
||
.PHP Cartridge Subscribes Entry | ||
---- | ||
Subscribes: | ||
set-env: | ||
Type: "ENV:*" | ||
Required: false | ||
set-mysql-connection-info: | ||
Type: "NET_TCP:db:mysql" | ||
Required: false | ||
set-postgres-connection-info: | ||
Type: "NET_TCP:db:postgres" | ||
Required: false | ||
set-doc-url: | ||
Type: "STRING:urlpath" | ||
Required: false | ||
---- | ||
|
||
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>#. | ||
|
||
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+. | ||
|
||
The publisher script determines the format of the information input to the subscriber script. Ensure that subscriber script can parse the input correctly. | ||
|
||
[[cartridge_event_example]] | ||
=== Cartridge Event Example | ||
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. | ||
|
||
*MySQL Cartridge as Publisher* | ||
|
||
The MySQL cartridge lists a [variable]#publish-mysql-connection-info# event in the _Publishes_ section of its [filename]#mysql/metadata/manifest.yml# file: | ||
|
||
---- | ||
Publishes: | ||
publish-mysql-connection-info: | ||
Type: "NET_TCP:db:mysql" | ||
---- | ||
|
||
The MySQL cartridge implements a script in [filename]#mysql/hooks/publish-mysql-connection-info#. | ||
|
||
*PHP Cartridge as Subscriber* | ||
|
||
The PHP cartridge lists a [variable]#set-mysql-connection-info# event in the _Subscribes_ section of its [filename]#php/metadata/manifest.yml# file: | ||
|
||
---- | ||
Subscribes: | ||
set-mysql-connection-info: | ||
Type: "NET_TCP:db:mysql" | ||
---- | ||
|
||
|
||
The PHP cartridge implements a script in [filename]#php/hooks/set-mysql-connection-info#. | ||
|
||
*Cartridge Event Communication Process* | ||
|
||
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". | ||
|
||
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: | ||
|
||
---- | ||
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; | ||
---- | ||
|
||
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: | ||
|
||
---- | ||
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;' | ||
---- | ||
|
||
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. | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The double-containment is not necessary. You can just do:
You don't need both the "====" and "----" containers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difference I see is the way the output is rendered, unless that depends on the CSS design aspect. When you don't use the double-containment, the callout title renders like so:
snapshot_exclusions Entry
Whereas if you use the double containment, it's automatically numbered and it renders like so:
Example 1.snapshot_exclusions Entry
And then the next one would be Example 2, and so on. But again, that could be CSS?