From 2fbccc0c693193533284330325f5803c8c6ce52a Mon Sep 17 00:00:00 2001 From: Mike Pittaro Date: Fri, 24 Feb 2012 09:56:26 -0800 Subject: Clean stale lockfiles on service startup : fixes bug 785955 Adds cleanup_files_locks() to nova/utils, which cleans up stale locks left behind after process failures. Adds a call to clean up locks on service startup for nova-api, nova-cert, nova-compute, nova-network, nova-objectstore, and nova-scheduler. Adds tools/clean_file_locks.py, which can be used to manually clean stale locks. Change-Id: I752e0b24d3c7fc5f1dc290da355cbd7f430789b8 --- tools/clean_file_locks.py | 63 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 tools/clean_file_locks.py (limited to 'tools') diff --git a/tools/clean_file_locks.py b/tools/clean_file_locks.py new file mode 100755 index 000000000..eb21177aa --- /dev/null +++ b/tools/clean_file_locks.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python + +# Copyright 2012 La Honda Research Center, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""clean_file_locks.py - Cleans stale interprocess locks + +This rountine can be used to find and delete stale lock files from +nova's interprocess synchroization. It can be used safely while services +are running. + +""" + +import logging +import optparse + +from nova import flags +from nova import utils +from nova import log + + +LOG = log.getLogger('nova.utils') +FLAGS = flags.FLAGS + + +def parse_options(): + """process command line options.""" + + parser = optparse.OptionParser('usage: %prog [options]') + parser.add_option('--verbose', action='store_true', + help='List lock files found and deleted') + + options, args = parser.parse_args() + + return options, args + + +def main(): + """Main loop.""" + options, args = parse_options() + verbose = options.verbose + + if verbose: + LOG.logger.setLevel(logging.DEBUG) + else: + LOG.logger.setLevel(logging.INFO) + LOG.info('Cleaning stale locks from %s' % FLAGS.lock_path) + utils.cleanup_file_locks() + LOG.info('Finished') + +if __name__ == '__main__': + main() -- cgit