From d6d1f19f1b908417f00a02d2608735da114b2093 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Mon, 19 Jan 2015 16:43:38 -1000 Subject: [PATCH] website: Document the lock command --- .../source/docs/commands/index.html.markdown | 2 + .../source/docs/commands/lock.html.markdown | 61 +++++++++++++++++++ website/source/layouts/docs.erb | 4 ++ 3 files changed, 67 insertions(+) create mode 100644 website/source/docs/commands/lock.html.markdown diff --git a/website/source/docs/commands/index.html.markdown b/website/source/docs/commands/index.html.markdown index fafca6ed90..0b5c621369 100644 --- a/website/source/docs/commands/index.html.markdown +++ b/website/source/docs/commands/index.html.markdown @@ -33,7 +33,9 @@ Available commands are: info Provides debugging information for operators join Tell Consul agent to join cluster keygen Generates a new encryption key + keyring Manages gossip layer encryption keys leave Gracefully leaves the Consul cluster and shuts down + lock Execute a command holding a lock members Lists the members of a Consul cluster monitor Stream logs from a Consul agent reload Triggers the agent to reload configuration files diff --git a/website/source/docs/commands/lock.html.markdown b/website/source/docs/commands/lock.html.markdown new file mode 100644 index 0000000000..a2c3f77e98 --- /dev/null +++ b/website/source/docs/commands/lock.html.markdown @@ -0,0 +1,61 @@ +--- +layout: "docs" +page_title: "Commands: Lock" +sidebar_current: "docs-commands-lock" +description: |- + The lock command provides a mechanism for leader election, mutual exclusion, + or worker pools. For example, this can be used to ensure a maximum number of + services running at once across a cluster. +--- + +# Consul Lock + +Command: `consul lock` + +The `lock` command provides a mechanism for simple distributed locking. +A lock (or semaphore) is created at a given prefix in the Key/Value store, +and only when held, is a child process invoked. If the lock is lost or +communication disrupted, the child process is terminated.A + +The number of lock holder is configurable with the `-n` flag. By default, +a single holder is allowed, and a lock is used for mutual exclusion. This +uses the [leader election algorithm](/docs/guides/leader-election.html). + +If the lock holder count is more than one, then a semaphore is used instead. +A semaphore allows more than a single holder, but the is less efficient than +a simple lock. This follows the [semaphore algorithm](/docs/guides/semaphore.html). + +An example use case is for highly-available N+1 deployments. In these +cases, if N instances of a service are required, N+1 are deployed and use +consul lock with `-n=N` to ensure only N instances are running. For singleton +services, a hot standby waits until the current leader fails to take over. + +## Usage + +Usage: `consul lock [options] prefix child...` + +The only required options are the key prefix and the command to execute. +The prefix must be writable. The child is invoked only when the lock is held, +and the `CONSUL_LOCK_HELD` environment variable will be set to `true`. + +If the lock is lost, communication disrupted, or the parent process interrupted, +the child process will receive a `SIGTERM`. After a grace period, a `SIGKILL` +will be used to force termination. + +The list of available flags are: + +* `-http-addr` - Address to the HTTP server of the agent you want to contact + to send this command. If this isn't specified, the command will contact + "127.0.0.1:8500" which is the default HTTP address of a Consul agent. + +* `-n` - Optional, limit of lock holders. Defaults to 1. The underlying + implementation switches from a lock to a semaphore when increased past + one. + +* `-name` - Optional name to associate with the underlying session. + If not provided, one is generated based on the child command. + +* `-token` - ACL token to use. Defaults to that of agent. + +* `-verbose` - Enables verbose output. + diff --git a/website/source/layouts/docs.erb b/website/source/layouts/docs.erb index d6c5e2aaa7..7b44f3e9b0 100644 --- a/website/source/layouts/docs.erb +++ b/website/source/layouts/docs.erb @@ -85,6 +85,10 @@ > leave + + + > + lock >