|
1 | | -#!/usr/bin/env python |
| 1 | +#!/usr/bin/python2 |
2 | 2 | # -*- coding: utf-8 -*- |
3 | 3 | # |
4 | 4 | # Copyright (c) 2012 Tyurin Anton [email protected] |
@@ -38,7 +38,6 @@ from functools import partial |
38 | 38 | import json |
39 | 39 | import logging |
40 | 40 | import logging.handlers |
41 | | -import os |
42 | 41 | import optparse |
43 | 42 | import shlex |
44 | 43 | import subprocess |
@@ -148,7 +147,7 @@ def notifier(cv): |
148 | 147 |
|
149 | 148 |
|
150 | 149 | # ToDo: accept options as the last argument |
151 | | -def main(cmd_arg, zk_cfg, period=None, exitcode=0, sequence=0, pdeathsig_num=0): |
| 150 | +def main(cmd_arg, zk_cfg, period=3, exitcode=0, sequence=0, pdeathsig_num=0, minlocktime=5): |
152 | 151 | try: |
153 | 152 | z = Zookeeper.ZKLockServer(**cfg) |
154 | 153 | except Exception as err: |
@@ -202,7 +201,8 @@ def main(cmd_arg, zk_cfg, period=None, exitcode=0, sequence=0, pdeathsig_num=0): |
202 | 201 |
|
203 | 202 | cv = Condition() |
204 | 203 |
|
205 | | - def sigterm_and_sigchld_handle(p, signum, frame): |
| 204 | + def sigterm_and_sigchld_handle(p, signum, frame, minlocktime=5): |
| 205 | + os.system("sleep %d" % minlocktime) |
206 | 206 | # TBD - split by two handlers for each signal |
207 | 207 | if signum == signal.SIGTERM: |
208 | 208 | LOGGER.info("Stop work by SIGTERM") |
@@ -260,7 +260,7 @@ def main(cmd_arg, zk_cfg, period=None, exitcode=0, sequence=0, pdeathsig_num=0): |
260 | 260 |
|
261 | 261 |
|
262 | 262 | if __name__ == "__main__": |
263 | | - usage = "Usage: %prog LOCKNAME COMMAND [-cdhs]" |
| 263 | + usage = "Usage: %prog LOCKNAME COMMAND [-cdhsl]" |
264 | 264 | parser = optparse.OptionParser(usage) |
265 | 265 | parser.add_option("-c", "--confpath", action="store", |
266 | 266 | dest="confpath", default="/etc/distributed-flock.json", |
@@ -289,6 +289,10 @@ if __name__ == "__main__": |
289 | 289 | dest="sequence", default=0, |
290 | 290 | help="Sequence of locks") |
291 | 291 |
|
| 292 | + parser.add_option("-l", "--minlocktime", action="store", type=int, |
| 293 | + dest="minlocktime", default=5, |
| 294 | + help="Minimum time for lock") |
| 295 | + |
292 | 296 | if pdeathsig.support_pdeathsig(): |
293 | 297 | parser.add_option("-p", "--pdeathsig", action="store", type=int, |
294 | 298 | dest="pdeathsig", default=signal.SIGTERM, |
@@ -339,7 +343,7 @@ if __name__ == "__main__": |
339 | 343 | daemon = Daemon() |
340 | 344 | daemon.run = main |
341 | 345 | daemon.start(cmd_arg, cfg, options.waittime, |
342 | | - options.exitcode, options.sequence, pdeathsig_num) |
| 346 | + options.exitcode, options.sequence, pdeathsig_num, options.minlocktime) |
343 | 347 | else: |
344 | 348 | main(cmd_arg, cfg, options.waittime, |
345 | | - options.exitcode, options.sequence, pdeathsig_num) |
| 349 | + options.exitcode, options.sequence, pdeathsig_num, options.minlocktime) |
0 commit comments