Search

Dark theme | Light theme

June 15, 2012

CloudFoundry Coolness: Setting Environment Variables for an Application

We can set environment variables for an application that is deployed in CloudFoundry. For example if we want to pass a JAVA_OPTS environment variable with a value of -XX:MaxPermSize=256m. We have to use the env-add command of the vmc command-line tool. We specify the application name we want to set the environment variable for followed by a key=value pair.

In the following command we set a JAVA_OPTS environment variable for the website application:

$ vmc env-add website JAVA_OPTS="-XX:MaxPermSize=256m -XX:+CMSClassUnloadingEnabled"
Adding Environment Variable [JAVA_OPTS="-XX:MaxPermSize=256m -XX:+CMSClassUnloadingEnabled"]: OK
Stopping Application: OK
Staging Application: OK
Starting Application: OK
$

To see which environment variables are set we can use the env command. To delete a variable we use env-del and the name of the environment variable.

$ vmc env website

+-----------+----------------------------------------------------+
| Variable  | Value                                              |
+-----------+----------------------------------------------------+
| JAVA_OPTS | -XX:MaxPermSize=256m -XX:+CMSClassUnloadingEnabled |
+-----------+----------------------------------------------------+

$ vmc env-del website JAVA_OPTS
Deleting Environment Variable [BLOG_OPTS]: OK
Stopping Application: OK
Staging Application: OK
Starting Application: OK
$