OpenShift 2.0 User Guide en US
OpenShift 2.0 User Guide en US
User Guide
Using OpenShift to manage your applications in the cloud
Legal Notice
Copyright 2012 Red Hat, Inc. The text of and illustrations in this document are licensed by Red Hat under
a Creative Commons AttributionShare Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CCBY-SA is available at . In accordance with CC-BY-SA, if you distribute this document or an adaptation of
it, you must provide the URL for the original version. Red Hat, as the licensor of this document, waives the
right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by
applicable law. Red Hat, Red Hat Enterprise Linux, the Shadowman logo, JBoss, MetaMatrix, Fedora,
OpenShift, the Infinity Logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States
and other countries. Linux is the registered trademark of Linus Torvalds in the United States and other
countries. Java is a registered trademark of Oracle and/or its affiliates. XFS is a trademark of Silicon
Graphics International Corp. or its subsidiaries in the United States and/or other countries. All other
trademarks are the property of their respective owners. 1801 Varsity Drive Raleigh, NC 27 606-207 2 USA
Phone: +1 919 7 54 37 00 Phone: 888 7 33 4281 Fax: +1 919 7 54 37 01
Keywords
Abstract
This guide provides an introduction to OpenShift and documents its application management functions.
Table of Contents
Table of Contents
.Preface
...............................................................................
1. Document Conventions
1.1. T ypographic Conventions
1.2. Pull-quote Conventions
1.3. Notes and Warnings
2. Getting Help
2.1. Do You Need Help?
2.2. We Need Feedback!
6
6
6
7
8
8
8
9
. . . . . . . . . 1.
Chapter
. . .Introduction
....................................................................
10
.Chapter
. . . . . . . . 2.
. . .OpenShift
. . . . . . . . . . .Overview
.........................................................
2.1. Platform Overview
2.2. System Resources and Application Containers
11
11
11
.Chapter
. . . . . . . . 3.
. . .OpenShift
. . . . . . . . . . .User
. . . . .Interfaces
....................................................
3.1. OpenShift Web Interface
3.1.1. Accessing the OpenShift Management Console
3.2. OpenShift Command Line Interface
13
13
13
13
.Chapter
........4
. ...Account
. . . . . . . . .Management
...........................................................
4.1. View Account Details
4.2. Changing Your Password
4.3. Resetting Your Password
14
14
14
14
.Chapter
. . . . . . . . 5.
. . .Namespaces
....................................................................
5.1. Management Console
5.1.1. Altering a Namespace
5.2. Command Line Interface
5.2.1. Creating a Namespace
5.2.2. Viewing a Namespace
5.2.3. Altering a Namespace
5.2.4. Deleting a Namespace
15
15
15
16
16
17
17
18
.Chapter
. . . . . . . . 6.
. . .Applications
. . . . . . . . . . . . . and
. . . . .Cartridges
..................................................
6.1. Applications Overview
6.1.1. Scaled Applications
6.1.1.1. How Scaling Works
6.1.1.2. Automatic and Manual Scaling
6.1.2. Non-scaled Applications
6.2. Cartridges Overview
6.2.1. Addon Cartridges
6.3. Creating an Application
6.3.1. Management Console
6.3.1.1. Creating Instant Applications
6.3.1.2. Cloning Application Files
6.3.2. Command Line Interface
6.3.2.1. Creating Non-scaled Applications
6.3.2.2. Creating Scaled Applications
6.3.2.2.1. Disabling Automatic Scaling
6.3.2.2.2. Scaling an Application Manually
6.3.2.3. Using DIY Cartridges
6.3.2.4. Using Arbitrary DNS Names
20
20
20
21
21
22
22
22
23
23
23
24
24
24
25
26
27
27
28
28
28
28
28
29
29
29
30
30
30
30
30
31
31
33
33
33
33
34
34
35
35
35
36
37
37
38
38
38
38
39
39
39
39
39
41
42
42
42
43
43
43
44
45
45
45
45
47
54
54
54
55
55
56
56
Preface
7.4. Node.js
7.4.1. Repository Layout
7.4.2. Installing Node Modules
7.5. Scheduling T imed Jobs with Cron
7.6. Sending and Receiving Email
7.6.1. Overview
7.6.2. Email Port Configuration
57
57
57
58
59
59
59
.Chapter
. . . . . . . . 8.
. . .SSH
. . . . .Authentication
...............................................................
8.1. Resolving Authentication Issues
8.1.1. Using the Interactive Setup Wizard
8.2. Managing SSH Keys
8.2.1. Management Console
8.2.1.1. Generating New Keys
8.2.1.2. Adding a Key
8.2.1.3. Removing a Key
8.2.2. Command Line Interface
8.2.2.1. Generating and Uploading SSH Keys Manually
8.2.2.2. Viewing Public Keys
8.2.2.3. Adding a Key
8.2.2.4. Removing a Key
61
61
61
61
61
61
62
62
62
62
63
63
63
.Chapter
. . . . . . . . 9.
. . .Monitoring
. . . . . . . . . . . and
. . . . .T. roubleshooting
...................................................
9.1. Monitoring Application Resources
9.2. MongoDB Monitoring Service (MMS)
9.2.1. Configuring an Application with MMS
9.2.2. Monitoring an Applications with MMS
9.2.2.1. Adding Hosts to MMS
9.2.2.2. MMS Monitoring with a Browser
9.3. T roubleshooting JBoss Applications
9.3.1. Using T hread Dumps
9.3.2. Inspecting Server, Boot and Other Log Files
9.4. Performing Application Maintenance from Your Workstation
9.4.1. Port Forwarding
9.4.1.1. Port Forwarding on Mac OS X
64
64
65
65
66
66
67
68
68
69
69
69
70
.Chapter
. . . . . . . . 10.
. . . . Backing
. . . . . . . . .Up
. . . and
. . . . .Restoring
. . . . . . . . . . Applications
........................................
10.1. Creating Application Snapshots
10.2. Restoring Application Snapshots
72
72
72
. . . . . . . . . .History
Revision
......................................................................
74
.Index
...............................................................................
A
B
F
H
J
S
U
74
74
75
76
76
76
76
76
Preface
Preface
1. Document Conventions
T his manual uses several conventions to highlight certain words and phrases and draw attention to
specific pieces of information.
In PDF and paper editions, this manual uses typefaces drawn from the Liberation Fonts set. T he
Liberation Fonts set is also used in HT ML editions if the set is installed on your system. If not, alternative
but equivalent typefaces are displayed. Note: Red Hat Enterprise Linux 5 and later includes the
Liberation Fonts set by default.
1.1. T ypographic Conventions
Four typographic conventions are used to call attention to specific words and phrases. T hese
conventions, and the circumstances they apply to, are as follows.
Mono-spaced Bold
Used to highlight system input, including shell commands, file names and paths. Also used to highlight
keys and key combinations. For example:
T o see the contents of the file m y_next_bestselling_novel in your current working
directory, enter the cat m y_next_bestselling_novel command at the shell prompt
and press Enter to execute the command.
T he above includes a file name, a shell command and a key, all presented in mono-spaced bold and all
distinguishable thanks to context.
Key combinations can be distinguished from an individual key by the plus sign that connects each part of
a key combination. For example:
Press Enter to execute the command.
Press Ctrl+Alt+F2 to switch to a virtual terminal.
T he first example highlights a particular key to press. T he second example highlights a key combination:
a set of three keys pressed simultaneously.
If source code is discussed, class names, methods, functions, variable names and returned values
mentioned within a paragraph will be presented as above, in m ono-spaced bold. For example:
File-related classes include filesystem for file systems, file for files, and dir for
directories. Each class has its own associated set of permissions.
Proportional Bold
T his denotes words or phrases encountered on a system, including application names; dialog box text;
labeled buttons; check-box and radio button labels; menu titles and sub-menu titles. For example:
Choose System Preferences Mouse from the main menu bar to launch Mouse
Preferences. In the Buttons tab, click the Left-handed m ouse check box and click
Close to switch the primary mouse button from the left to the right (making the mouse
suitable for use in the left hand).
T o insert a special character into a gedit file, choose Applications Accessories
Character Map from the main menu bar. Next, choose Search Find from the
Character Map menu bar, type the name of the character in the Search field and click
Next. T he character you sought will be highlighted in the Character T able. Double-click
this highlighted character to place it in the T ext to copy field and then click the Copy
button. Now switch back to your document and choose Edit Paste from the gedit menu
bar.
T he above text includes application names; system-wide menu names and items; application-specific
menu names; and buttons and text found within a GUI interface, all presented in proportional bold and all
distinguishable by context.
Mono-spaced Bold Italic or Proportional Bold Italic
Whether mono-spaced bold or proportional bold, the addition of italics indicates replaceable or variable
text. Italics denotes text you do not input literally or displayed text that changes depending on
circumstance. For example:
T o connect to a remote machine using ssh, type ssh username@ domain.name at a shell
prompt. If the remote machine is exam ple.com and your username on that machine is
john, type ssh john@ exam ple.com .
T he m ount -o rem ount file-system command remounts the named file system. For
example, to remount the /hom e file system, the command is m ount -o rem ount /hom e.
T o see the version of a currently installed package, use the rpm -q package command. It
will return a result as follows: package-version-release.
Note the words in bold italics above username, domain.name, file-system, package, version and
release. Each word is a placeholder, either for text you enter when issuing a command or for text
displayed by the system.
Aside from standard usage for presenting the title of a work, italics denotes the first use of a new and
important term. For example:
Publican is a DocBook publishing system.
1.2. Pull-quote Conventions
T erminal output and source code listings are set off visually from the surrounding text.
Output sent to a terminal is set in m ono-spaced rom an and presented thus:
books
books_tests
Desktop
Desktop1
documentation
downloads
drafts
images
mss
notes
photos
scripts
stuff
svgs
svn
Source-code listings are also set in m ono-spaced rom an but add syntax highlighting as follows:
10
package org.jboss.book.jca.ex1;
import javax.naming.InitialContext;
public class ExClient
{
public static void main(String args[])
throws Exception
{
InitialContext iniCtx = new InitialContext();
Object
ref
= iniCtx.lookup("EchoBean");
EchoHome
home
= (EchoHome) ref;
Echo
echo
= home.create();
System.out.println("Created Echo");
System.out.println("Echo.echo('Hello') = " + echo.echo("Hello"));
}
}
Note
Notes are tips, shortcuts or alternative approaches to the task at hand. Ignoring a note should
have no negative consequences, but you might miss out on a trick that makes your life easier.
Important
Important boxes detail things that are easily missed: configuration changes that only apply to the
current session, or services that need restarting before an update will apply. Ignoring a box
labeled 'Important' will not cause data loss but may cause irritation and frustration.
Warning
Warnings should not be ignored. Ignoring warnings will most likely cause data loss.
2. Getting Help
2.1. Do You Need Help?
If you experience difficulty with a procedure or other information described in this documentation, visit the
Red Hat Knowledgebase at http://kbase.redhat.com to search or browse through technical support
articles about Red Hat products, or visit the Red Hat Customer Portal at http://access.redhat.com. You
can also access the OpenShift web site at https://openshift.redhat.com/ to find blogs, FAQs, forums, and
other sources of information.
Red Hat also hosts a large number of electronic mailing lists for discussion of Red Hat software and
11
technology. You can find a list of publicly available mailing lists at https://www.redhat.com/mailman/listinfo.
Click the name of any mailing list to subscribe to that list or to access the list archives.
2.2. We Need Feedback!
If you find a typographical or any other error in this manual, or if you have thought of a way to make this
manual better, we would love to hear from you! Please submit a report in Bugzilla:
http://bugzilla.redhat.com/ against the product OpenShift Origin.
When submitting a bug report, be sure to mention the manual's identifier: Docs User Guide
If you have a suggestion for improving the documentation, try to be as specific as possible when
describing it. If you have found an error, please include the section number and some of the surrounding
text so we can find it easily.
12
Chapter 1. Introduction
OpenShift is Red Hat's Platform as a Service (PaaS) offering. OpenShift is an application platform in the
cloud where application developers and teams can build, test, deploy, and run their applications with
automatic scaling. OpenShift provides developers with a wide selection of programming languages and
frameworks including Java, Ruby, PHP, Perl, Python, and Node.js. It also provides integrated developer
tools to support the application lifecycle, including Eclipse integration, JBoss Developer Studio, Jenkins,
Maven, and GIT . OpenShift uses an open source ecosystem to provide key platform services for mobile
applications (Appcelerator), NoSQL services (MongoDB), SQL services (Postgres, MySQL), and more.
JBoss provides an enterprise-class middleware platform for Java applications, providing support for
Java EE6 and integrated services such as transactions and messaging, which are critical for enterprise
applications.
T he foundation of the OpenShift platform is Red Hat Enterprise Linux, which provides a secure and
scalable multi-tenant operating system to address the needs of enterprise-class applications as well as
providing integrated application runtimes and libraries.
T his document describes how to navigate and utilize an OpenShift environment. It provides information
on overall architecture, common application management tasks via web and command line interfaces,
and basic troubleshooting. It is intended for developers and administrators of applications on OpenShift.
13
14
Chapter 5. Namespaces
15
If you do not have any applications, the Create a New Application screen opens. If you have
applications, you are taken to the My Applications screen.
16
Chapter 5. Namespaces
default
FreeShift
3
3
openshift.redhat.com
small
17
Chapter 5. Namespaces
You must create a namespace before you can create an application. OpenShift uses non-strict domain
names (that is, there is no preceding period), and the domain name forms part of the application name.
T he syntax for the application name is ApplicationNamenamespace.example.com.
Each username can only support a single namespace, but you can create multiple applications within the
namespace. If you need multiple namespaces, you need to create multiple accounts using different
usernames.
Important
T his procedure alters the URLs for your applications. You need to update any bookmarks and
external links you have made to these URLs. Links made using an alias do not need to be
changed. See Section 6.3.2.4, Using Arbitrary DNS Names.
Procedure 5.1. T o change your namespace:
1. Access the Management Console and click My Account in the navigation bar at the top of the
page.
2. Scroll down to the Nam espace section and click Change your nam espace.
3. Enter your desired namespace in the box provided and click Save.
T he public URLs and repository addresses of your applications automatically update with the new
namespace. T o enable the git push command to function properly, update the git config file using
the following procedure.
Procedure 5.2. T o update the git config files:
18
Chapter 5. Namespaces
1. Access the Management console and click My Applications in the navigation bar at the top of
the page.
2. Click on your first application.
3. Copy the entire SSH address located in the GIT REPOSIT ORY box.
4. Open the git config file located in path/to/appdirectory/.git/ and replace the remote URL
address with the new SSH address for your application.
5. Repeat the previous four steps for each of the applications in the altered namespace to update
their git config files.
namespace specifies the namespace that you want to create. T his must contain a maximum of 16
alphanumeric characters.
rhlogin this can be your Red Hat Network login or the email address that you used to apply for
your OpenShift account.
password the password that you used to apply for your OpenShift account.
Optional Parameters
Further optional parameters exist that you can pass to the rhc dom ain create command. Refer to
rhc dom ain create --help for details.
Note
T he rhc dom ain create command creates a local configuration file in
~/.openshift/express.conf and updates it with your rhlogin. T he rhc client tools use the
login specified in the ~/.openshift/express.conf file by default when you run further
commands. If no default login is configured, or if you want to use a different login, include the -l
rhlogin parameter as a command line argument.
19
Note
You do not need SSH keys to create a domain. You only need to create SSH keys and upload
them to the server when you want to create applications and communicate with your domain.
OpenShift uses a blacklist to restrict the list of available namespace and application names that
you can use. T his list is maintained on the server. If you try to use rhc dom ain create or
rhc app create with any members of this blacklist, the command will fail.
20
Important
T he rhc dom ain update command alters the URLs of your applications. You need to update
any bookmarks and external links you have made to these URLs. Links made using an alias do
not need to be changed. Refer to Section 6.3.2.4, Using Arbitrary DNS Names for more
information.
Note
If no SSH keys are found in the .ssh folder of your home directory, the rhc dom ain update
command generates a new pair of keys for you. You will then be prompted to upload the public
SSH key to the OpenShift server. Refer to the SSH Authentication chapter for more information.
If any applications are listed, use the rhc app delete command to remove them.
$ rhc app delete <ApplicationName>
Warning
Application removal is irreversible. All remote data associated with the application will be
removed.
2. Use the rhc dom ain delete command to delete the namespace.
21
After you have deleted your namespace, you need to create a new one before you can create any new
applications or use the other client tools.
22
Description
Namespace
Application Name
Alias
Users can provide their own DNS names for the application by registering
an alias with OpenShift and pointing the DNS entry to the OpenShift servers.
Git repository
Allows you to modify your application code locally; you can then run the git
push command to deploy the revised code.
23
resources accordingly. You need to specify whether an application is scaled or not when you create the
application. A scaled application cannot be converted to a non-scaled application. Likewise, a non-scaled
application cannot be converted to a scaled application.
6.1.1.1. How Scaling Works
Each application created on OpenShift always has the web cartridge associated with it. T he web
cartridge can, for example, be a PHP cartridge. When an application is scaled, a second cartridge, called
HAProxy, is added to the application. T he HAProxy cartridge listens to all incoming web page requests
for an application and passes them on to the web cartridge, following defined guidelines for load
monitoring.
As the number of web page requests to an application increase, the HAProxy will inform OpenShift when
an overload of requests is detected. OpenShift will then create a copy of the existing web cartridge on a
separate gear. In such a case, the web cartridge now has been scaled up two times. T his process is
repeated as more web page requests are detected by the HAProxy cartridge, and each time a copy of
the web cartridge is created on a separate gear, the application scale factor increases by one.
However, not all OpenShift applications can be scaled, as detailed in the table below.
T able 6.2. Applications that can or cannot be scaled
T ype of Application
Scalable
Yes
Yes
Yes
Yes
PHP
Yes
Python
Yes
Perl
Yes
Ruby
Yes
Node.js
Yes
Jenkins
No
HAProxy
No
Z end Server
No
DIY
No
Note
You can add only MySQL 5.1, MongoDB, PostgreSQL, or Jenkins Client 1.4 cartridges to scaled
applications.
24
Note
Web cartridges can only be added to new applications.
Use the rhc cartridge list command to view the current list of all cartridges available on
OpenShift.
6.2.1. Addon Cartridges
After you create an OpenShift application with the required web cartridge, you can then add a number of
other cartridges that provide capabilities like databases, scheduled jobs, or continuous integration. T he
table below describes the functionality of the different types of add-on cartridges available with
OpenShift.
T able 6.3. Add-on Cartridge Functions
Function
Description
Database
Provide your application with one of several database back ends. Examples
include MySQL and PostgreSQL.
Database management
Provide functionality for managing your application's database using thirdparty software. Examples include phpMyAdmin, RockMongo, and 10gen's
MongoDB Monitoring Service (MMS).
Monitoring and
Management
Again, you can run the rhc cartridge list command to view the current list of available add-on
cartridges. At the time of this writing, the following add-on cartridges are available:
Database Cartridges
MySQL Database 5.1 MySQL is a multi-user, multi-threaded SQL database server
MongoDB NoSQL Database 2.2 MongoDB is a scalable, high-performance, open source NoSQL
database
PostgreSQL Database 8.4 PostgreSQL is an advanced object-relational database management
system
Management Cartridges
25
26
T he git clone command copies the template application files from the remote repository into the
working directory. Edit the template application files to develop your own application.
6.3.2. Command Line Interface
T he rhc app create command from the OpenShift client tools is used to create a new application.
When a new application is created, a new, remote git repository is created and automatically cloned to
your current directory on your local machine. Further, the hostname and IP address of your application is
added to the list of known hosts (~/.ssh/known_hosts).
Refer to rhc app create --help for a complete list of options.
Prerequisites
Application creation requires a reliable network connection. T he rhc app create command only
makes a single attempt to create your application. OpenShift makes up to seven checks for the DNS
entry to exist, and returns a failure message if not found.
If you continue to experience timeout issues, you may need to use the --tim eout option on the
command line to override the default values. OpenShift uses two timeout parameters: a connection
timeout, which determines how long the client tries to connect to the server before timing out; and a read
timeout, which determines how long the client waits for a response from the server. T he default
connection timeout value is 20 seconds. T he default read timeout value is 120 seconds.
T he --tim eout option affects both timeout parameters, but it can only be used to increase values from
the default. You cannot set the timeout value to be less than the default. For example, if you use -tim eout 50, it sets the connection timeout value to 50 seconds, but does not affect the read timeout
value. If you use --tim eout 150, it sets both the connection and read timeout values to 150 seconds.
6.3.2.1. Creating Non-scaled Applications
Use the rhc app create command without any options to create a non-scaled OpenShift application
with the specified name, and in your domain namespace.
27
T he following example demonstrates creating a PHP application called "racer" in the autom obile
domain that was created in Example 5.1, Creating a new domain:
$ rhc app create racer php-5.3
Password: *******
Creating application 'racer'
============================
Gear Size:
Namespace:
Cartridge:
Scaling:
default
automobile
php-5.3
no
Your application's domain name is being propagated worldwide (this might take a
minute)...
Initialized empty Git repository in /root/apps/racer/.git/
done
racer @ http://racer-automobile.example.com/
===========================================
Application Info
================
Git URL
= ssh://[email protected]/~/git/racer.git/
Created
= Dec 19 8:53 PM
SSH URL
= ssh://[email protected]
UUID
= 732b4727894f4afc3sep73796db80ac3
Gear Size = small
Cartridges
==========
php-5.3
RESULT:
Application racer was created.
As mentioned in Section 5.2.1, Creating a Namespace, each domain can support multiple applications.
By running rhc app create hybrid php-5.3, for example, you could create another application in
the autom obile namespace. T he application URLs would appear as follows:
http://racer-automobile.example.com
http://hybrid-automobile.example.com
6.3.2.2. Creating Scaled Applications
Scaled applications automatically allocate resources based on demand. Use the rhc app create
command with the -s (or --scaling) option to create a scaled application, as shown in the example
below. Refer to Section 6.1.1, Scaled Applications for more information.
28
yes
default
php-5.3
automobile
Your application's domain name is being propagated worldwide (this might take a
minute)...
Initialized empty Git repository in /apps/hybrid/.git/
done
hybrid @ http://hybrid-automobile.example.com/
==================================================
Application Info
================
SSH URL
= ssh://[email protected]
UUID
= fjoe04cabdc4efa8f2513a21e2ed27d
Git URL
= ssh://[email protected]/~/git/hybrid.git/
Created
= 12:53 AM
Gear Size = small
Cartridges
==========
php-5.3
haproxy-1.4
Scaling Info
============
Scaled x2 (minimum: 2, maximum: available gears) with haproxy-1.4 on small
gears
RESULT:
Application hybrid was created.
When you create a scaled application, the automatic scaling feature is enabled by default. However, you
can manually scale your application by disabling the automatic scaling feature.
6.3.2.2.1. Disabling Automatic Scaling
T here may be cases where you may want to scale your application manually. Such cases may include:
If you are anticipating a certain load on your application and wish to scale it accordingly.
You have a fixed set of resources for your application.
You want to manually control the cost.
You can disable the automatic scaling feature to manually control your application's scaling function. T he
instructions below describe how to disable the automatic scaling feature. It is assumed you have already
created your scaled application.
Procedure 6.4 . T o disable the automatic scaling feature:
1. From your locally cloned Git repository, create a disable autoscaling marker, as shown in the
example below.
29
$ touch <AppName>/.openshift/markers/disable_auto_scaling
For example, to create a disable autoscaling marker for an application named myapp, run the
command as follows:
$ touch myapp/.openshift/markers/disable_auto_scaling
b. Use the git add command to add your changes to your local Git repository.
$ git add .openshift/markers/disable_auto_scaling
c. Use the git com m it command to commit your changes to your local Git repository.
$ git commit -m "disable auto-scaling"
3. Push your changes to your application's remote repository using the git push command.
$ git push
Now that you have disabled the automatic scaling feature of your application, the next section describes
how you can manually scale your application.
6.3.2.2.2. Scaling an Application Manually
After disabling the automatic scaling feature of your application, you can manually control the scaling
function of your application. T he instructions below describe how you can manually scale your
application up or down.
Procedure 6.5. T o manually scale an application:
1. Create an SSH connection to your scaled application, as shown in the example below.
$ ssh <AppUUID>@<AppName>-<DomainName>.example.com
2. Use the add-gear or rem ove-gear command to manually scale your application up or down.
a. Run the following command to scale up an application:
[app-domain.example.com ~]\> add-gear -a <AppName> -u <AppUUID> -n
<DomainName>
30
T his creates an application that is not publicly available nor does it have anything running. You need to
use git push and the .openshift/action_hooks/ scripts to perform all required operations.
6.3.2.4 . Using Arbitrary DNS Names
You can specify meaningful DNS names for your OpenShift applications so that you can use your own
DNS entries instead of using the domain generated for you by the system.
For example, for the two applications in the previous section, you could create aliases that better suited
your own domain and application purposes. You can use the rhc alias add <application>
<alias> command to create these aliases, as follows:
$ rhc alias add racer fast.cars.com
31
You can view the cartridges associated with your applications by running the rhc apps command. T o
view an individual application's information, use rhc app show AppName. Installed cartridges are listed
under the Cartridge heading.
6.4 .2.1. Adding Cartridges
T he current list of available cartridges can be viewed by running the rhc cartridge list command.
Note that certain cartridges can only be added after a prerequisite cartridge is added. Cartridge
descriptions in the OpenShift website Management Console detail these dependencies.
Note
You can add only MySQL 5.1, MongoDB, PostgreSQL, or Jenkins Client 1.4 cartridges to scaled
applications.
Procedure 6.7. T o add a cartridge using the CLI:
Run the following command, replacing AppName and CartType with the name of the application to
which you want to add a cartridge and the type of cartridge you want to add:
$ rhc cartridge add CartType -a AppName
Details
list
add
Adds a cartridge.
remove
Removes a cartridge.
stop
Stops a cartridge.
start
Starts a cartridge.
restart
Restarts a cartridge.
status
reload
show
storage
scale
32
to application 'racer'
=
=
=
=
racer
mysql://127.5.32.1:3306/
XdyRc3q9YbMF
admin
You can use SSH to connect to your application and verify the integrity of your database. Use the
following command to connect to your application:
$ ssh [email protected]
Use the password provided as output to the rhc cartridge add command to connect to the
database:
PGPASSWORD=password psql -h 127.0.251.129 -U admin -d appname
psql (8.4.9)
Type "help" for help.
appname=#
T he last line in the output indicates a successful connection to the database. As a further check, you
can run a simple query:
appname=# select 1 as a, 2 as b, 3 as c;
a | b | c
---+---+--1 | 2 | 3
(1 row)
33
Use the rhc cartridge add command to add a MongoDB database instance to your application
and to add RockMongo to control that database instance. T he following procedure demonstrates how
to create a new application and how to use MongoDB and RockMongo with that application.
Procedure 6.8. How to use MongoDB and RockMongo with OpenShift applications
1. Create a new application.
$ rhc app create myMongo php-5.3
T ake note of the credentials and other information that this command provides.
3. Add the RockMongo cartridge to your application.
$ rhc cartridge add rockmongo-1.1 -a myMongo
T ake note of the credentials and other information that this command provides.
6.5.3.3. Managing MongoDB Instances with a Browser
After you have added a MongoDB database and the RockMongo cartridge to your application, you can
navigate to and start exploring your database. Use the URL and RockMongo User and RockMongo
Password credentials provided as output from the last step in the Procedure 6.8, How to use MongoDB
and RockMongo with OpenShift applications procedure. In this example, the URL is https://myMongomyDomain.example.com/rockmongo/. Below is an example of the RockMongo web interface.
Refer to RockMongo documentation for further information on how to use this interface to manage your
database.
6.5.3.4 . Managing MongoDB Instances in a Shell Environment
After you have added a MongoDB database and the RockMongo cartridge to your application as
described in Procedure 6.8, How to use MongoDB and RockMongo with OpenShift applications, you
can manage your MongoDB instance in a shell environment.
34
Important
Shell access is quite powerful and it is possible to damage an application accidentally. T herefore
it is recommended you only use shell access when necessary.
Use the rhc apps command to display information about all of your available applications. T ake note of
the UUID and public URL information that this command provides for your MongoDB instance.
T he example below shows viewing information for the myMongo application:
Example 6.1. Viewing Application Information
$ rhc apps
Password: **********
myMongo @ http://myMongo-myDomain.example.com/ (uuid:
f74d7e4fffeb4w1c5abe5agr19e3d7f2)
-------------------------------------------------------------------------------------Created: 1:09 AM
Gears:
1 (defaults to small)
Git URL: ssh://[email protected]/~/git/myMongo.git/
SSH:
[email protected]
php-5.3 (PHP 5.3)
----------------Gears: Located with mongodb-2.2, rockmongo-1.1
mongodb-2.2 (MongoDB NoSQL Database 2.2)
---------------------------------------Gears:
Located with php-5.3, rockmongo-1.1
Connection URL: mongodb://127.2.27.120:27327/
Database Name: myMongo
Password:
z57C6HdU5JnL
Username:
admin
rockmongo-1.1 (RockMongo 1.1)
----------------------------Gears:
Located with php-5.3, mongodb-2.2
Connection URL: https://myMongo-myDomain.example.com/rockmongo/
You will also need the Root username and the Root password for your MongoDB instance that was
provided as output from Step 2 in Procedure 6.8, How to use MongoDB and RockMongo with OpenShift
applications.
When you have the necessary information, use the ssh command to open a shell environment for your
MongoDB instance, substituting the UUID and public URL parameters noted previously, as
demonstrated below:
$ ssh [email protected]
When you have accessed your OpenShift application in the shell environment, you can type help at the
shell prompt to get a list of the specialized shell commands.
35
T he example below demonstrates an open Mongo shell, and use of the show users Mongo shell
command:
Example 6.2. Running Mongo Shell Commands
MongoDB shell version: 2.2.0
connecting to: 127.0.250.129:27017/admin
Welcome to the MongoDB shell.
> show users
{
"_id" : ObjectId("4ee55d39078e94193206e157"),
"user" : "admin",
"readOnly" : false,
"pwd" : "aba43436961fbc6145261a12ed94b8f7"
}
Refer to the MongoDB website and documentation for more information on Mongo shell commands.
2. Use the following command to commit your application to your local repository:
$ git commit -m "commit message"
36
changes.
Procedure 6.10. T o deploy your application to the cloud using the command line:
Use the following command to deploy your application to the remote repository:
$ git push
Hot Deploy
Yes
Yes
Yes
Yes
PHP
Yes
Perl
Yes
Ruby
Yes
Python
Yes
Node.js
Yes
Z end Server
Yes
Jenkins
No
HAProxy
No
DIY
No
37
For Jenkins enabled applications, the build is performed on a Jenkins slave instance and then synced to
the gear(s) where the application server is running.
Ruby
When you hot deploy a Ruby application, the Passenger restart.txt file is touched, causing the
application server to serve the new code without the need for a full server restart. For further details on
this process, view the Passenger Documentation.
6.6.3.2. Enabling and Disabling Hot Deployment
Procedure 6.11. T o enable hot deployment:
Open a terminal and run the command applicable to your operating system from your application's
root directory to create the hot_deploy marker file:
Windows
C:\app_directory> copy NUL > .openshift\markers\hot_deploy
38
C:\app_directory>
C:\app_directory>
C:\app_directory>
C:\app_directory>
app_directory]$
app_directory]$
app_directory]$
app_directory]$
touch .openshift/markers/java7
git add .openshift/markers/java7
git commit -a -m "Add Java 7 marker"
git push
39
Important
If you are building locally, add any output .war and .ear files in the deploym ents/ directory
from the build to your .gitignore file.
Option 2: Uploading prebuilt content
You can use git push to push prebuilt .war files (with the corresponding .dodeploy file for
exploded .war files) into the deploym ents/ directory.
Important
If you use this method using the default repository, first run git rm -r src/ pom .xm l from
the root directory of your repository. If the pom .xm l file still exists, the build will run again and
replace any prebuilt content.
Description
.dodeploy
Placed by the user to indicate that the given content should be deployed into the
runtime (or redeployed if already deployed in the runtime.)
.deploying
.deployed
Placed by the deployment scanner service to indicate that the given content has
been deployed to the runtime. If you delete this file, the content will be withdrawn.
.faileddeploy
Placed by the deployment scanner service to indicate that the given content failed to
deploy to the runtime. T he content of this file will include some information about the
cause of the failure.
.undeploying
.undeployed
Placed by the deployment scanner service to indicate that the given content has
been withdrawn from the runtime. If you delete this file, it has no impact.
40
T o add new, unzipped content and deploy it, run the following commands:
$ cp -r target/example.war/ deployments/
$ touch deployments/example.war.dodeploy
T o replace currently deployed, zipped content with a new version and deploy it, run the
following command:
$ cp target/example.war deployments/
T o replace currently deployed, unzipped content with a new version and deploy it, run the
following commands:
$ git rm -rf deployments/example.war/
$ cp -r target/example.war/ deployments/
$ touch deployments/example.war.dodeploy
Note
T he following procedures assume that you already have a valid user account for OpenShift.
41
on the first gear, then Jenkins will be added to a separate gear. A third gear will be used for the Jenkins
builder. In other words, whenever the Jenkins builder is active, it occupies one of your available gears.
6.7.3. Creating Jenkins-enabled Applications
You can enable Jenkins with new applications, either scaled or non-scaled. Use the rhc app create
command to create a scaled or non-scaled application with an associated Jenkins application, and to
add the Jenkins client to your application.
6.7.3.1. Creating a Scaled Jenkins-enabled Application
Use the rhc app create command with the -s (or --scaling) option to create a scaled application,
and the --enable-jenkins option to add the Jenkins client to your application, as shown below:
$ rhc app create App01 php-5.3 --enable-jenkins -s
Important
T ake note of the login credentials that this command outputs to the screen. You will need these
credentials to log in to the Jenkins home page.
Note
As part of the process of adding the Jenkins application to your domain, the Jenkins repository is
downloaded to your local machine. T his repository is not required for normal operations, and it is
safe to delete this local copy.
42
T he actual build and deployment process that Jenkins executes involves numerous steps, as described
below.
1. T he user issues a git push command, and Jenkins is notified that a new push is ready.
2. A dedicated Jenkins slave (a builder) is created. You can use the rhc apps command to display
this slave information. T he application name is the same as the originating application, but with a
"bldr" suffix.
Important
T he first 28 characters of the application name must be unique or builders will be shared
across applications. T his can lead to build issues.
3. Jenkins runs the build.
4. Content from the originating application is downloaded to the builder application using git (for
source code) and rsync (for existing libraries).
5. ci_build.sh is called from the Jenkins shell. T his sets up the builder application for the Jenkins
environment and performs some built-in bundling steps (PHP pear processing, Python virtual
environment, etc).
6. .openshift/action_hooks/build is executed on the Jenkins builder.
7. Any additional desired steps are executed from the Jenkins shell (Maven build, Gem install, test
cases, etc).
8. Jenkins stops the currently running application, and runs rsync to synchronize all new content
over to the originating application.
9. .openshift/action_hooks/deploy is executed on the originating application.
10. Jenkins starts the originating application, and .openshift/action_hooks/post_deploy is
executed on this application.
11. Jenkins archives all build artifacts for later reference.
12. After 15 minutes of idle time, the "build app" will be destroyed and will no longer appear in the
output of the rhc apps command. T he build artifacts however, will still exist in Jenkins and can
be viewed there.
You can monitor the build job using the Jenkins interface. T he interface provides an extensive range of
information about the current build, build history, artifacts, as well as plug-ins to graph, track, run tests
and perform other operations. T he following is an example build history of an application built using the
embedded Jenkins Client.
43
Logging for Jenkins-level errors (for example, DNS timeouts, builder configuration, etc.) is available in the
Jenkins logs from the command line using the rhc tail command. Replace jenkins with your Jenkins
application name in the following, if different:
$ rhc tail jenkins
Logging for application-level errors (for example, compilation failures, test failures, etc.) is available via
the Jenkins web interface under the corresponding build history, while logging for deployment-level
errors is available in the application's logs from the command line:
$ rhc tail App01
44
T he status of the build process can be viewed in the web interface under the section labeled Build
Executor Status.
Warning
Application removal is irreversible. All remote data associated with the application will be removed.
Procedure 6.15. T o delete an application:
45
1. Access the Management Console and click My Applications in the navigation bar at the top of
the page.
2. Click on the application you want to delete.
3. Click Delete this application.
4. You are asked to confirm the request. Click Delete to confirm.
T his process deletes your remote application data. If you want to delete application data stored on your
local machine, you must do so manually.
6.8.2. Command Line Interface
Warning
Application removal is irreversible. All remote data associated with the application will be removed.
Procedure 6.16. T o delete an application:
1. Run the following command to delete all the remote data for your application:
$ rhc app delete AppName
Warning
T he following procedure deletes the selected directory and all the files it contains. Ensure you
enter the correct directory and that you no longer need the files it contains before running this
command.
Procedure 6.17. T o delete local application data
Open a terminal and use the following command to delete the application data stored on your local
machine:
$ rm -rf ~/path/to/app_directory/
46
Important
OpenShift does not automatically back up or rotate log files. T he Disk Space Cleanup T ool
runs the rm -rf command to clear the contents of these directories. If you want to save their
contents, you should use the rhc snapshot save command first to create a snapshot of
your system.
Clears unused application libraries. T his means that any library files previously installed by a
git push command are removed.
T he Disk Space Cleanup T ool uses the following syntax:
$ rhc app tidy <ApplicationName>
Note
T he rhc client tools use the login specified in the ~/.openshift/express.conf file by default.
If no default login is configured, or if you want to use a different login, include the -l parameter as
a command line argument.
47
T he following table describes the application management command options that you can use to
manage an existing application in the cloud.
T able 7.1. Application management command argument options
Option
Details
start
Start an application.
stop
Stop an application.
force-stop
restart
Restart an application.
reload
Reload an application.
status
show
tidy
Clean out the application's logs and tmp directories and tidy up the git repo
on the server.
create
git-clone
delete
Remove an application.
Important
Shell access is quite powerful and it is possible to accidentally damage an application. T herefore
it is recommended you only use shell access when necessary.
48
T ake note of the UUID and public URL information for the application you wish to manage in the shell
environment. Use the ssh command to open a shell environment for your application, substituting the
UUID and public URL parameters noted previously.
T he example below demonstrates opening a shell environment to the "racer" application:
Example 7.2. Opening a Shell Environment for an Application Node
$ ssh [email protected]
Warning: Permanently added 'racer-automobile.example.com,174.129.151.26' (RSA)
to the list of known hosts.
Welcome to OpenShift shell
This shell will assist you in managing OpenShift applications.
!!! IMPORTANT !!! IMPORTANT !!! IMPORTANT !!!
Shell access is quite powerful and it is possible for you to
accidentally damage your application. Proceed with care!
If worse comes to worst, destroy your application with 'rhc app delete'
and recreate it.
!!! IMPORTANT !!! IMPORTANT !!! IMPORTANT !!!
Type "help" for more info.
[racer-automobile.example.com ~]\>
49
Note
T he shell environment to access your OpenShift applications is protected and restricted with
Security-Enhanced Linux (SELinux) policies.
When you have accessed your OpenShift application in the shell environment, you can type help at the
shell prompt to get a list of the specialized shell commands. As mentioned previously, you can also use
general Linux commands to perform routine operations in the shell environment.
7.2.2. Windows
Managing OpenShift applications in a Secure Shell (SSH) environment on Windows requires the PuT T Y
SSH and T elnet client, and PuT T Ygen SSH key generator. T his section provides instructions on how
you can use PuT T Y to establish an SSH connection to your OpenShift applications. T he instructions are
provided in four easy steps, as outlined below:
Step 1: Download PuT T Y and PuT T Ygen for Windows
Step 2: Convert OpenSSH keys to PuT T Y format
Step 3: Locate application username and hostname
Step 4: Establish SSH connection using PuT T Y
Important
Secure Shell (SSH) access is quite powerful, and it is possible to accidentally damage an
application. T herefore, it is recommended you only use SSH access when necessary.
Note
T he screenshots shown in the instructions below were taken on Windows XP. Where necessary,
the differences among other Windows operating systems have been noted.
It is assumed that the application you want to establish an SSH connection to has already been created.
In the examples used in this section, an SSH connection will be established to the application named
testapp.
Step 1: Download PuT T Y and PuT T Ygen
Go to http://www.chiark.greenend.org.uk. Download the executable files of the latest version of PuT T Y
and PuT T Ygen to your desired directory. Alternatively, you can also download the PuT T Y installer file
that will install all required PuT T Y packages on your computer.
Step 2: Convert OpenSSH Keys to PuT T Y Format
By default, the pair of SSH keys generated when installing client tools on Windows are in OpenSSH
format. T he pair consists of a private key, named id_rsa, and a public key, named id_rsa.pub. T o
establish an SSH connection to your application using PuT T Y, the private SSH key must be converted to
PuT T Y format. T he pair of SSH keys generated during initial configuration of OpenShift client tools are
stored in the following folders:
c:\Docum ents and Settings\user\.ssh for Windows XP
50
3. Navigate to the \user\.ssh folder, and select the id_rsa key file to import, as shown in the
figure below.
51
4. Your private SSH key should now be imported to PuT T Ygen, as shown in the figure below. Click
Save private key, and save the id_rsa.ppk file in the \user\.ssh folder where the original
keys are stored.
5. Navigate to the \user\.ssh folder and verify that you now have three SSH key files. T he
id_rsa.ppk key will be used to establish an SSH connection to your OpenShift application. You
can close PuT T Ygen.
Step 3: Locate Application Username and Hostname
Each application created on OpenShift gets a unique UUID and gear name that is used to clone the
remote Git repository to your local repository. You can use the rhc apps command or the OpenShift
Management Console to get this information for the application to which you wish to establish an SSH
connection. Both examples are shown below.
Use the rhc apps command and note the UUID and gear name listed in the SSH field.
52
$ rhc apps
Password: *******
testapp @ http://testapp-doctesting.rhcloud.com/ (uuid:
aa8d89ed311741e7b84d4edb82b11e0d)
-----------------------------------------------------------------------------------Created: Dec 19 10:20 PM
Gears:
1 (defaults to small)
Git URL: ssh://[email protected]/~/git/testapp.git/
SSH:
[email protected]
php-5.3 (PHP 5.3)
----------------Gears: 1 small
Alternatively, you can use the OpenShift Management Console to get the required information for your
application. From the OpenShift Management Console, click on the My Applications tab, then click the
name of the application you wish to access. T he SSH parameters can be found by clicking and
expanding WANT T O LOG IN T O YOUR APPLICAT ION? on this page; note the UUID and gear name
used.
In the next step you will use the UUID as the username and the gear name as the hostname to configure
PuT T Y, and establish an SSH connection to your application. T o avoid errors, it is recommended you cut
and paste this information into PuT T Y.
Step 4 : Establish SSH Connection Using PuT T Y
Now that you have the necessary information, you are ready to configure PuT T Y to establish an SSH
connection to your application. Follow the instructions below to configure PuT T Y using the information
from the previous step.
1. Double-click putty.exe to launch the PuT T Y SSH and T elnet client. If necessary, click Run in the
Security Warning window. If you installed the PuT T Y software with the installer file, click Start,
point to All Programs, point to PuT T Y, and then click PuT T Y.
2. In the left window pane under Category, click Session. Now copy and paste the gear name of
your application in the Host Name text box, as highlighted in the figure below.
53
3. In the expanded list of options under Connection, click Data. Now copy and paste the UUID of
your application in the Auto-login username text box, as highlighted in the figure below. Because
the UUID is quite long, it may not be fully visible.
4. In the expanded list of options under Connection|SSH, click Auth. T hen click Browse to locate
the id_rsa.ppk file you created earlier, as shown in the figure below.
54
When you have browsed to the id_rsa.ppk file, click Open, as shown in the figure below.
5. With your id_rsa.ppk key selected, click Open, as shown in the figure below. T his will open an
SSH connection to your application gear.
55
If a security warning is displayed, click Yes to accept it. An SSH terminal window will open, similar
to the example shown below.
Using username "aa8d89ed311741e7b84d4edb82b11e0d".
Authenticating with public key "imported-openssh-key"
Welcome to OpenShift shell
This shell will assist you in managing OpenShift applications.
!!! IMPORTANT !!! IMPORTANT !!! IMPORTANT !!!
Shell access is quite powerful and it is possible for you to
accidentally damage your application. Proceed with care!
If worse comes to worst, delete your application with 'rhc app delete'
and recreate it
!!! IMPORTANT !!! IMPORTANT !!! IMPORTANT !!!
Type "help" for more info.
[testapp-doctesting.example.com ~]\>
One of the useful features of secure shell access is the ability to view application logs. You can
find the application log files in the App_Name/logs directory. T he example below shows how to
view the log file for the application named testapp.
[testapp-doctesting.example.com ~]\> cd testapp/logs
[testapp-doctesting.example.com ~]\> ls
[testapp-doctesting.example.com ~]\> view error_log-20120618-000000-EST
56
Note
T he Secure Shell environment to access your OpenShift applications is protected and
restricted with Security-Enhanced Linux (SELinux) policies.
With an SSH connection established to your OpenShift application, you can type help at the shell
prompt to get a list of specialized shell commands. You can also use general Linux commands to
perform routine operations in the shell environment.
Example
Purpose
OPENSHIFT _APP_DNS
appnamenamespace.example.com
T he application's fully-qualified
domain name
OPENSHIFT _APP_NAME
appname
T he application's name
OPENSHIFT _APP_UUID
0123456789abcdef0123456789
abcdef
127.0.250.1
8080
57
Example
Purpose
app-root/data/
OPENSHIFT _<cartridge>_LOG_
DIR
<cartridge>/logs/
OPENSHIFT _<database>_DB_
LOG_DIR
<database>/logs/
OPENSHIFT _REPO_DIR
app-root/runtime/repo/
OPENSHIFT _T MP_DIR
/tmp/
Example
Purpose
OPENSHIFT _<database>_DB_
HOST
127.0.250.1
T he hostname or IP address
used to connect to the database
OPENSHIFT _<database>_DB_
PORT
3306
OPENSHIFT _<database>_DB_
USERNAME
admin
T he database administrative
username
OPENSHIFT _<database>_DB_
PASSWORD
8ddT nst22X3Y
T he database administrative
user's password
OPENSHIFT _<database>_DB_
SOCKET
$OPENSHIFT _HOMEDIR/mysql5.1/socket/mysql.sock
OPENSHIFT _<database>_DB_
URL
mysql://admin:8ddT nst22X3Y@1
27.0.250.1:3306/
58
Example
Purpose
JENKINS_USERNAME
system_builder
JENKINS_PASSWORD
RnmXQlavsb4f
JENKINS_URL
https://jenkinsnamespace.example.com/
Example
Purpose
OPENSHIFT _GEAR_DNS
gearnamenamespace.example.com
OPENSHIFT _GEAR_NAME
gearname
T he gear's name
OPENSHIFT _GEAR_UUID
0123456789abcdef0123456789
abcdef
T he gear's UUID
You can save environment variables on the server, which means that you do not have to pass sensitive
information repeatedly to the command line.
Procedure 7.1. How to set environment variables on the server
1. Open the <appnam e>/.openshift/config/standalone.xm l file.
2. Specify the required values for any of your environment variables, then save and close the file.
3. Commit and push the changes to the server:
$ git commit -a -m "COMMIT MESSAGE"
$ git push
59
Important
Sensitive information stored in your environment variables is visible if you use the rhc
snapshot commands.
7.4. Node.js
T his section provides the basic information required for running Node.js applications on OpenShift.
7.4 .1. Repository Layout
When you create a new Node.js application on OpenShift, the application directory is populated with
several files. T he following table displays this layout:
T able 7.7. Node.js Repository Layout
File
Use
node_modules/
deplist.txt
npm_global_module_list
server.js
package.json
README
.openshift/
.openshift/action_hooks/pre_bui
ld
Script that gets run every git push before the build
.openshift/action_hooks/build
Script that gets run every git push as part of the build process (on
the CI system if available)
.openshift/action_hooks/deploy
Script that gets run every git push after build but before the
application is restarted
.openshift/action_hooks/post_d
eploy
Script that gets run every git push after the application is restarted
You can create additional directories if needed, but do not delete the node_m odules and .openshift
directories.
Note
When you git push, everything in your remote repository directory is recreated. Place items that
you want to persist between pushes, such as a database, in the ../data directory on the gear
where your OpenShift application is running.
60
the OpenShift environment when you git push your application. For more information, see
https://npmjs.org/doc/json.html.
Example package.json entry:
"dependencies": {
"coffee-script":
"connect":
"1.3.3",
"*",
"optimist": "<=0.3.4",
"socket.io": ""
},
Node modules not included in the npm registry can be installed by packaging them in the
node_m odules directory.
T he npm _global_m odule_list file contains a list of globally installed modules. You can override a
globally available module by specifying it in package.json or by packaging it in the node_m odules
directory. Node gives preference to the "locally" installed version of that module.
61
T his example appends a new line of date information to the $OPENSHIFT _REPO_DIR/php/date.txt
file every minute.
You can use curl to verify the operation of this script:
$ curl http://holy-roller.example.com/date.txt
Thu Feb
Thu Feb
Thu Feb
T he scripts that you place in the /cron subdirectories are executed at the respective frequencies.
Scripts in each subdirectory are executed sequentially, in alphabetical order. Scripts in the
/cron/hourly directory are executed on the first minute of every hour. You can use the rhc
cartridge command to enable or disable your cron scripts. For example, to disable all of your scripts:
$ rhc cartridge stop cron-1.4 -a holy
Note
T he cron commands affect all cron jobs. You cannot disable or enable individual cron jobs.
62
Important
Be aware that access to email servers from cloud providers may be blocked by Realtime
Blackhole Lists (RBLs). T his may affect your ability to connect to some email servers. If you are
unable to make a connection to one of these services, make sure that your email provider allows
authenticated connections from Amazon AWS EC2 hosts.
63
Refer to the Client Tools Installation Guide for more information about the OpenShift client tools
interactive setup wizard.
64
Procedure 8.1. T o generate new SSH keys with the ssh-keygen command:
1. Manually generate a new pair of keys, replacing KeyType with the type of key you want to
generate, either dsa or rsa:
$ ssh-keygen -t KeyType
2. By default the new SSH keys are located in the /hom e/username/.ssh/ directory.
8.2.1.2. Adding a Key
Procedure 8.2. T o add a key:
1. Access the Management Console and click My Account in the navigation bar at the top of the
page.
2. In the Public Keys section, click Add a new key.
3. Enter a name for your key then paste the public key in the space provided.
4. Click Create to add your public key.
Important
If you copy and paste your SSH key from an editor or terminal with the word wrap function
enabled, the key may include unnecessary line breaks. T his causes the OpenShift web console
to reject the SSH key and the upload process to fail. When you paste your key into the web
console, confirm that the key contents are correct and do not contain any unnecessary line
breaks.
where KeyType is the type of key you want to generate, either DSA or RSA.
2. Add the new public key to the user account:
65
where <KeyPath> is the path and filename of the public key that you want to add, and <KeyName>
is a name that you specify to identify this key.
3. Add the new public key to the SSH agent:
$ ssh-add <KeyPath>
where <KeyName> is the user-specified identifier for the SSH key, and <KeyPath> is the path to an
existing key (optional). If an existing key is not specified, a new key is generated and uploaded to the
server.
Run rhc sshkey add --help for more information.
8.2.2.4 . Removing a Key
Use the rhc sshkey rem ove command to remove an existing public key from the OpenShift server for
the specified user account:
$ rhc sshkey remove <KeyName> -l <UserName>
66
3. T he OpenShift Management Console displays the number of gears, along with the size of the
gears, used by the selected application, as highlighted in the figure below.
4. Hover over the gear size information with your mouse to display a popup message with more
67
detailed information.
5. Scaling is performed by the HAProxy cartridge. Click Scales with HAProxy to get information
about testing the scaling function of your application.
Note
At the time of this writing, the scaling function cannot be disabled from an application. T he
only way to disable scaling is to remove the scaled application, and create a new
application without the scaling option.
68
provided by MMS. T his procedure assumes that you have successfully created an application and
added the MongoDB cartridge.
Procedure 9.2. How to set up your application to use MMS
1. Download the agent.
When you log into MMS, you will see a "download the agent" link on the Hosts page. Click this link
to download an agent preconfigured with your group credentials.
2. Create a directory named m m s in your application's .openshift directory with the following
command, replacing app_directory with the root directory for your application:
$ mkdir ~/app_directory/.openshift/mms
Important
T he settings.py file contains the MMS agent settings that contain the API keys for
connecting to your MMS account and updating the monitoring metrics. T he MMS agent will
not function without this file.
4. Use git to add and commit the m m s directory to your local repository, then push it to your remote
repository:
$
$
$
$
cd app_directory/
git add .openshift/mms/
git commit -m "mms settings" -a
git push
After you have successfully completed this procedure, you can navigate to the https://mms.10gen.com/
page, enter your host's details and start monitoring your application.
9.2.2. Monitoring an Applications with MMS
9.2.2.1. Adding Hosts to MMS
After you have created an application and added the MMS agent, you can add the host to the Hosts
page on https://mms.10gen.com/. T o add a new host, you need the hostname, port number, and login
credentials that were provided when you added MongoDB to your application. If you no longer have this
information, you can retrieve it directly from your application, as follows:
1. Use SSH to connect to your application:
$ ssh [email protected]
where UUID is the UUID of your application. You can retrieve this using the rhc apps command.
Replace appname and namespace with your application name and namespace, respectively.
69
2. Run the following command to retrieve all the necessary connection and credential information for
your application:
> echo $OPENSHIFT_MONGODB_DB_URL
70
Note
T his example assumes that you have a valid account and have already created a domain and
JBoss application called "myJBoss".
You can now use the rhc tail command to inspect the resultant thread dump:
71
Note
Ensure that your application is running before attempting to configure port forwarding.
Refer to the following example:
72
In this example, you could now open a browser and connect to your remote application as if it were
running locally.
T he current implementation of the rhc port-forward command forwards all open ports on your
running application to your local workstation. If you have multiple cartridges added to your application,
you will see further messages indicating which remote services are being bound to local ports. Refer to
the following example:
$ rhc port-forward myJBoss
Password: **********
Checking available ports...
Forwarding ports
Service Connect to
Forward to
====== ================ ==== ================
java
127.4.188.1:3528 => 127.4.188.1:3528
java
127.4.188.1:4447 => 127.4.188.1:4447
java
127.4.188.1:5445 => 127.4.188.1:5445
java
127.4.188.1:5455 => 127.4.188.1:5455
java
127.4.188.1:8080 => 127.4.188.1:8080
java
127.4.188.1:9990 => 127.4.188.1:9990
java
127.4.188.1:9999 => 127.4.188.1:9999
mysqld 127.4.188.1:3306 => 127.4.188.1:3306
Press CTRL-C to terminate port forwarding
If you need to forward only specific ports, you need to use the ssh command with the -L option. Refer to
the ssh manual page for details.
9.4 .1.1. Port Forwarding on Mac OS X
Currently, out of the box, Mac OS X only provides the following interfaces for loopback addresses:
localhost
127.0.0.1
T herefore, you may experience error messages similar to those shown below when attempting to
configure port forwarding using the IP address for your OpenShift application.
$ rhc port-forward app01
Password: **********
Checking available ports...
Error trying to forward ports. You can try to forward manually by running:
ssh -N [email protected]
T he current workaround to enable port forwarding on Mac OS X is to configure an alias manually using
the ifconfig command for each IP address used by your application, using the command as shown
73
below:
$ sudo ifconfig lo0 alias application_IP_address
For example, if the IP address used by your application is 127.10.51.129, run the command as shown
below:
$ sudo ifconfig lo0 alias 127.10.51.129
If your application uses multiple IP addresses, as shown in the example above, you must configure an
alias for each IP address. For example, suppose you have a Node.js application with both MySQL and
phpMyAdmin cartridges added, and it uses the IP addresses 127.11.25.1 and 127.11.25.2. T o correctly
enable port forwarding, you must configure an alias for each IP address, as shown in the example below.
$ sudo ifconfig lo0 alias 127.11.25.1
$ sudo ifconfig lo0 alias 127.11.25.2
Note
T he ifconfig command on Mac OS X requires root/administrative privileges to execute.
You can now use the rhc port-forward command to enable port forwarding.
Important
T he IP address alias you configure for your OpenShift application is not persistent through
system reboots. If you reboot your computer, you must repeat these steps to correctly enable port
forwarding on Mac OS X.
74
Revision History
Important
OpenShift does not maintain backups of your applications or user data on the OpenShift servers.
T he files created by this process are always downloaded to your local machine.
T he command will prompt for any missing information, such as your rhlogin and password. T he default
filename for the snapshot is $Application_Name.tar.gz. You can override this path and filename with
the --filepath option.
T he following example demonstrates the process of creating and downloading a snapshot:
$ rhc snapshot save MasterApp
Password: **********
Pulling down a snapshot to MasterApp.tar.gz...
Waiting for stop to finish
Done
Creating and sending tar.gz
Done
RESULT:
Success
75
Important
Even though you can save your application using a different filename, you cannot restore that
application to a different name. T hat is, if your application name is "MyApp", you can save it as
OurApp.tar.gz, but when you restore it you must use the original application name.
T he rhc snapshot restore command overwrites the remote git repository. Any changes that
you might have made since you took the snapshot will be lost.
Warning
Importing snapshot data into a local environment may delete local content, for example a user
table in your database. If you are unsure what effect a snapshot import may have on your local
data, use SSH to access your application and make the backup directly.
T he following example demonstrates the process of restoring a snapshot:
$ rhc snapshot restore MasterApp
Password: **********
Restoring from snapshot MasterApp.tar.gz...
restart_on_add=false
Waiting for stop to finish
Done
Removing old git repo: ~/git/MasterApp.git/
Removing old data dir: ~/app-root/data/*
Restoring ~/git/MasterApp.git and ~/app-root/data
restart_on_add=false
~/git/MasterApp.git ~
~
Running .openshift/action_hooks/pre_build
Running .openshift/action_hooks/build
Running .openshift/action_hooks/deploy
hot_deploy_added=false
Done
Running .openshift/action_hooks/post_deploy
RESULT:
Success
76
Revision History
Revision History
Revision 2.0.25-0
T ue Apr 02 2013
Brian Moss
OpenShift Online 2.0-25 release.
Add T omcat 7 to list of application types.
Add content for deleting an application using the CLI.
Add Jenkins-related logging info.
Fix typos and grammatical errors.
Add SwitchYard 0.6 to the list of supported cartridges.
Remove application version numbers.
Update Applications and Cartridges chapter.
Add Introduction chapter.
Remove Introduction-style content from Preface.
Changed all mentions of Getting Started Guide to Client T ools Installation Guide
Add 'rhc apps' and 'rhc account' usage
Revision 2.0.24 -0.0
T hu Feb 28 2013
OpenShift Online 2.0-24 release.
Restructure table of contents.
Remove author from pdf output.
Brian Moss
Revision 2.0.22-0
Fri Feb 15 2013
OpenShift Online 2.0-22 release.
Refactor rhc commands.
Add T omcat 6 and Z end 5.6 to list of application types.
Update MongoDB 2.0 to MongoDB 2.2.
Update environment variables.
Add import warning to snapshot section.
Update web interface chapter.
Brian Moss
Index
A
Applications
- alias, Using Arbitrary DNS Names
- cloud
- git command, Deploying Your Application to the Cloud
- committing, Preparing Your Application for Deployment
- creating, Command Line Interface
- command, Creating Non-scaled Applications
- multiple, Creating Non-scaled Applications
- network issues, Command Line Interface
- timeout, Command Line Interface
- troubleshooting, Command Line Interface
- Web GUI, Management Console
- customized domain names
- alias, Using Arbitrary DNS Names
77
- deleting
- command line, Application Management Commands
- locally, Deleting Local Application Data
- Web GUI, Management Console
- deploying
- command line, Deploying Applications
- directories, Platform Overview
- security, Platform Overview
- files, Cloning Application Files
- managing
- command line, Application Management Commands
- reloading
- command line, Application Management Commands
- removing
- command line, Application Management Commands
- restarting
- command line, Application Management Commands
- starting
- command line, Application Management Commands
- stopping
- command line, Application Management Commands
- testing, Using DIY Cartridges
- types
- no type, Using DIY Cartridges
- supported, Management Console
- viewing
- command line, Application Management Commands
B
Build System
- Jenkins, Introduction to Jenkins
78
Revision History
F
feedback
- contact information for this manual, We Need Feedback!
H
help
- getting help, Do You Need Help?
J
Jenkins, Introduction to Jenkins
- (see also Build System)
- benefits, Introduction to Jenkins
S
Security
- Environmental variables, JBoss Environment Variables
U
Users
- managing
- access, Managing SSH Keys
- public keys, Managing SSH Keys
79