b10-cfgmgr.py.in 1.08 KB
Newer Older
1
2
3
4
#!@PYTHON@

import sys; sys.path.append ('@@PYTHONPATH@@')

Jelte Jansen's avatar
Jelte Jansen committed
5
from isc.config.cfgmgr import ConfigManager
6
from isc.cc import SessionError
7
import signal
8
import os
9

Jelte Jansen's avatar
Jelte Jansen committed
10
11
12
13
14
15
16
17
18
# 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)

19
20
21
22
23
24
25
cm = None

def signal_handler(signal, frame):
    global cm
    if cm:
        cm.running = False

26
27
if __name__ == "__main__":
    try:
Jelte Jansen's avatar
Jelte Jansen committed
28
        cm = ConfigManager(DATA_PATH)
29
30
        signal.signal(signal.SIGINT, signal_handler)
        signal.signal(signal.SIGTERM, signal_handler)
Jelte Jansen's avatar
Jelte Jansen committed
31
        cm.read_config()
32
        cm.notify_boss()
33
        cm.run()
34
    except SessionError as se:
35
        print("[b10-cfgmgr] Error creating config manager, "
Jelte Jansen's avatar
Jelte Jansen committed
36
              "is the command channel daemon running?")
Jelte Jansen's avatar
Jelte Jansen committed
37
    except KeyboardInterrupt as kie:
38
        print("Got ctrl-c, exit")
39
40
    if cm:
        cm.write_config()