etcdctl: support exec on lock

The lock command is clumsy to use from the command line, needing mkfifo,
wait, etc. Instead, make like consul and support launching a command if
one is given.
This commit is contained in:
Anthony Romano
2017-05-24 13:57:16 -07:00
parent 8c1ab62bc5
commit 643c2a310d
2 changed files with 38 additions and 7 deletions

View File

@@ -790,7 +790,7 @@ Prints a line of JSON encoding the database hash, revision, total keys, and size
## Concurrency commands
### LOCK \<lockname\>
### LOCK \<lockname\> [command arg1 arg2 ...]
LOCK acquires a distributed named mutex with a given name. Once the lock is acquired, it will be held until etcdctl is terminated.
@@ -798,13 +798,24 @@ LOCK acquires a distributed named mutex with a given name. Once the lock is acqu
Once the lock is acquired, the result for the GET on the unique lock holder key is displayed.
If a command is given, it will be launched with environment variables `ETCD_LOCK_KEY` and `ETCD_LOCK_REV` set to the lock's holder key and revision.
#### Example
Acquire lock with standard output display:
```bash
./etcdctl lock mylock
# mylock/1234534535445
```
Acquire lock and execute `echo lock acquired`:
```bash
./etcdctl lock mylock echo lock acquired
# lock acquired
```
#### Remarks
LOCK returns a zero exit code only if it is terminated by a signal and releases the lock.