X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=python%2Fovs%2Fdaemon.py;h=864a1633dc08ed2fdd7b26035a3a5ded8aca4d67;hb=b153e667907ed68164a15207ad5f91ad4c39927c;hp=184e7832fc264f8d0bf52dd2df8d56d7c5695a2b;hpb=2a8859b0a4fe11c6418fe07dbb9b1c403a3986b4;p=sliver-openvswitch.git diff --git a/python/ovs/daemon.py b/python/ovs/daemon.py index 184e7832f..864a1633d 100644 --- a/python/ovs/daemon.py +++ b/python/ovs/daemon.py @@ -487,26 +487,43 @@ def _check_already_running(): _fatal("%s: pidfile check failed (%s), aborting" % (_pidfile, os.strerror(pid))) -# XXX Python's getopt does not support options with optional arguments, so we -# have to separate --pidfile (with no argument) from --pidfile-name (with an -# argument). Need to write our own getopt I guess. -LONG_OPTIONS = ["detach", "no-chdir", "pidfile", "pidfile-name=", - "overwrite-pidfile", "monitor"] +def add_args(parser): + """Populates 'parser', an ArgumentParser allocated using the argparse + module, with the command line arguments required by the daemon module.""" -def parse_opt(option, arg): - if option == '--detach': + pidfile = make_pidfile_name(None) + + group = parser.add_argument_group(title="Daemon Options") + group.add_argument("--detach", action="store_true", + help="Run in background as a daemon.") + group.add_argument("--no-chdir", action="store_true", + help="Do not chdir to '/'.") + group.add_argument("--monitor", action="store_true", + help="Monitor %s process." % ovs.util.PROGRAM_NAME) + group.add_argument("--pidfile", nargs="?", default=pidfile, + help="Create pidfile (default %s)." % pidfile) + group.add_argument("--overwrite-pidfile", action="store_true", + help="With --pidfile, start even if already running.") + + +def handle_args(args): + """Handles daemon module settings in 'args'. 'args' is an object + containing values parsed by the parse_args() method of ArgumentParser. The + parent ArgumentParser should have been prepared by add_args() before + calling parse_args().""" + + if args.detach: set_detach() - elif option == '--no-chdir': + + if args.no_chdir: set_no_chdir() - elif option == '--pidfile': - set_pidfile(None) - elif option == '--pidfile-name': - set_pidfile(arg) - elif option == '--overwrite-pidfile': + + if args.pidfile: + set_pidfile(args.pidfile) + + if args.overwrite_pidfile: ignore_existing_pidfile() - elif option == '--monitor': + + if args.monitor: set_monitor() - else: - return False - return True