4fcbeff22f
You can now give swift-init a -k N (or --kill-wait N) option to override the default 15 second wait for a process to die after sending it the die signal. This is useful for boxes that are awfully slow for whatever reason. DocImpact Change-Id: I328ec254f6e0ee1cd423c1d062ba4c5331bd8337
78 lines
2.8 KiB
Python
Executable File
78 lines
2.8 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# Copyright (c) 2010-2012 OpenStack, LLC.
|
|
#
|
|
# 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.
|
|
|
|
import sys
|
|
from optparse import OptionParser
|
|
|
|
from swift.common.manager import Server, Manager, UnknownCommandError, \
|
|
KILL_WAIT
|
|
|
|
USAGE = """%prog <server> [<server> ...] <command> [options]
|
|
|
|
Commands:
|
|
""" + '\n'.join(["%16s: %s" % x for x in Manager.list_commands()])
|
|
|
|
|
|
def main():
|
|
parser = OptionParser(USAGE)
|
|
parser.add_option('-v', '--verbose', action="store_true",
|
|
default=False, help="display verbose output")
|
|
parser.add_option('-w', '--no-wait', action="store_false", dest="wait",
|
|
default=True, help="won't wait for server to start "
|
|
"before returning")
|
|
parser.add_option('-o', '--once', action="store_true",
|
|
default=False, help="only run one pass of daemon")
|
|
# this is a negative option, default is options.daemon = True
|
|
parser.add_option('-n', '--no-daemon', action="store_false", dest="daemon",
|
|
default=True, help="start server interactively")
|
|
parser.add_option('-g', '--graceful', action="store_true",
|
|
default=False, help="send SIGHUP to supporting servers")
|
|
parser.add_option('-c', '--config-num', metavar="N", type="int",
|
|
dest="number", default=0,
|
|
help="send command to the Nth server only")
|
|
parser.add_option('-k', '--kill-wait', metavar="N", type="int",
|
|
dest="kill_wait", default=KILL_WAIT,
|
|
help="wait N seconds for processes to die (default 15)")
|
|
options, args = parser.parse_args()
|
|
|
|
if len(args) < 2:
|
|
parser.print_help()
|
|
print 'ERROR: specify server(s) and command'
|
|
return 1
|
|
|
|
command = args[-1]
|
|
servers = args[:-1]
|
|
|
|
# this is just a silly swap for me cause I always try to "start main"
|
|
commands = dict(Manager.list_commands()).keys()
|
|
if command not in commands and servers[0] in commands:
|
|
servers.append(command)
|
|
command = servers.pop(0)
|
|
|
|
manager = Manager(servers)
|
|
try:
|
|
status = manager.run_command(command, **options.__dict__)
|
|
except UnknownCommandError:
|
|
parser.print_help()
|
|
print 'ERROR: unknown command, %s' % command
|
|
status = 1
|
|
|
|
return 1 if status else 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|