Loading

CloudHub 2.0 - How to perform a bulk rolling restart of Private Space applications using the API

Julkaisupäivä: Sep 29, 2026
Kuvaus

Runtime Manager does not provide a bulk restart for CloudHub 2.0 applications. When many applications on a Private Space need new replicas, for example after a Private Space change that only takes effect when replicas are recreated, restarting them one by one in the UI is slow and error-prone.

This article describes the attached script ch2_bulk_restart.py. It performs a rolling restart of every running application deployed to a Private Space in one business group and environment, and records the result for every application.

Ratkaisu

GOAL

Restart all running CloudHub 2.0 applications deployed to Private Spaces in a business group and environment, with a rolling update (no downtime for applications that use the rolling update strategy), without changing their configuration.

HOW IT WORKS

CloudHub 2.0 creates a new deployment version and replaces the replicas whenever the application configuration changes. The script changes one dummy application property, restart.count, incrementing it by one on every run. For each application it:

  1. Reads the current deployment with the Application Manager API v2 (GET .../amc/application-manager/api/v2/organizations/{orgId}/environments/{envId}/deployments/{deploymentId}).
  2. Builds a PATCH body that contains all current application properties plus restart.count, and all protected (secure) properties with their masked value ******. A masked value keeps the stored secret. See KB 005316378.
  3. Checks the body before sending it. Every existing property and protected property must be present and unchanged. Otherwise, the app is not patched and is reported as UNSAFE.
  4. Sends PATCH for that deployment and checks the response: same property set, the new restart.count value, and a new deployment version.

Only the application properties section is sent. Other settings are not included in the request and are not changed: log levels, scheduler settings, ingress/public endpoint, runtime version, replicas, vCores, JVM arguments, update strategy and the rest of the deployment settings.

BEFORE YOU START – IMPORTANT CAVEATS

  1. Every run restarts every selected application. Each run creates a new deployment version for each app, and the new version is visible in the app's configuration history. Running the script again restarts the apps again, including apps that were already restarted in an earlier run.
  2. The property PATCH replaces the whole property set. Any property or protected property left out of a PATCH is deleted, and a deleted protected property cannot be recovered from the platform. This is why a simple loop of API calls is risky (see also KB 001120993 for the same behaviour with the Anypoint CLI). The script always re-sends every property, and refuses to patch if it cannot confirm that.
  3. The restart.count property is added to each application and is visible to the app like any other property. Do not use a property with this name in your applications, as a plain or a protected property.
  4. Only Private Space applications are selected. The script skips:
    • applications on Shared Spaces,
    • Runtime Fabric applications (see KB 001117072 for those),
    • stopped applications,
    • deployments with status FAILED.
    Applications that are still APPLYING a change are included.
  5. One business group and one environment per run. Business groups below the one you pass are not processed; run the script once per business group and environment. Private Spaces shared from a parent business group are included.
  6. Applications with the recreate update strategy have downtime, because the old replicas stop before the new ones start. These apps are skipped unless you pass --include-recreate.
  7. Rolling updates need spare Private Space capacity. For each app, a new replica starts before the old one stops. When many apps restart together, new replicas can stay PENDING with reasons such as "Waiting for compute capacity to be provisioned for the replica" or network initialization messages. The old replicas keep running, so the application stays available, but the restart takes longer. The script pauses after each batch (by default 120 seconds after every 5 restarts). On busy Private Spaces use a smaller --batch-size or a longer --batch-pause.
  8. Apps on an unsupported runtime version cannot be restarted this way. The platform rejects the PATCH with HTTP 400: Runtime Version not supported for this target. and applies no change. The script reports these apps as ERROR with the runtime version, and continues. Update these apps to a supported runtime version (the latest patch is recommended) in Runtime Manager. The update itself restarts them.
  9. A restart does not fix an application that fails to start. An app that is APPLYING because its new replicas keep crashing is restarted again, and the new version fails the same way. Check such apps in Runtime Manager before the run, or leave them out with --app.
  10. Use a connected app (client credentials). This is highly recommended. The script renews a connected app token automatically if it expires during the run. A pasted bearer token cannot be renewed: if it expires, the run stops part-way. The script shows a warning at the start when it runs with a pasted token.
  11. Always do a dry run first and test in a non-production environment. Without --execute nothing is changed.

