To validate if an external service is reachable from your Cloud Foundry instance, you normally would like to send a kind of ping
from there. The easiest way to do so is CF SSH.
However, if your Ops admin disabled CF SSH, the Connection Tester for Cloud Foundry becomes handy.
The tester can also be used in other clouds and remote servers, since it is written in Java and reads an environment variable.
- Download the app's .jar file from here.
- Push it to the cloud:
cf push connection-test --no-route --no-start -u none -p connection-tester-cloudfoundry-1.0.0.jar
- Configure the target URL (without schema):
cf set-env connection-test URL "www.google.com:80"
- Start the app:
cf start connection-test
CF will report the app as crashed because it shuts itself down after the test. - Stop the app:
cf stop connection-test
- Find the test result in the logs:
cf logs connection-test --recent
Being a good 12-factor-app the Connection Tester prints its logs to Standard Out and Standard Error.
You can display the most recent logs by using: cf logs connection-test --recent
.
Or you can monitor the log output live during the app's execution in a second terminal: cf logs connection-test
.
OUT Creating container
OUT Successfully created container
OUT Starting health monitoring of container
OUT Read URL from environment variables: "www.google.de:80"
OUT Trying to connect (timeout: 10000 milliseconds)...
OUT Connecting to "www.google.de:80" was successful!
OUT Exit status 0
OUT Creating container
OUT Successfully created container
OUT Starting health monitoring of container
OUT Read URL from environment variables: "www.google.de:80"
OUT Trying to connect (timeout: 10000 milliseconds)...
ERR Connecting to "www.google.de:80" failed!
OUT Exit status 0
The Connection Tester exits normally after it tested the connection. It doesn't run any other background processes or keeps an HTTP endpoint open, so there is no need to keep running. This is signalled with exit code 0
.
However, Cloud Foundry expects the app to keep on running forever - even if the health check has been disabled on purpose and no route has been set up. This is considered to be a feature, not a bug:
Codependent step exited
Your application has exited normally and has returned an exit code of 0. This often happens when a program finishes it's execution and is complete. While this may seem like a normal thing, apps that run on PWS should never finish. A well behaved application should continue listen for HTTP requests or work indefinitely. If you see this error, check for cases where your application might finish without any errors.
CLOUD FOUNDRY is a trademark of the CloudFoundry.org Foundation in the United States and other countries.