Monday, April 21, 2014

Managing OpenShift with RHC Command Line

In all the previous articles we have seen how we can create domains , application and cartridges. In all the cases we have used the “rhc” commands for dealing with these Operations. In this article we will see how we can use “rhc” command with available options.

We can get the help for rhc command like,

Getting started:
  setup              Connects to OpenShift and sets up your keys and domain
  create-app         Create an application
  apps               List all your applications
  cartridges         List available cartridges
  add-cartridge      Add a cartridge to your application
  set-env            Set one or more environment variable(s) to your application
  logout             End the current session

Working with apps:
  tail               Tail the logs of an application
  port-forward       Forward remote ports to the workstation
  threaddump         Trigger a thread dump for JBoss and Ruby apps
  snapshot           Save the current state of your application locally
  git-clone          Clone and configure an application's repository locally

Management commands:
  account            Display details about your OpenShift account
  alias              Add or remove a custom domain name for an app
  app                Commands for creating and managing applications
  authorization      Manage your authorization tokens
  cartridge          Manage your application cartridges
  deployment         Commands for deploying and managing deployments of an application
  domain             Add or rename the container for your apps
  env                Manages user-defined environment variables set on a given application
  member             Manage membership on domains and teams
  scp                SCP a file to or from your application
  server             Display information about the status of the OpenShift service
  ssh                SSH into the specified application
  sshkey             Add and remove keys for Git and SSH
  team               Create or delete a team

We will see some of the commands and examples of using them.

----Account Information----
[root@vx111a funtest]# rhc accountt
Login on
  ID:                     537de3924382ec94c9000394
  Plan:                   Free
  Gears Used:         3
  Gears Allowed:     3
  Domains Allowed: 1
  Allowed Gear Sizes: small
  SSL Certificates:   no

OpenShift Information
[root@vx111a funtest]# rhc server
Connected to
All systems running fine

Create Domain
[root@vx111a rubygems-2.2.2]# rhc domain create -n fundomain
You have not yet configured the OpenShift client tools. Please run 'rhc setup'.
Creating domain 'fundomain' ... Login to
Password: ***********
You may now create an application using the 'rhc create-app' command

See What Domains Exist
[root@vx111a rubygems-2.2.2]# rhc domain show
You have not yet configured the OpenShift client tools. Please run 'rhc setup'.
Login to
Password: ***********

