Skip to content

Instantly share code, notes, and snippets.

@tammersaleh
Last active January 4, 2016 01:09
Show Gist options
  • Save tammersaleh/8546241 to your computer and use it in GitHub Desktop.
Save tammersaleh/8546241 to your computer and use it in GitHub Desktop.

Proposal for BOSH Errands

Background

We've had a number of requests for being able to run scripts against a deployment. The challenge has been defining these scripts and the execution environment without reducing the predictable, descriptive and deterministic nature of BOSH.

Use cases

Out of scope (for now...)

  • Triggered execution (ie: Run this errand after every deployment).
  • Cron support (ie: Run this errand every 10 minutes).
  • Running multiple instances of a particular errand at the same time. BOSH will error saying that the specified errand is already running.
  • Running an errand on the same VM as another job.

Proposal

Errands are defined in a release, and are configured in the deploy manifest. They are similar to Jobs, but are neither long running, nor deployed during a deployment.

When an errand is run, BOSH will provision a new VM using the specified stemcell, install that errand and all required packages and templates, and run the given command.

By making use of some of the same constructs as jobs, BOSH can ensure that errands are run in a completely predictable, descriptive, and deterministic environment each and every time.

Defining an Errand

Errands are defined in the release in a similar fashion to jobs. Errands make use of packages, and generate templates to configure those packages. This allows an errand that requires a specific runtime (such as ruby) to include it explicitly.

The only differences are:

  • Errands are first class objects. They're defined as errands as opposed to jobs.
  • Errands aren't run via monit, but via the bosh run errand command.
  • Errands are installed into /var/vcap/errands/foo

Configuring an Errand

Deploy Manifest

---
...
networks:
- name: default
  ...
resource_pools:
- name: default
  network: default
  ...
jobs:
  ...
errands:
- name: smoke_test
  release: release_name
  templates:
  - name: smoke_test
  resource_pool: default
  networks:
  - name: default
    default:
    - dns
    - gateway
  # instances: 1
  # persistent_disk: 20480

Running an Errand

Once an errand is defined and configured, running is as simple as bosh run errand smoke_test. Bosh will then provision a new VM, install the errand on it, and execute the errands/smoke_test/execute script.

Additional command-line arguments given to bosh run errand, will be passed to the remote script as command line arguments.

Open Questions

  1. Will errands be run asynchronously (like tasks)? If so, that opens up a whole can of work around bosh errands, bosh errand 123, etc. If not, then we'll have to ensure we don't have timeout issues.
  2. How will we provide the return code of the script being run as opposed to the return code of the bosh run errand command? If errands are async, then the bosh run errand foo command could return before the script finishes executing. If synchronous, then bosh run errand foo could be killed locally, while the script continues to a successful exit.
  3. How do we deal with script output? Do we need to stream that back to the bosh run errand command?
@tammersaleh
Copy link
Author

Let's keep all comments on the email thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment