summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorThiago da Silva <thiagodasilva@gmail.com>2018-08-15 21:05:24 +0000
committerTim Burke <tim@swiftstack.com>2018-08-15 21:51:14 +0000
commita7c5ca08066d457695c906bd6348b96a54636b86 (patch)
tree8fedf6bc9df2714395c1dd6762103391320bb0cf /bin
parent75bfc79d2d960d5516db10fb4bb809a1f7c3443f (diff)
downloadswift-a7c5ca08066d457695c906bd6348b96a54636b86.tar.gz
Fix locking in swift-recon-cron
The previous locking method would leave the lock dir lying around if the process died unexpectedly, preventing others swift-recon-cron process from running sucessfuly and requiring a manual clean. Change-Id: Icb328b2766057a2a4d126f63e2d6dfa5163dd223
Diffstat (limited to 'bin')
-rwxr-xr-xbin/swift-recon-cron26
1 files changed, 10 insertions, 16 deletions
diff --git a/bin/swift-recon-cron b/bin/swift-recon-cron
index 709bd9d5e..d750ba4b2 100755
--- a/bin/swift-recon-cron
+++ b/bin/swift-recon-cron
@@ -19,9 +19,10 @@ swift-recon-cron.py
import os
import sys
-from gettext import gettext as _
+from eventlet import Timeout
-from swift.common.utils import get_logger, dump_recon_cache, readconf
+from swift.common.utils import get_logger, dump_recon_cache, readconf, \
+ lock_path
from swift.obj.diskfile import ASYNCDIR_BASE
@@ -62,21 +63,14 @@ def main():
conf['log_name'] = conf.get('log_name', 'recon-cron')
logger = get_logger(conf, log_route='recon-cron')
try:
- os.mkdir(lock_dir)
- except OSError as e:
- logger.critical(str(e))
- print(str(e))
+ with lock_path(lock_dir):
+ asyncs = get_async_count(device_dir, logger)
+ dump_recon_cache({'async_pending': asyncs}, cache_file, logger)
+ except (Exception, Timeout) as err:
+ msg = 'Exception during recon-cron while accessing devices'
+ logger.exception(msg)
+ print('%s: %s' % (msg, err))
sys.exit(1)
- try:
- asyncs = get_async_count(device_dir, logger)
- dump_recon_cache({'async_pending': asyncs}, cache_file, logger)
- except Exception:
- logger.exception(
- _('Exception during recon-cron while accessing devices'))
- try:
- os.rmdir(lock_dir)
- except Exception:
- logger.exception(_('Exception remove cronjob lock'))
if __name__ == '__main__':
main()