PREREQUISITES

  • Python 3. The script uses only the standard library, so there is nothing to install.
  • The business group ID and the environment ID. The script checks that both exist, and that the environment belongs to the business group, before it does anything else.
  • A connected app that acts on its own behalf (client credentials), with access to the business group and environment. Alternatively, a bearer token (not recommended).
  • For a control plane other than the US one, the host name, for example eu1.anypoint.mulesoft.com.

PROCEDURE

  1. Download the attached ch2_bulk_restart.py.
  2. Set the connected app credentials as environment variables. Do not write them into the script or any file.
    macOS / Linux:
    export ANYPOINT_CLIENT_ID=<client id>
    export ANYPOINT_CLIENT_SECRET=<client secret>
    
    Windows (PowerShell):
    $env:ANYPOINT_CLIENT_ID="<client id>"
    $env:ANYPOINT_CLIENT_SECRET="<client secret>"
    If both a connected app and ANYPOINT_TOKEN are set, the connected app is used.
  3. Run a dry run. It reads everything and shows what would be done, but changes nothing:
    python3 ch2_bulk_restart.py --org <businessGroupId> --env <environmentId>
    Check the list: every app is shown as WOULD (would be restarted) or SKIP (with the reason), together with its property counts, update strategy, replicas and runtime version.
  4. Run the restart:
    python3 ch2_bulk_restart.py --org <businessGroupId> --env <environmentId> --execute
    To restart only some applications, add --app <name> once for each app.
  5. Watch the applications in Runtime Manager until the new replicas are running. The script does not wait for each rollout to finish.

Options

OptionMeaning
--orgBusiness group ID (required)
--envEnvironment ID (required)
--executeActually restart. Without it the run is a dry run.
--app NAMEOnly this application; repeat for more than one
--include-recreateAlso restart apps with the recreate update strategy (downtime)
--batch-size NRestarts per batch, default 5. Only accepted restarts count.
--batch-pause SSeconds to wait after each batch, default 120
--hostControl plane host, default anypoint.mulesoft.com
--report-dirWhere run reports are written, default reports/ next to the script

RESULTS AND REPORTS

Every application gets a result line on screen, for example:

[12/35] ERROR      app-a  PATCH rejected: HTTP 400: Runtime Version not supported for this target. (runtime 4.8.5:4e-java8)
[14/35] PATCHING   app-b
[14/35] PATCHED    app-b  props 14->14, protected 0, restart.count->2, rolling, replicas 1, runtime 4.6.34:6-java8, new version 9a603387
ResultMeaning
WOULDDry run: would be restarted
SKIPNot selected; the reason is shown
PATCHEDRestart requested; new deployment version created
ERRORRejected by the platform (for example HTTP 400) or not applied; nothing changed for this app
UNSAFENot sent, because the request could not be confirmed to keep all properties
UNKNOWNThe PATCH got a server error, so it may or may not have been applied. The run stops. Check this app in Runtime Manager before running again.
CHECKThe PATCH response did not match the request. The run stops. Check this app in Runtime Manager.

Each run writes a folder named <businessGroupId>_<environmentId>_<YYYYMMDDHHMMSS> that contains:

  • run.log: the same lines as the screen.
  • report.json: every application with its result and reason. For restarted apps it also has the previous and new deployment version.

The run also stops if authentication fails. If a restart was not applied because of that, it is recorded against the application.

ROLLBACK

To return an application to the version it had before the restart:

  1. In Runtime Manager, open the application.
  2. Go to Settings > Configuration (Config changes history).
  3. Select the previous version and click Deploy.

report.json lists the previous version for each restarted application.

References

Lisäresurssit

ADDITIONAL INFORMATION

Disclaimer – not a MuleSoft product.

The attached script ch2_bulk_restart.py is provided as a sample only. It is not a MuleSoft product, is not covered by MuleSoft Support or any SLA, and is provided "as is" without warranty of any kind.

Before you run it against production:

  • Review the script and make sure you understand what it changes.
  • Run it first in dry-run mode, then with --execute, in a non-production environment.
  • Check that your applications restart and recover as expected.

You are responsible for testing, running and maintaining the script in your environment. The script prints the same disclaimer at the start of every run.

Knowledge-artikkelin numero

005460813

Liitteet

ch2_bulk_restart.py.zip

7 KB

 
Ladataan
Salesforce Help | Article