Skip to content

Instantly share code, notes, and snippets.

@drnic
Last active July 23, 2018 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drnic/b42bbcda9b47bd2241cdc41cdfd4abed to your computer and use it in GitHub Desktop.
Save drnic/b42bbcda9b47bd2241cdc41cdfd4abed to your computer and use it in GitHub Desktop.
Stop all Cloud Foundry applications in any spaces with "staging" in their name
curl -sL https://gist.githubusercontent.com/drnic/b42bbcda9b47bd2241cdc41cdfd4abed/raw/c5c2e27377c43bdd04dd86463ca48cce3677580d/run.sh | bash
#!/bin/bash
space_name_filter=${space_name_filter:-staging}
cf_config_path=~/.cf/config.json
cf_config=$(cat ${cf_config_path})
function restore_cf_config {
echo "${cf_config}" > ${cf_config_path}
echo "Restoring ${cf_config_path}"
}
trap restore_cf_config EXIT
next_url="/v2/spaces?results-per-page=100"
while [[ "${next_url}" != "null" ]]; do
space_names=$(cf curl ${next_url} | jq -r ".resources[].entity.name" | grep ${space_name_filter})
for space_name in $space_names; do
cf target -s "${space_name}"
space_guid=$(cat ${cf_config_path} | jq -r .SpaceFields.GUID)
app_names=$(cf curl "/v2/spaces/${space_guid}/apps" | jq -r ".resources[].entity.name")
for app_name in $app_names; do
cf stop $app_name
done
done
next_url=$(cf curl ${next_url} | jq -r -c ".next_url")
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment