def main():
parser = argparse.ArgumentParser()
parser.add_argument("--private", action="store_true", help="Only accept local connections.")
parser.add_argument("--port", type=int, default=0, help="listening port for switch")
parser.add_argument("--statusfile", help="file to record status; useful for communications")
parser.add_argument("--pidfile", help="file to record pid; useful for communciations")
parser.add_argument("--unreliable", action="store_true", default=False, help="Introduce errors on the wire")
parser.add_argument("--no-daemon", action="store_true", default=False, help="do not launch switch in a daemon; remain in foreground")
args = parser.parse_args()
pidFileName = os.path.expanduser(os.path.expandvars(args.pidfile))
statusFileName = os.path.expanduser(os.path.expandvars(args.statusfile))
pidFileDir = os.path.dirname(pidFileName)
host = None
if args.private: host = "127.0.0.1"
if args.no_daemon:
runSwitch(args.unreliable, host, args.port, statusFileName)
else:
with daemon.DaemonContext(
working_directory=pidFileDir,
umask=0o002,
pidfile=pidfile.TimeoutPIDLockFile(pidFileName),
) as context:
runSwitch(args.unreliable, host, args.port, statusFileName)
评论列表
文章目录