Restart all applications in PCF space

Viewed 1901

We have tons of services hosted in Pivotal Cloud Foundry(PCF). What is the best way to restart all micro-services in given space via scripts? Other challenge we have is we want to start services in order and introduce some delay between each service start ups. We are doing it manually right now but it is tedious and time consuming. Please suggest if anyway we can automate it. Thx.

2 Answers

I would suggest you write a wrapper-script either in powershell or bash that will first execute cf apps in your space

The above command will give you the App Name. Read that text and have your wrapper-script execute cf restart <APP_NAME> in a loop

This will restart all the Apps in your space...

Regarding Introducing delay in service start ups.. I would suggest you to have a CI/CD process to have your apps deployed (a Jenkins process, for example) with which you can have a complete control over your deployments

To realize what @Arun suggested:

for i in $(cf apps | grep '[0-9]/[0-9]' | cut -d" " -f1); do cf restart $i; done

To have a certain order, you could maintain a text file containing the app names in the correct order:

first_app
second_app
(...)

If the file is called app_order.txt, then to restart in order with a delay of say 30 seconds each, do:

while read i; do cf restart $i; sleep 30; done < app_order.txt
Related