Pages

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 jagadesh.manchala@gmail.com on openshift.redhat.com
---------------------------------------------------------
  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 openshift.redhat.com
All systems running fine


----Domain----
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 openshift.redhat.com:
jagadesh.manchala@gmail.com
Password: ***********
done
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 openshift.redhat.com: jagadesh.manchala@gmail.com
Password: ***********

Domain fundomain (owned by jagadesh.manchala@gmail.com)
-------------------------------------------------------
  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>

----Application----
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 '54.234.230.143' to the list of known hosts.

Your application 'dbtest' is now available.

  URL:        http://dbtest-fundomain.rhcloud.com/
  SSH to:     537f4c0f50044652c1000265@dbtest-fundomain.rhcloud.com
  Git remote: ssh://537f4c0f50044652c1000265@dbtest-fundomain.rhcloud.com/~/git/dbtest.git/

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 @ http://funtest-fundomain.rhcloud.com/ (uuid: 537f2c545973caec750002b8)
--------------------------------------------------------------------------------
  Domain:     fundomain
  Created:    May 23  4:39 PM
  Gears:      1 (defaults to small)
  Git URL:    ssh://537f2c545973caec750002b8@funtest-fundomain.rhcloud.com/~/git/funtest.git/
  SSH:        537f2c545973caec750002b8@funtest-fundomain.rhcloud.com
  Deployment: auto (on git push)

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

Reload an Application
[root@vx111a funtest]# rhc app reload funtest
RESULT:
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


----Cartridge----
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
  Connection URL: mysql://$OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT/
  Database Name:  dbtest
  Password:       xxxxxxxxxx
  Username:       xxxxxxxxxx

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

   Root User: XXXXXXXXXXXXXXX
   Root Password: XXXXXXXXXXX
   Database Name: dbtest

Connection URL: mysql://$OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT/

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
  Connection URL: mysql://$OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT/
  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
  Connection URL: mysql://$OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT/
  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'

RESULT:
MySQL is running

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

----Deployments----
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----
SnapShots
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
Success

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
installed.

Login to openshift.redhat.com: jagadesh.manchala@gmail.com
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/id_rsa.pub

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-dv-6.0.0
  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>
jboss-vertx-2.1

  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 jagadesh.manchala@gmail.com)
-------------------------------------------------------
  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

22 comments :

  1. Ӏ will right away grab your rss as I can not find your email subscription hyperlink or e-newsletter service.

    Do you have any? Kindly allow me understand so thаt I
    could subsϲribe. Thanks.

    Also visit my web-sіte: temp2

    ReplyDelete
  2. Nice post. I learn something new and challenging on sites I stumbleupon everyday.
    It will always be exciting to read through articles from other authors and practice a little something from
    other web sites.

    Feel free to surf to my web-site; hindi movies

    ReplyDelete
  3. This is really interesting, You're a very skilled blogger.

    I have joinhed your rsss feed and look forward to seeking more
    of your great post. Also, I've sharedd your site in my social networks!


    Here is my web page - Ven Cleanse ()

    ReplyDelete
  4. Thank you for another excellent post. The place else may just
    anybody get that kind of information in such
    a perfect method of writing? I've a presentation subsequent week,
    and I am at the look for such information.

    my page; Vital Cleanse

    ReplyDelete
  5. What's Happening i'm new to this, I stumbled pon this I have discovered It positively helpful and it hhas
    aided me out loads. I am hoping to give a contribution &
    assist different users like its aided me. Great job.

    Here iss my website - Cellumis

    ReplyDelete
  6. It's actually a nice and helpful piece of information. I'm satksfied that you just shared this helpful information with us.
    Please keep us up to date like this. Thanks for sharing.


    My homepage; Garcinia Cambogia Pure Select

    ReplyDelete
  7. My partner and I stumbled over here from a different webbsite and thought I might check things out.
    I like whqt I see so now i am following you. Look forwardd tto going over our web paage for
    a second time.

    Also visit my site hangers joist - -

    ReplyDelete
  8. Wow, superb blog layout! How long have you been blogging for?

    you made blogging look easy. The overall lokok of
    your webb site is magnificent, let alone the content!


    Herre is my blog; Replennage Eyee Serum [http://replennage.org.uk/]

    ReplyDelete
  9. I like the valuable info you supply to your articles. I'll bookmark
    your blog and test once more right here regularly.
    I'm somewhat certain I will learn many new sstuff proper here!
    Best of luck for tthe next!

    Also visit mmy blo post: Hydravella

    ReplyDelete
  10. I do agree with all the concepts you've presented on your post.
    Theey are very convincing and will definitely work. Nonetheless, the posts are very brief for beginners.

    May just you please lengthen them a little from nedxt time?
    Thanks for the post.

    my web page ... Bella Teeth Whitening

    ReplyDelete
  11. Very quickly this website will be famous amid alll blog
    users, due tto it's nice content

    My web-site; Cellumis Serum

    ReplyDelete
  12. Exсеllent items from you, man. I've keep in mind your stuff prior tߋ
    and you're simply extremely great. I really like wһat you've got here, certainly like
    what you are stating and the best way by which you are sayіng it.
    You make it еnjoyable and you cⲟntinue to take care of
    to keep it smart. I can't wait to learn far morе from you.
    That is really a tremendous website.

    ReplyDelete
  13. Pretty nice post. I just stumbled upon your weblog and wished
    to say that I have really loved browsing your blog posts.
    After all I'll be subscribing for your rss feed and I'm hoping you write again soon!

    ReplyDelete
  14. You're so interesting! I do not suppose I've read through something
    like this before. So great to find somebody with a few original
    thoughts on this subject. Seriously.. thank you for starting this
    up. This website is something that is required on the web, someone with a bit of originality!

    ReplyDelete
  15. My brother suggested I might like this web site. He was totally right.
    This post truly made my day. You can not imagine simply how much time I had spent for this info!
    Thanks!

    ReplyDelete
  16. Incredible points. Outstanding arguments. Keep up the good spirit.

    ReplyDelete
  17. After I originally commented I seem to have
    clicked on the -Notify me when new comments are added- checkbox and now whenever a comment is added
    I recieve four emails with the same comment.

    There has to be a means you are able to remove me from that service?

    Kudos!

    ReplyDelete
  18. Wow, this piece of writing is nice, my younger sister
    is analyzing these kinds of things, thus I am going to tell her.

    ReplyDelete
  19. My brother recommended I might like this website. He used to be totally right.
    This publish truly made my day. You can not believe just how much time I had spent for this information! Thank you!

    ReplyDelete
  20. Thanks for finally writing about >"Managing OpenShift with RHC Command Line" <Liked it!

    ReplyDelete
  21. Heya i'm for the primary time here. I found this board and I in finding It truly useful & it
    helped me out much. I am hoping to give something again and help others such as you helped me.

    ReplyDelete
  22. Great delivery. Great arguments. Keep up the great work.

    ReplyDelete