curl -sL https://gist.githubusercontent.com/drnic/b42bbcda9b47bd2241cdc41cdfd4abed/raw/c5c2e27377c43bdd04dd86463ca48cce3677580d/run.sh | bash
Last active
July 23, 2018 03:33
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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