Package: lockpick
LockpickLockpick is an utility for distributed locking using zookeeper. Its intended to be used in distributed environments where scripts need synchronization between runs.Why LockpickLockpick uses the kazoo library but provides following benefits over kazoo recipes :Use non ephemeral zknode to allowexplicitlock releaseExits with correct return codesCorrect signal Handling and cleanupRetires and timeoutUsage$lockpick--help
usage:lockpick[-h][-sSERVERS][-cCHROOT][-iIDENTIFIER][-v][-rRETRY_COUNT][-pRETRY_SLEEP]{lock,rlock,wlock,unlock,list}lock_path

DistributedlockingusingZookeeperprimarilyforscripting.Afteracquiring
thelock,thezknodeisprintedtoSTDOUT.Thiszknodeshouldbepassedto
unlock.Note:alllogsareprintedtoSTDERR

positionalarguments:{lock,rlock,wlock,unlock,list}lock:acquireamutexlock.rlock:acquireareadlockwlock:acquireawritelock.unlock:releaselockidentifiedbyzknode.list:listalllockcontenderslock_pathZKpathtolockORZKnodetounlock.Fortheunlockactionthismustbethechrootedzkpathtothenodee.g.lockpicklock-c/devops/mylocklockpickunlock-c/devops/mylock/9d2badeec7684f35b10f4860db42e45c__rlock__0000000022

optionalarguments:-h,--helpshowthishelpmessageandexit-sSERVERS,--serversSERVERS-cCHROOT,--chrootCHROOTZKchrootforthelockpath-iIDENTIFIER,--identifierIDENTIFIEROptionalstringidentifiertoaddtothelocknodeORverifywhenunlocking-v,--verbose-rRETRY_COUNT,--retry-countRETRY_COUNT-pRETRY_SLEEP,--retry-sleepRETRY_SLEEPInstallWe recommend using pip to install in a virtualenv :$ virtualenv lockpick
$ pip install lockpickExample$lockpick-slocalhost:2181-c/test-i"test lock1"rlock/mylock/mylock/503e61fadc8f492497db823b87e64afe__rlock__0000000038$lockpick-slocalhost:2181-c/test-i"test lock1"rlock/mylock/mylock/e21b0ecd480346aaaba23e77946e16e9__rlock__0000000039$lockpick-slocalhost:2181-c/test-i"test lock1"list/mylock'test lock1' /mylock/e21b0ecd480346aaaba23e77946e16e9__rlock__0000000039'test lock1' /mylock/503e61fadc8f492497db823b87e64afe__rlock__0000000038$lockpick-slocalhost:2181-c/test-i"test lock1"wlock/mylock[2018-07-25 19:09:53,095] WARNING lockpick: Waiting to acquire lock, contenders are :[2018-07-25 19:09:53,103] WARNING lockpick: 'test lock1' /mylock/e21b0ecd480346aaaba23e77946e16e9__rlock__0000000039[2018-07-25 19:09:53,103] WARNING lockpick: 'test lock1' /mylock/503e61fadc8f492497db823b87e64afe__rlock__0000000038[2018-07-25 19:09:53,104] WARNING lockpick: 'test lock1' /mylock/492b4a6c1727417daf511b343d0d11b7__lock__0000000042[2018-07-25 19:09:56,104] WARNING lockpick: Waiting to acquire lock, contenders are :[2018-07-25 19:09:56,114] WARNING lockpick: 'test lock1' /mylock/e21b0ecd480346aaaba23e77946e16e9__rlock__0000000039[2018-07-25 19:09:56,114] WARNING lockpick: 'test lock1' /mylock/503e61fadc8f492497db823b87e64afe__rlock__0000000038[2018-07-25 19:09:56,114] WARNING lockpick: 'test lock1' /mylock/492b4a6c1727417daf511b343d0d11b7__lock__0000000042[2018-07-25 19:09:59,116] WARNING lockpick: LockTimeout exception rasied by locker thread[2018-07-25 19:09:59,117] ERROR lockpick: Failed to acquire lock within timeout!$lockpick-slocalhost:2181-c/test-i"test lock1"unlock/mylock/503e61fadc8f492497db823b87e64afe__rlock__0000000038$lockpick-slocalhost:2181-c/test-i"test lock1"unlock/mylock/e21b0ecd480346aaaba23e77946e16e9__rlock__0000000039$lockpick-slocalhost:2181-c/test-i"test lock1"wlock/mylock/mylock/d6602d4a54124826b27c50a43ab67a5e__lock__0000000043syncd_spawn.shSpawns the given command only if it can acquire the given lock../syncd_spawn -n /test -C 'test' -l rlock sleep 5Got lock on /testRunning your command sleep 5Unlocked '/test/141bcfad04c6459591164ea12d1604af__rlock__0000000011'