Skip to content

Recovering from a partially-applied JPS install

When a JPS install aborts halfway, you're left with nodes, partial files, and orphan state. How to assess what actually happened and roll back cleanly.

A JPS install for a customer environment aborts at the eighth cmd action with a non-zero exit. The Jelastic UI marks the environment as failed, but the two nodes are provisioned, half the config files are in place, three of seven cron jobs are installed, and the database has a schema but no data. The standard advice — “delete the environment and reinstall” — is correct but costs you the provisioning time again and, more importantly, doesn’t tell you why it failed. This article is the runbook for both halves: assess and recover.

What’s happening

JPS install failures fall into two categories and the recovery procedure is different for each.

  • Install aborted before any meaningful side effects. Settings validation failed, a node didn’t provision, an early cmd action returned non-zero because of a missing dependency. The engine marks the environment failed, the nodes may or may not exist depending on how far it got, and there’s no state on the nodes worth preserving. Recovery: delete the environment, fix the manifest, reinstall.
  • Install aborted after side effects landed. Files were uploaded, services were configured, database schema was created, secrets were generated and stored. The engine marks the environment failed the same way, but now you have stateful nodes with half-configured services on them. Recovery: either fix forward (run the missing actions manually, then mark the environment installed), or roll back (capture the state you need, destroy the environment, reinstall clean).

The decision between fix-forward and roll-back depends on what’s at stake. For a development environment, always roll back — clean state is worth more than the install time. For a production environment where the install failed during cutover and the previous environment is gone, fix forward is sometimes the only option, but it requires that the manifest be idempotent enough to re-run from the failing action.

The other thing that bites operators is that JPS does not guarantee atomicity inside a single cmd action. If your action is a multi-line shell script and it fails on line 17, lines 1-16 ran. Whether they ran cleanly enough to retry depends entirely on whether you wrote them to be idempotent. Most operators don’t, and discover the hard way that running the manifest twice in a row creates two MySQL users with the same name, two cron entries, two systemd units in three different states.

How to verify

When you see failed in the Jelastic UI, the first job is to figure out exactly where it stopped. The install log is the source of truth:

# Pull the full log for the failed environment
jelastic environment.control.GetEnvInfo \
  --envName acme-broken --session "$SESSION_ID" \
  | jq -r '.env.log[] | "\(.created) \(.action) \(.actionResult) \(.message)"' \
  | tail -40

Read it from the bottom up. The first non-zero actionResult is where it failed. Note the action index and the node it ran on.

Then verify the actual state of the nodes — not what the manifest thought it did, what’s actually on disk:

# What did the manifest claim to do, and what's actually there?
jelastic environment.control.ExecCmdById \
  --envName acme-broken --session "$SESSION_ID" \
  --nodeId "$CP_NODE_ID" \
  --commandList '[
    {"command":"ls -la /var/www/webroot/ROOT/"},
    {"command":"systemctl is-active nginx php-fpm"},
    {"command":"crontab -l -u nginx"},
    {"command":"cat /var/www/webroot/ROOT/config/env.php 2>/dev/null | head -5 || echo MISSING"}
  ]'

jelastic environment.control.ExecCmdById \
  --envName acme-broken --session "$SESSION_ID" \
  --nodeId "$DB_NODE_ID" \
  --commandList '[
    {"command":"mysql -uroot -p${nodes.sqldb.password} -e \"SHOW DATABASES; SHOW GRANTS FOR '\''acme_app'\''@'\''%'\'';\""},
    {"command":"mysql -uroot -p${nodes.sqldb.password} -e \"SELECT COUNT(*) FROM acme.migrations\" 2>/dev/null || echo NO_TABLE"}
  ]'

Three questions to answer from the output:

  1. Did the install create durable state (database, generated secrets) that you’d lose by deleting the environment? If yes and the state is irreplaceable, you’re fix-forward.
  2. Are the partial files clean (consistent versions, valid syntax) or contradictory (half from version A, half from version B)? Contradictory state means roll back.
  3. Do the manifest’s actions you’d need to re-run from the failure point have idempotency guards? If yes, fix-forward is mechanical. If no, you’re either patching by hand or rolling back.

The fix

The roll-back path (preferred when feasible):

# 1. Capture the state you can't recreate from the manifest
SESSION="$SESSION_ID"
ENV=acme-broken
DB_NODE_ID=<from-jelastic-ui>

