Skip to content

Instantly share code, notes, and snippets.

@mrbuk
Last active June 28, 2016 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mrbuk/71faef39e5005694b11564ab00c38458 to your computer and use it in GitHub Desktop.
Save mrbuk/71faef39e5005694b11564ab00c38458 to your computer and use it in GitHub Desktop.
PCF Stop/Start (including services)
#!/bin/sh
# bosh setup
alias bosh='BUNDLE_GEMFILE=/home/tempest-web/tempest/web/bosh.Gemfile bundle exec bosh'
# extract list of all deployments
echo "# Running 'bosh deployments'"
echo "#"
deployments=$(bosh deployments 2>/dev/null | grep 'bosh-vsphere' | awk -F '|' '{print $2}' | sed -E 's/\s//g')
echo "# The following deployments exists:"
echo "# $(printf "%s " $deployments)"
echo "#"
# download deployments
echo "# Creating download instructions for deployment manifests"
for deployment in $deployments; do
bosh download manifest ${deployment} ${deployment}
done
echo "#"
#!/bin/sh
# bosh setup
alias bosh='BUNDLE_GEMFILE=/home/tempest-web/tempest/web/bosh.Gemfile bundle exec bosh'
# extract list of all deployments
echo "# Running 'bosh deployments'"
echo "#"
deployments=$(bosh deployments 2>/dev/null | grep 'bosh-vsphere' | awk -F '|' '{print $2}' | sed -E 's/\s//g')
echo "# The following deployments exists:"
echo "# $(printf "%s " $deployments)"
echo "#"
# seperate deployments between CF and services
cf_deployment=$(printf "%s\n" $deployments | grep 'cf-')
srv_deployments=$(printf "%s\n" $deployments | grep -v 'cf-')
echo "# Generating stop commands of PCF jobs to be stopped:"
echo "#"
# filter so that we only get the running ones, extract the name only
# extract list of vms
echo "bosh deployment ${cf_deployment}"
cf_vms=$(bosh vms $cf_deployment 2>/dev/null | grep 'running' $vms_all | awk -F '|' '{print $2}' | sed -E 's/\s//g' | awk -F"/" '{print $1}' | sort -u)
# stop order for PCF - see: https://docs.pivotal.io/pivotalcf/customizing/start-stop-vms.html
pcf_stop_order_before_services="loggregator_trafficcontroller- doppler- dea- diego_cell- diego_brain- uaa- collector-"
for comp in $pcf_stop_order_before_services; do
for comp_indexed in $(printf "%s\n" $cf_vms | grep $comp); do
prefix=$(printf "%s" "$comp_indexed" | egrep -o "^[^-]+")
case $prefix in
"dea" | "diego_cell")
echo "bosh stop --skip-drain $comp_indexed"
;;
*)
echo "bosh stop $comp_indexed"
;;
esac
done
done;
echo "#"
# extract list of all services
# stop order for service
# -> stop the broker (no new services can be provisioned)
# -> stop the ha proxy (no communication to the nodes possible)
# -> stop the instances ()
echo "# Generating stop commands for service deployments"
for deployment in $srv_deployments; do
echo "bosh deployment ${deployment}"
deployment_vms=$(bosh vms $deployment 2>/dev/null | grep 'running' | awk -F '|' '{print $2}' | sed -E 's/ //g' | awk -F"/" '{print $1}' | sort -u)
# stop broker
for comp_indexed in $(printf "%s\n" $deployment_vms | grep "broker"); do
echo bosh stop $comp_indexed
done
# stop (ha) proxy
for comp_indexed in $(printf "%s\n" $deployment_vms | grep "proxy"); do
echo bosh stop $comp_indexed
done
# stop rest
for comp_indexed in $(printf "%s\n" $deployment_vms | grep -v "proxy" | grep -v "broker"); do
echo bosh stop $comp_indexed
done
echo "#"
done
#
# stop order for PCF - see: https://docs.pivotal.io/pivotalcf/customizing/start-stop-vms.html
#
# stopping rest of PCF components after services. Some service may rely upon PCF service like the cc or uaa. also without nats running stopping via BOSH doesn't make sense.
#
echo "bosh deployment ${cf_deployment}"
pcf_stop_order_after_services="cloud_controller_worker- clock_global- health_manager- ha_proxy- cloud_controller- consoledb- uaadb- ccdb- mysql- mysql_proxy- router- nfs_server- diego_database- etcd_server- consul_server- nats-"
for comp in $pcf_stop_order_after_services; do
for comp_indexed in $(printf "%s\n" $cf_vms | grep $comp); do
echo bosh stop $comp_indexed
done
done;
echo "#"
#!/bin/sh
# bosh setup
alias bosh='BUNDLE_GEMFILE=/home/tempest-web/tempest/web/bosh.Gemfile bundle exec bosh'
# extract list of all deployments
echo "# Running 'bosh deployments'"
echo "#"
deployments=$(bosh deployments 2>/dev/null | grep 'bosh-vsphere' | awk -F '|' '{print $2}' | sed -E 's/\s//g')
echo "# The following deployments exists:"
echo "# $(printf "%s " $deployments)"
echo "#"
# seperate deployments in CF and services
cf_deployment=$(printf "%s\n" $deployments | grep 'cf-')
srv_deployments=$(printf "%s\n" $deployments | grep -v 'cf-')
echo "# Generating start commands of PCF jobs to be started:"
echo "#"
# filter so that we only get the running ones, extract the name only
# extract list of vms
echo "bosh deployment ${cf_deployment}"
cf_vms=$(bosh vms $cf_deployment 2>/dev/null | grep 'running' $vms_all | awk -F '|' '{print $2}')
# start order for PCF - see: https://docs.pivotal.io/pivotalcf/customizing/start-stop-vms.html
pcf_stop_order_before_services="nats- consul_server- etcd_server- diego_database- nfs_server- router- mysql_proxy- mysql- ccdb- uaadb- consoledb- cloud_controller- ha_proxy- health_manager- clock_global- cloud_controller_worker-"
for comp in $pcf_stop_order_before_services; do
for comp_indexed in $(printf "%s\n" $cf_vms | grep $comp); do
echo bosh start $(echo $comp_indexed | sed -E 's|/| |g')
done
done;
echo "#"
# extract list of all services
# start order for service
# -> start the nodes
# -> start the ha proxy
# -> start the broker
echo "# Generating start commands for service deployments"
for deployment in $srv_deployments; do
echo "# running bosh vms $deployment"
echo "bosh deployment ${deployment}"
deployment_vms=$(bosh vms $deployment 2>/dev/null | grep 'running' | awk -F '|' '{print $2}' | sed -E 's/ //g')
# start actual nodes
for comp_indexed in $(printf "%s\n" $deployment_vms | grep -v "proxy" | grep -v "broker"); do
echo bosh start $(echo $comp_indexed | sed -E 's|/| |g')
done
# start (ha) proxy
for comp_indexed in $(printf "%s\n" $deployment_vms | grep "proxy"); do
echo bosh start $(echo $comp_indexed | sed -E 's|/| |g')
done
# start broker
for comp_indexed in $(printf "%s\n" $deployment_vms | grep "broker"); do
echo bosh start $(echo $comp_indexed | sed -E 's|/| |g')
done
echo "#"
done
# start order for PCF - see: https://docs.pivotal.io/pivotalcf/customizing/start-stop-vms.html
#
# start rest of PCF components after services. Collector, applications running in DEAs and Diego rely on PCF services.
#
pcf_stop_order_after_services="collector- uaa- diego_brain- diego_cell- dea- doppler- loggregator_trafficcontroller-"
for comp in $pcf_stop_order_after_services; do
for comp_indexed in $(printf "%s\n" $cf_vms | grep $comp); do
echo bosh start $(echo $comp_indexed | sed -E 's|/| |g')
done
done;
echo "#"

Login to OpsMgr via SSH

Create a directory e.g.

  mkdir 20160501_pcf_stop_start

Copy 01_download_deployment_manifest.sh, 02_create_stop_commands.sh and 03_create_start_commands.sh into the previously created directory.

Important: The commands will only be generated for jobs ins running state. Please make sure everything is running before executing using

  bosh vms | grep -v running

Run the following commands on the OpsMgr console (being logged via SSH)

  sh 01_download_deployment_manifest
  sh 02_create_stop_commands.sh > stop_commands
  sh 03_create_start_commands.sh > start_commands

Validate the content of the files stop_commands and start_commands. It is recommened that when executing you have two sessions open.

  • Session 1: run the 'meta' commands in this session and keep *_commands open.
  • Session 2: run the actual bosh commands here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment