forked from maartendamen/HouseAgent
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHouseAgent.py
77 lines (62 loc) · 2.69 KB
/
HouseAgent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import os
from houseagent.utils.config import Config
from houseagent import config_file
from houseagent.core.coordinator import Coordinator
from houseagent.core.events import EventHandler
from houseagent.core.history import HistoryCollector, HistoryAggregator
from houseagent.core.web import Web
from houseagent.core.database import Database
from houseagent.core.databaseflash import DatabaseFlash
from twisted.internet import reactor
from houseagent.plugins import pluginapi
class MainWrapper():
'''
This is the main wrapper for HouseAgent, this class takes care of starting all important
core components for HouseAgent such as the event engine, network coordinator etc.
'''
def start(self):
self.log = pluginapi.Logging("Main")
self.log.debug("Starting HouseAgent database layer...")
if config.embedded.enabled:
database = DatabaseFlash(self.log, config.general.dbfile, config.embedded.db_save_interval)
else:
database = Database(self.log, config.general.dbfile)
self.log.debug("Starting HouseAgent coordinator...")
coordinator = Coordinator(self.log, database)
coordinator.init_broker(config.zmq.broker_host, config.zmq.broker_port)
self.log.debug("Starting HouseAgent event handler...")
event_handler = EventHandler(coordinator, database)
self.log.debug("Starting Houseagent history aggregator")
histagg = HistoryAggregator(database)
self.log.debug("Starting Houseagent history collector")
HistoryCollector(database, histagg)
self.log.debug("Starting HouseAgent web server...")
Web(self.log, config.webserver.host, config.webserver.port,\
config.webserver.backlog, coordinator, event_handler, database)
if os.name == 'nt':
reactor.run(installSignalHandlers=0)
else:
reactor.run()
return True
if os.name == "nt":
class MainService(pluginapi.WindowsService):
'''
This is the main service definition for HouseAgent.
It takes care of running HouseAgent as Windows Service.
'''
_svc_name_ = "hamain"
_svc_display_name_ = "HouseAgent - Main Service"
def start(self):
main = MainWrapper()
main.start()
if __name__ == '__main__':
config = Config(config_file)
if os.name == "nt":
if config.general.runasservice:
pluginapi.handle_windowsservice(MainService) # We want to start as a Windows service on Windows.
else:
main = MainWrapper()
main.start()
else:
main = MainWrapper()
main.start()