Openshift Cheatsheet

Deprecated

Openshift v2.0 has now reached End of Life and will be replaced by v3.0.


I primarily use Openshift for Node and Ghost apps, but I can never remember all the necessary commands needed to manage the server. This list is pretty much all you need to get started.

Managing SSH

SSH into your specific Openshift gear

rhc ssh -a [name of app] --namespace [name of namespace]

If you SSH into your application, then these are the commands you will use instead of rhc.

gear       control your application (start, stop, restart, etc.)
           or deps with --cart      (gear start --cart mysql-5.1)
tail_all   tail all log files
export     list available environment variables
rm         remove files/directories
ls         list files/directories
ps         list running applications
kill       kill running applications
mysql      interactive MySQL shell
mongo      interactive MongoDB shell
psql       interactive PostgreSQL shell
quota      list disk usage

Managing the Server

Start, stop or restart a cartridge

rhc cartridge restart [cartridge name] -a [name of app]

Reload the configuration without restarting your app

rhc app reload -a [name of app]

Restart the app

rhc app restart -a [name of app]

Force stop the app

rhc app force-stop -a [name of app]

View NodeJS console.log

rhc tail -a [name of app]

Manage scaling through HaProxy

This one is tricky but here's how to restart HaProxy

rhc cartridge-restart --cartridge haproxy -a [name of app]

Here's how to tweak something within the HaProxy config

rhc ssh -a [name of app] --namespace [name of namespace]
nano ~/haproxy/conf/haproxy.cfg

Managing Environmental Variables

View environmental variables

rhc env list -a [name of app] --namespace [name of namespace]

Create an Environmental Variable.

rhc env-set NODE_ENV=production --app [name of app]

Managing Filesystem

This diagram does an excellent job of explaining where files live. 90% of the time, you will be working with app-root.


Managing Storage

Calculating File Size

This will give you the 50 largest directories and files on the gear.

du -h * | sort -rh | head -50

Clean Up

Clean up the application’s logs, tmp directories, and even tidy up the git repo on the server:

rhc app-tidy -a main --namespace [name of namespace]

Resources