Pivotal Cloud Foundry中Restage与Restart的区别及选型时机问询
As someone who’s worked with PCF for years and helped troubleshoot countless deployment questions, let’s break down exactly what separates these two operations and when you should reach for each.
Core Differences at a Glance
Restart: Quick Process Reset
Think of cf restart <app-name> as hitting the "reboot" button on your running app instances. Here’s what it does:
- It stops all currently running instances of your app, then spins them back up using the existing, pre-built droplet (the packaged runtime environment created when you last pushed or restaged the app).
- No re-compilation, no re-downloading dependencies, no re-running buildpacks—just a fresh start for the app processes.
- One key detail: While it doesn’t touch the droplet, it does load the latest environment variables and service bindings. So if you just bound a new database or updated a config var, restart will pick those up without rebuilding.
Restage: Full Rebuild + Restart
cf restage <app-name> is more like hitting "rebuild and reboot". It goes through the entire application build pipeline again:
- It takes the application code/package you last pushed to PCF, runs the associated buildpack(s) from scratch—re-downloading dependencies, compiling code (if needed), applying buildpack configs, and generating a brand-new droplet.
- Once the new droplet is ready, it replaces the old one and starts fresh instances with this updated package.
- This means any changes to buildpack settings, dependency versions (specified in your app’s config), or build-time environment variables will take effect here.
When to Use Which Operation?
Go for Restart If:
- Your app is misbehaving (e.g., memory leaks, frozen processes) and you just need to reset the running instances quickly.
- You’ve updated environment variables or bound/unbound services, and need the app to pick up those changes without waiting for a build.
- Your code and dependencies haven’t changed at all—you just need a process refresh.
Example: You just bound a new Redis service to your Node.js app and need the app to read the new REDIS_URL config var. A restart is perfect here—it’s fast and gets the job done.
Go for Restage If:
- You’ve modified buildpack configurations (e.g., updated
JAVA_OPTSfor a Java app, switched to a newer buildpack version, or adjusted build-time env vars). - Your app’s dependencies need to be re-resolved or updated (e.g., you pushed a new
package.jsonwith updated npm packages, or the buildpack has a security patch for a runtime library). - The existing droplet is corrupted (e.g., build cache got messed up, leading to missing files or broken dependencies).
- You’ve changed the app’s start command (in
manifest.ymlor via buildpack settings) and need that change to take effect.
Example: You updated the Maven_OPTS in your app’s manifest to increase build-time memory. A restart won’t apply this—you need to restage to let the buildpack pick up the new settings during the rebuild.
Common Misconception to Avoid
Restage does not pull new code from your local machine or version control—if you’ve made code changes, you still need to run cf push first. Restage only uses the code/package that’s already been uploaded to PCF.
内容的提问来源于stack exchange,提问作者Vijai

