1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #!@PYTHON@
- # Copyright (C) 2010 Internet Systems Consortium.
- #
- # Permission to use, copy, modify, and distribute this software for any
- # purpose with or without fee is hereby granted, provided that the above
- # copyright notice and this permission notice appear in all copies.
- #
- # THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
- # DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
- # INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
- # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
- # FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
- # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
- # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- import sys; sys.path.append ('@@PYTHONPATH@@')
- from isc.config.cfgmgr import ConfigManager, ConfigManagerDataReadError
- from isc.cc import SessionError
- import isc.util.process
- import signal
- import os
- from optparse import OptionParser
- isc.util.process.rename()
- # If B10_FROM_SOURCE is set in the environment, we use data files
- # from a directory relative to that, otherwise we use the ones
- # installed on the system
- if "B10_FROM_SOURCE" in os.environ:
- DATA_PATH = os.environ["B10_FROM_SOURCE"]
- else:
- PREFIX = "@prefix@"
- DATA_PATH = "@localstatedir@/@PACKAGE@".replace("${prefix}", PREFIX)
- cm = None
- def parse_options(args=sys.argv[1:], Parser=OptionParser):
- parser = Parser()
- parser.add_option("-p", "--data-path", dest="data_path",
- help="Directory to search for configuration files " +
- "(default="+DATA_PATH+")", default=DATA_PATH)
- parser.add_option("-c", "--config-filename", dest="file_name",
- help="Configuration database filename " +
- "(default=b10-config.db)", default="b10-config.db")
- (options, args) = parser.parse_args(args)
- if args:
- parser.error("No non-option arguments allowed")
- return options
- def signal_handler(signal, frame):
- global cm
- if cm:
- cm.running = False
- def main():
- options = parse_options()
- global cm
- try:
- cm = ConfigManager(options.data_path, options.file_name)
- signal.signal(signal.SIGINT, signal_handler)
- signal.signal(signal.SIGTERM, signal_handler)
- cm.read_config()
- cm.notify_boss()
- cm.run()
- except SessionError as se:
- print("[b10-cfgmgr] Error creating config manager, "
- "is the command channel daemon running?")
- return 1
- except KeyboardInterrupt as kie:
- print("[b10-cfgmgr] Interrupted, exiting")
- except ConfigManagerDataReadError as cmdre:
- print("[b10-cfgmgr] " + str(cmdre))
- return 2
- return 0
- if __name__ == "__main__":
- sys.exit(main())
|