Example: Update a service to its latest version

This documentation is part of the Use the CLI guide. View the full guide here: Install and use the Stackhero CLI to manage your stacks and services from the command line, scripts, CI, and AI agents.

service-updates-list shows the version of your service, the updates available, and the severity of each one (normal, critical, or critical, internet blocked). Add --changelog to read what each version brings.

Some versions cannot be skipped, so the updates are grouped in steps: each service-update installs the next step. This script applies every step, one after the other:

#!/bin/bash
set -e

service="My service"   # A service name or ID. See: `stackhero services-list`

stackhero service-updates-list --service="${service}" --changelog

while [ "$(stackhero service-updates-list --service="${service}" --format=json | jq .steps)" != "0" ]; do
  stackhero service-update --service="${service}" --confirm
  stackhero service-wait-for --service="${service}"
done

Before an update, a backup of your service is taken automatically. If you need to go back, stackhero service-backups-list --service="${service}" lists the backups, and stackhero service-backup-rollback --service="${service}" --backup=BACKUP_ID restores one.