Example: Update a service to its latest version
This documentation is part of the Manage services with the CLI guide. You can view the complete 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 your service version, available updates, 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 updates are grouped into steps: each service-update installs the next step. This script applies each 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 created automatically. If you need to roll back, stackhero service-backups-list --service="${service}" lists the backups, and stackhero service-backup-rollback --service="${service}" --backup=BACKUP_ID restores one.