Over a million developers have joined DZone.

CloudFoundry Coolness: Setting Environment Variables for an Application

· Cloud Zone

Learn about the benefits and drawbacks of microservices with best practices for your own architecture, brought to you in partnership with Iron.io.

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
$

 

 

The Cloud Zone is brought to you in partnership with Iron.io.  Learn about best practices and common pitfalls for working with Iron.io. Avoid the dead ends, and take the enlightened path.

Topics:

Published at DZone with permission of Hubert Klein Ikkink , DZone MVB .

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}