Skip to content
SHC Docs

A seed job

This page adds a job: a command SHC runs for the deployment rather than a service it keeps running. A database often needs a first value before the app can use it. Putting it there is a command that ends, so it is a job, not a container left sitting after its work is done.

seed runs redis-cli in counter once Redis is up and sets visits to 0. setnx sets a key only when it is not there yet, so a count that already exists is kept. A job is a file of the app, <name>.job.yaml.

~/learn/guestbook/seed.job.yaml
name: seed
context: service
service: counter
after: [counter]
command: redis-cli setnx visits 0
timeout: 60

context: service runs the command inside the running counter container. after: [counter] holds the job until counter reads ready, which its healthcheck decides. A job with after runs at every install and update, once for the deployment, never on a restart; if it fails, so does the install or update.

home01
$ shc validate ~/learn/guestbook
...
$ shc update guestbook
...

guestbook’s counter already held 3, and setnx left it alone.

home01
$ shc exec -s guestbook -S counter -- redis-cli get visits
3

A new deployment of the app is where the seed matters: its counter starts empty. Install a second copy, read its count, and remove it.

home01
$ shc install ~/learn/guestbook -s fresh
...
home01
$ shc exec -s fresh -S counter -- redis-cli get visits
0

uninstall backs a deployment up before it removes it, and this node has no backup repository yet, so that backup would refuse: --no-backup removes the copy without one.

home01
$ shc uninstall fresh --no-backup --yes
...

Next: Replicas and scale.