f72704fc82
Change-Id: I7c3df47c31759dbeb3105f8883e2688ada848d58 Closes-bug: #1214176
83 lines
3.1 KiB
Python
Executable File
83 lines
3.1 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# Copyright (c) 2010-2012 OpenStack Foundation
|
|
#
|
|
# 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 Manager, UnknownCommandError, \
|
|
KILL_WAIT, RUN_DIR
|
|
|
|
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)")
|
|
parser.add_option('-r', '--run-dir', type="str",
|
|
dest="run_dir", default=RUN_DIR,
|
|
help="alternative directory to store running pid files "
|
|
"default: %s" % RUN_DIR)
|
|
|
|
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, run_dir=options.run_dir)
|
|
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())
|