Domain fundomain (owned by
  Created:            5:19 PM
  ID:                    537de4445973ca6cf70000b2
  Allowed Gear Sizes: small

The domain fundomain exists but has no applications. You can use 'rhc
create-app' to create a new application.

Rename a Domain
rhc domain rename Old_Domain_Name New_Domain_Name

Delete a Domain
rhc domain destroy -n  <Domain name> -l <username>

For application we have the available actions,

List of Actions
  configure          Configure several properties that apply to an application
  create             Create an application
  delete             Delete an application from the server
  deploy             Deploy a git reference or binary file of an application
  force-stop         Stops all application processes
  reload             Reload the application's configuration
  restart            Restart the application
  scale-down         Scale down the application's web cartridge
  scale-up           Scale up the application's web cartridge
  show               Show information about an application
  start              Start the application
  stop               Stop the application
  tidy               Clean out the application's logs and tmp directories and tidy up the git repo on the server
Create an Application
[root@vx111a funtest]# rhc app create -a dbtest -t jbossas-7
Application Options
Domain:     fundomain
Cartridges: jbossas-7
Gear Size:  default
Scaling:    no

Creating application 'dbtest' ... done

Waiting for your DNS name to be available ... done

Initialized empty Git repository in /soa/openShift/funtest/dbtest/.git/
Warning: Permanently added the RSA host key for IP address '' to the list of known hosts.

Your application 'dbtest' is now available.

  SSH to:
  Git remote: ssh://

Run 'rhc show-app dbtest' for more details about your app.

Application Status
[root@vx111a funtest]# rhc app show Sample-app
Application 'Sample-app' not found.
[root@vx111a funtest]# rhc app show funtest
funtest @ (uuid: 537f2c545973caec750002b8)
  Domain:     fundomain
  Created:    May 23  4:39 PM
  Gears:      1 (defaults to small)
  Git URL:    ssh://
  Deployment: auto (on git push)

  jbossas-7 (JBoss Application Server 7)
    Gears: 1 small

Reload an Application
[root@vx111a funtest]# rhc app reload funtest
funtest config reloaded

Delete a application
[root@vx111a funtest]# rhc app delete funtest
This is a non-reversible action! Your application code and data will be permanently deleted if you continue!

Are you sure you want to delete the application 'funtest'? (yes|no): y

Deleting application 'funtest' ... deleted

Confirm Deletion of an application
[root@vx111a funtest]# rhc app delete jenapp --confirm
Deleting application 'jenapp' ... deleted

Tail application logs
[root@vx111a funtest]# rhc tail -a dbtest
==> app-root/logs/jbossas.log <==
 def new generation   total 14336K, used 7651K [0xbc140000, 0xbd0c0000, 0xc1690000)
  eden space 12800K,  47% used [0xbc140000, 0xbc738fa8, 0xbcdc0000)
  from space 1536K, 100% used [0xbcf40000, 0xbd0c0000, 0xbd0c0000)
  to   space 1536K,   0% used [0xbcdc0000, 0xbcdc0000, 0xbcf40000)
 tenured generation   total 30972K, used 21414K [0xc1690000, 0xc34cf000, 0xcc140000)
   the space 30972K,  69% used [0xc1690000, 0xc2b79b58, 0xc2b79c00, 0xc34cf000)
 compacting perm gen  total 31744K, used 31672K [0xcc140000, 0xce040000, 0xd2740000)
   the space 31744K,  99% used [0xcc140000, 0xce02e0b8, 0xce02e200, 0xce040000)
    ro space 10240K,  58% used [0xd2740000, 0xd2d1cae0, 0xd2d1cc00, 0xd3140000)
    rw space 12288K,  63% used [0xd3140000, 0xd38da8e8, 0xd38daa00, 0xd3d40000)

==> app-root/logs/mysql.log <==
140526 03:14:22 mysqld_safe Logging to '/var/lib/openshift/537f4c0f50044652c1000265/mysql//stdout.err'.
140526 03:14:23 mysqld_safe Starting mysqld daemon with databases from /var/lib/openshift/537f4c0f50044652c1000265/mysql/data/
140526 03:14:23 mysqld_safe Starting mysqld daemon with databases from /var/lib/openshift/537f4c0f50044652c1000265/mysql/data/
140526  3:14:23  InnoDB: Initializing buffer pool, size = 32.0M
140526  3:14:23  InnoDB: Completed initialization of buffer pool
140526  3:14:23  InnoDB: Started; log sequence number 0 44233
140526  3:14:23 [Note] Event Scheduler: Loaded 0 events
140526  3:14:23 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.1.73'  socket: '/var/lib/openshift/537f4c0f50044652c1000265/mysql//socket/mysql.sock'  port: 3306  Source distribution

We can get the information about the cartridges added to our application. Here are the suggested actions on the cartridge,

[root@vx111a funtest]# rhc cartridge

List of Actions
  add                Add a cartridge to your application
  list               List available cartridges
  reload             Reload the cartridge's configuration
  remove             Remove a cartridge from your application
  restart            Restart a cartridge
  scale              Set the scale range for a cartridge
  show               Show useful information about a cartridge
  start              Start a cartridge
  status             Get current the status of a cartridge
  stop               Stop a cartridge
  storage            View/manipulate storage on a cartridge

Available Cartridges
[root@vx111a funtest]# rhc cartridge list
jbossas-7           JBoss Application Server 7        web
jboss-dv-6.0.0 (!)  JBoss Data Virtualization 6     web
jbosseap-6 (*)      JBoss Enterprise Application     web
jenkins-1           Jenkins Server                          web
nodejs-0.10         Node.js 0.10                           web
nodejs-0.6          Node.js 0.6                              web
perl-5.10           Perl 5.10                                  web
php-5.3             PHP 5.3                                    web

Add a Cartridge
[root@vx111a funtest]# rhc app cartridge add -a dbtest -c mysql-5.1
Warning: This command is deprecated. Please use 'rhc cartridge-add' instead.

Adding mysql-5.1 to application 'dbtest' ... done

mysql-5.1 (MySQL 5.1)
  Gears:          Located with jbossas-7
  Database Name:  dbtest
  Password:       xxxxxxxxxx
  Username:       xxxxxxxxxx

MySQL 5.1 database added.  Please make note of these credentials:

   Root Password: XXXXXXXXXXX
   Database Name: dbtest


You can manage your new MySQL database by also embedding phpmyadmin.
The phpmyadmin username and password will be the same as the MySQL credentials above.

Cartridge Information
[root@vx111a funtest]# rhc cartridge show mysql -a dbtest
Using mysql-5.1 (MySQL 5.1) for 'mysql'
mysql-5.1 (MySQL 5.1)
  Gears:          Located with jbossas-7
  Database Name:  dbtest
  Password:       XXXXXXXXX
  Username:      XXXXXXXXX

Show Cartridge available to a application
[root@vx111a funtest]# rhc cartridge show mysql -a dbtest
Using mysql-5.1 (MySQL 5.1) for 'mysql'
mysql-5.1 (MySQL 5.1)
  Gears:          Located with jbossas-7
  Database Name:  dbtest
  Password:       XXXXXXXXX
  Username:      XXXXXXXXX

Status of a Cartridge
[root@vx111a funtest]# rhc cartridge status mysql -a dbtest
Using mysql-5.1 (MySQL 5.1) for 'mysql'

MySQL is running

Storage of a Cartridge
[root@vx111a funtest]# rhc cartridge storage mysql -a dbtest
Using mysql-5.1 (MySQL 5.1) for 'mysql'
MySQL 5.1
  Base Gear Storage:       1GB
  Additional Gear Storage: None

Deployment List
[root@vx111a funtest]# rhc deployment list dbtest
May 23  6:54 PM, deployment 63ad57cc

Deployment Information
[root@vx111a funtest]# rhc deployment show 63ad57cc -a dbtest
Deployment ID 63ad57cc (active)
  Git Reference:     master
  SHA1:              096f4f2
  Created At:        May 23  6:54 PM
  Hot Deploy:        false
  Force Clean Build: false
  Activations:       May 23  6:54 PM

Snapshots allow you to export the current state of your OpenShift application into an archive on your local system, and then to restore it later

[root@vx111a funtest]# rhc snapshot save -a dbtest
Pulling down a snapshot of application 'dbtest' to dbtest.tar.gz ... done

Restore action can be used to restore a previously stored snapshot.

----Thread Dump----
[root@vx111a funtest]# rhc threaddump -a dbtest

The thread dump file will be available via: rhc tail dbtest -g 537f4c0f50044652c1000265 -f /var/lib/openshift/537f4c0f50044652c1000265/app-root/logs/jbossas.log -o '-n 250'

----SSH Setup----
[root@vx111a rubygems-2.2.2]# rhc setup
OpenShift Client Tools (RHC) Setup Wizard

This wizard will help you upload your SSH keys, set your application
namespace, and check that other programs like Git are properly

Login to
Password: ***********

OpenShift can create and store a token on disk which allows to you to
access the server without using your password. The key is stored in
your home directory and should be kept
secret.  You can delete the key at any time by running 'rhc logout'.
Generate a token now? (yes|no) yes
Generating an authorization token for this client ... lasts about 1 month

Saving configuration to /root/.openshift/express.conf ... done

No SSH keys were found. We will generate a pair of keys for you.

    Created: /root/.ssh/

Your public SSH key must be uploaded to the OpenShift server to access
code.  Upload now? (yes|no) yes

Since you do not have any keys associated with your OpenShift account,
your new key will be uploaded as the 'default' key.

Uploading key 'default' ... done

Checking for git ... found git version 1.7.1

Checking common problems .. done

Checking for a domain ... fundomain

Checking for applications ... none

Run 'rhc create-app' to create your first application.

  Do-It-Yourself 0.1                      rhc create-app <app name> diy-0.1
  JBoss Application Server 7              rhc create-app <app name> jbossas-7
  JBoss Data Virtualization 6             rhc create-app <app name>
  JBoss Enterprise Application Platform 6 rhc create-app <app name> jbosseap-6
  Jenkins Server                          rhc create-app <app name> jenkins-1
  Node.js 0.10                            rhc create-app <app name> nodejs-0.10
  Node.js 0.6                             rhc create-app <app name> nodejs-0.6
  PHP 5.3                                 rhc create-app <app name> php-5.3
  PHP 5.4                                 rhc create-app <app name> php-5.4
  PHP 5.4 with Zend Server 6.1            rhc create-app <app name> zend-6.1
  Perl 5.10                               rhc create-app <app name> perl-5.10
  Python 2.6                              rhc create-app <app name> python-2.6
  Python 2.7                              rhc create-app <app name> python-2.7
  Python 3.3                              rhc create-app <app name> python-3.3
  Ruby 1.8                                rhc create-app <app name> ruby-1.8
  Ruby 1.9                                rhc create-app <app name> ruby-1.9
  Tomcat 6 (JBoss EWS 1.0)                rhc create-app <app name> jbossews-1.0
  Tomcat 7 (JBoss EWS 2.0)                rhc create-app <app name> jbossews-2.0
  Vert.x 2.1                              rhc create-app <app name>

  You are using 0 of 3 total gears
  The following gear sizes are available to you: small

Your client tools are now configured.

Now the SSH is configured, try to see the available domains

[root@vx111a rubygems-2.2.2]# rhc domain show
Domain fundomain (owned by
  Created:            5:19 PM
  ID:                 537de4445973ca6cf70000b2
  Allowed Gear Sizes: small

The domain fundomain exists but has no applications. You can use 'rhc create-app' to create a new application.

More to come , Happy Learning J

No comments :

Post a Comment