Pivotal Cloud Foundry - Why is restart required after bind-service

1.9k Views Asked by At

The entry in VCAP_SERVICES seems to be getting added as soon as as cf bind-service command is called. If that is the case why is Restart required

3

There are 3 best solutions below

0
On

When you bind a new service, restarting the app is not enough. You have to restage it.

Restaging your application stops your application and restages it, by compiling a new droplet and starting it.

Go thru the Starting, Restarting, and Restaging Applications for more details.

Also go thru How Applications are staged to understand the staging lifecycle, how a droplet is created and stored.

0
On

The VCAP_SERVICES OS environment variable is set when an application starts up. Once a process is started the value of the environment variable can't be changed. This is why after doing a cf bind-service the application needs to be restarted to see the new value of VCAP_SERVICES

When you a do a cf push The builpack executes and some build packs inspect which services have been bound to an app and might react to the presence of a service. For example if you have bind a newrelic service to the app then the buildpack will install the newrelic agent into the dropplet created by the cf push. This is why for after cf bind-service operations you should do a cf restage to re-run the buildpack and give it a chance to react to the presence of the newly bound services by modify the droplet generated by the buildpack.

0
On

When you bind a service to an application following, the VCAP_SERVICES field is updated. When you restart an app, the droplet is not newly created. Hence you need to restage the app. Restaging recreates your droplet and stores it in the Blobstore. As a result the changes get reflected.