Get lock from zookeeper and execute
Project description
lockex
======
lockex is a tool that attempts to acquire a lock from zookeeper prior
to executing a user supplied command.
If lockex cannot aquire a lock, it will block, wait and retry to acquire
the lock. Alernatively instead of blocking, lockex can exit after a given
timeout or immediately. The lock id is generated automatically based on
user supplied command. We also assume that the user command that is to
be run, is executed in the foreground.
By default if the concurrency is set it 1, lockex will try and get lock,
if the concurrency is greater than 1 then lockex will try to acquire a
lock via a semaphore.
lockex will die if the connection to zookeeper is lost, it will continue
to run if the connection is suspended. lockex will do it's best to
cleanup the child process when this happens.
License
-------
Please see COPYING
Use cases:
----------
* You have a producer/consumer based daemons, you can only run one
producer at a time. *lockex* will let you startup many producers but
only one will run if it has acquired a lock.
* A long running cronjob and you want to guarantee that it runs on only
on one host assuming the jobs all start within a small time window.
Installation:
-------------
pip install https://github.com/rapid7/lockex
Usage:
------
Running *lockex --help* will give you information about how to use
the application. In general,
lockex OPTIONS -- your_command your_args
*lockex* will treat anything after the '--' as the command that you want
to run. *lockex* will also look for the ZKHOSTS environment variable
to connect to your zookeeper cluster, the format is a comma seperated
list of 'hostname:port'.
Example:
--------
Assuming redis did not have a master/slave capability and you are using
supervisord to run your processes.
On host1, you have a single redis instance running (assuming the data
is stored in a shared location)
lockex -- /usr/local/bin/redis-server /etc/redis.conf
On host2, you have an identical configuration (with access to the data
in the shared location), run the same command as on host1
lockex -- /usr/local/bin/redis-server /etc/redis.conf
If and when host1's instance redis dies, host2 will acquire the lock
from zookeeper and startup redis. In a controlled example send host1's
lockex instance with a SIGTERM and it will kill it's child processes.
Requirements:
-------------
* A working installation of zookeeper and python2.7 or higher.
* A durable instance of zookeeper (at least three nodes).
* The hosts are all synchronised with ntp.
Vendored packages:
------------------
* lockex/glog.py - https://github.com/benley/python-glog - Copyright (c) 2015 Benjamin Staffin - under 2 clause BSD license.
======
lockex is a tool that attempts to acquire a lock from zookeeper prior
to executing a user supplied command.
If lockex cannot aquire a lock, it will block, wait and retry to acquire
the lock. Alernatively instead of blocking, lockex can exit after a given
timeout or immediately. The lock id is generated automatically based on
user supplied command. We also assume that the user command that is to
be run, is executed in the foreground.
By default if the concurrency is set it 1, lockex will try and get lock,
if the concurrency is greater than 1 then lockex will try to acquire a
lock via a semaphore.
lockex will die if the connection to zookeeper is lost, it will continue
to run if the connection is suspended. lockex will do it's best to
cleanup the child process when this happens.
License
-------
Please see COPYING
Use cases:
----------
* You have a producer/consumer based daemons, you can only run one
producer at a time. *lockex* will let you startup many producers but
only one will run if it has acquired a lock.
* A long running cronjob and you want to guarantee that it runs on only
on one host assuming the jobs all start within a small time window.
Installation:
-------------
pip install https://github.com/rapid7/lockex
Usage:
------
Running *lockex --help* will give you information about how to use
the application. In general,
lockex OPTIONS -- your_command your_args
*lockex* will treat anything after the '--' as the command that you want
to run. *lockex* will also look for the ZKHOSTS environment variable
to connect to your zookeeper cluster, the format is a comma seperated
list of 'hostname:port'.
Example:
--------
Assuming redis did not have a master/slave capability and you are using
supervisord to run your processes.
On host1, you have a single redis instance running (assuming the data
is stored in a shared location)
lockex -- /usr/local/bin/redis-server /etc/redis.conf
On host2, you have an identical configuration (with access to the data
in the shared location), run the same command as on host1
lockex -- /usr/local/bin/redis-server /etc/redis.conf
If and when host1's instance redis dies, host2 will acquire the lock
from zookeeper and startup redis. In a controlled example send host1's
lockex instance with a SIGTERM and it will kill it's child processes.
Requirements:
-------------
* A working installation of zookeeper and python2.7 or higher.
* A durable instance of zookeeper (at least three nodes).
* The hosts are all synchronised with ntp.
Vendored packages:
------------------
* lockex/glog.py - https://github.com/benley/python-glog - Copyright (c) 2015 Benjamin Staffin - under 2 clause BSD license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
lockex-0.3.tar.gz
(9.6 kB
view details)
Built Distribution
lockex-0.3-py2-none-any.whl
(6.7 kB
view details)
File details
Details for the file lockex-0.3.tar.gz
.
File metadata
- Download URL: lockex-0.3.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc71c6fe470ee510ed4063dd7ee54fc9a9a233bdad9096a38d0d02b1a08a7013 |
|
MD5 | ca482be28987332cbe09e6a440ef129d |
|
BLAKE2b-256 | a359fdd1cf3eb3ca5cd3760e4a069f9756a257dca8e7992ca36f77ccf10a6cd1 |
File details
Details for the file lockex-0.3-py2-none-any.whl
.
File metadata
- Download URL: lockex-0.3-py2-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 240c338bd7b4f455784f4746e6b9259d2e1f0ba7e55157f8876100f585a19a68 |
|
MD5 | a0a72b482f1b77a3287b829d6fc20db9 |
|
BLAKE2b-256 | f52d76ed9ba5d3ce7bdd7b642b171b4c3864699110b37c1364127ce5b0af1b6d |