b10-cfgmgr.py.in 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!@PYTHON@
  2. # Copyright (C) 2010 Internet Systems Consortium.
  3. #
  4. # Permission to use, copy, modify, and distribute this software for any
  5. # purpose with or without fee is hereby granted, provided that the above
  6. # copyright notice and this permission notice appear in all copies.
  7. #
  8. # THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
  9. # DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
  10. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
  11. # INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
  12. # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
  13. # FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  14. # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  15. # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. # $Id$
  17. import sys; sys.path.append ('@@PYTHONPATH@@')
  18. from isc.config.cfgmgr import ConfigManager, ConfigManagerDataReadError
  19. from isc.cc import SessionError
  20. import signal
  21. import os
  22. # If B10_FROM_SOURCE is set in the environment, we use data files
  23. # from a directory relative to that, otherwise we use the ones
  24. # installed on the system
  25. if "B10_FROM_SOURCE" in os.environ:
  26. DATA_PATH = os.environ["B10_FROM_SOURCE"]
  27. else:
  28. PREFIX = "@prefix@"
  29. DATA_PATH = "@localstatedir@/@PACKAGE@".replace("${prefix}", PREFIX)
  30. cm = None
  31. def signal_handler(signal, frame):
  32. global cm
  33. if cm:
  34. cm.running = False
  35. def main():
  36. global cm
  37. try:
  38. cm = ConfigManager(DATA_PATH)
  39. signal.signal(signal.SIGINT, signal_handler)
  40. signal.signal(signal.SIGTERM, signal_handler)
  41. cm.read_config()
  42. cm.notify_boss()
  43. cm.run()
  44. except SessionError as se:
  45. print("[b10-cfgmgr] Error creating config manager, "
  46. "is the command channel daemon running?")
  47. return 1
  48. except KeyboardInterrupt as kie:
  49. print("[b10-cfgmgr] Interrupted, exiting")
  50. except ConfigManagerDataReadError as cmdre:
  51. print("[b10-cfgmgr] " + str(cmdre))
  52. return 2
  53. if cm:
  54. return cm.write_config()
  55. return 0
  56. if __name__ == "__main__":
  57. sys.exit(main())