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.
name: seedcontext: serviceservice: counterafter: [counter]command: redis-cli setnx visits 0timeout: 60context: 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.
$ shc validate ~/learn/guestbook...$ shc update guestbook...guestbook’s counter already held 3, and setnx left it alone.
$ shc exec -s guestbook -S counter -- redis-cli get visits3A new deployment of the app is where the seed matters: its counter starts empty. Install a second copy, read its count, and remove it.
$ shc install ~/learn/guestbook -s fresh...$ shc exec -s fresh -S counter -- redis-cli get visits0uninstall 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.
$ shc uninstall fresh --no-backup --yes...Next: Replicas and scale.