# Dump the database (in case there's seed data worth preserving)
jelastic environment.control.ExecCmdById \
  --envName "$ENV" --session "$SESSION" \
  --nodeId "$DB_NODE_ID" \
  --commandList '[{"command":"mysqldump --single-transaction --all-databases | gzip > /tmp/recover.sql.gz"}]'

jelastic environment.file.Read \
  --envName "$ENV" --session "$SESSION" \
  --nodeId "$DB_NODE_ID" \
  --path /tmp/recover.sql.gz > recover.sql.gz

# Save any generated secrets that were stored in files
jelastic environment.file.Read \
  --envName "$ENV" --session "$SESSION" \
  --nodeId "$CP_NODE_ID" \
  --path /var/www/webroot/ROOT/config/env.php > env.php.bak 2>/dev/null || true

# Save the original manifest + install log for post-mortem
jelastic environment.control.GetEnvInfo \
  --envName "$ENV" --session "$SESSION" > "$ENV"-failed-state.json

# 2. Delete the environment
jelastic environment.control.DeleteEnv \
  --envName "$ENV" --session "$SESSION" --password "$ACCOUNT_PASS"

# 3. Fix the manifest based on the failed action
# (root-cause whatever failed at action index N — usually a missing
#  dependency, a regex that didn't match real input, or a baseUrl
#  asset that 404'd)

# 4. Reinstall on a fresh environment
jelastic marketplace.app.Install \
  --manifest "$(cat manifest-fixed.yml)" \
  --envName "$ENV" \
  --displayName "Acme demo (recovered)" \
  --region yyz \
  --session "$SESSION"

The fix-forward path (when state matters and rebuild is too costly):

# 1. Identify the failing action
LAST_ACTION_INDEX=12   # from the install log

# 2. For each remaining action in the manifest, port it to a manual
#    invocation against the existing nodes
SESSION="$SESSION_ID"
ENV=acme-broken

# Action 13 in the manifest was a SQL load — run it by hand
jelastic environment.file.Write \
  --envName "$ENV" --session "$SESSION" \
  --nodeGroup sqldb \
  --path /tmp/schema.sql --body "$(cat schema-1.4.2.sql)"

jelastic environment.control.ExecCmdByGroup \
  --envName "$ENV" --session "$SESSION" \
  --nodeGroup sqldb \
  --commandList '[{"command":"mysql -uacme_app -p<pw> acme < /tmp/schema.sql && rm /tmp/schema.sql"}]'

# Action 14 was a config template — write it by hand with the
# same templating the manifest would have done

# ... etc. for each remaining action

# 3. Mark the environment installed (drops it out of the failed state)
jelastic environment.control.SetEnvDisplayName \
  --envName "$ENV" --session "$SESSION" --displayName "Acme demo"
# (no direct "mark installed" API; setting fields it through the platform
#  and confirming via env.control.GetEnvInfo that .env.status="running")

# 4. Write down what you did in a runbook entry on this environment
# and tag it so the next person knows the manifest history is incomplete.

After either path, do the manifest hardening that prevents the next failure:

  • Add idempotency guards to every cmd action that creates state. CREATE DATABASE IF NOT EXISTS. CREATE USER IF NOT EXISTS. if [ ! -f /path/to/marker ]; then ... ; touch /path/to/marker; fi. The marker-file pattern is the lowest-effort way to make a shell action re-runnable.
  • Capture state in onBeforeUpdate / early onInstall so rollback has something to work with. For installs, this is mostly a no-op (there’s nothing to back up before install). For updates, it’s the difference between a clean rollback and a hand-edited recovery.
  • Validate prerequisites in the first action. If the install needs network access to assets.example.com, the first cmd action should curl -fsI https://assets.example.com/jps/1.0/sentinel and exit non-zero if it can’t. Failing in action 1 is recoverable; failing in action 12 is a partial-install ticket.
  • Reject obviously-bad settings in the settings block, not in actions. Regex validation on email fields, value lists for region/version, required fields actually marked required. The earlier the engine refuses the install, the less state ends up half-created.

A failed install that you investigated and recovered from cleanly is a manifest improvement opportunity. A failed install that you blew away and reinstalled without root-causing is a failed install waiting to happen again.

Stack Harbor runs JPS-managed environments under Managed Cloud Ops with idempotency and recovery built into every manifest we ship — so a failed install is a logged event, not a customer outage. If you’ve inherited a fragile JPS pipeline, book a manifest audit and we’ll harden it.