-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_sensor_services.py
More file actions
167 lines (142 loc) · 6.62 KB
/
start_sensor_services.py
File metadata and controls
167 lines (142 loc) · 6.62 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
"""
KootNet Sensors is a collection of programs and scripts to deploy,
interact with, and collect readings from various Sensors.
Copyright (C) 2018 Chad Ermacora chad.ermacora@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
from datetime import datetime
program_initialization_start_time = datetime.utcnow()
from time import sleep
from operations_modules import logger
from operations_modules.initialization_checks import run_program_start_checks
# Ensure files, database & configurations are OK
run_program_start_checks()
from operations_modules.app_cached_variables import running_with_root, running_as_service
try:
from sensor_modules import sensor_access
except Exception as import_error_raw:
import_error_msg = str(import_error_raw)
log_message = "-- Failed to Start Kootnet Sensors - Problem Loading Sensor Access: "
logger.primary_logger.critical(log_message + import_error_msg)
while True:
sleep(3600)
from operations_modules.app_cached_variables_update import start_cached_variables_refresh
from sensor_recording_modules.recording_interval import start_interval_recording_server
from sensor_recording_modules.recording_high_low_triggers import start_trigger_high_low_recording_server
from sensor_recording_modules.recording_triggers import start_trigger_variance_recording_server
from operations_modules.software_checkin import start_sensor_checkins
from operations_modules.software_automatic_upgrades import start_automatic_upgrades_server
from operations_modules.server_hardware_interactive import start_hardware_interactive_server
from operations_modules.server_display import start_display_server
from operations_modules.email_server import start_report_email_server
from operations_modules.email_server import start_graph_email_server
from mqtt.server_mqtt_publisher import start_mqtt_publisher_server
from mqtt.server_mqtt_subscriber import start_mqtt_subscriber_server
from online_services_modules.luftdaten import start_luftdaten_server
from online_services_modules.weather_underground import start_weather_underground_server
from online_services_modules.open_sense_map import start_open_sense_map_server
from mqtt.server_mqtt_broker import start_mqtt_broker_server
from http_server.server_http import start_https_server
logger.primary_logger.debug(" -- Starting Kootnet Sensor Threads")
try:
# Start HTTPS Web Portal Server
start_https_server()
except Exception as error:
logger.primary_logger.critical("-- HTTPS Web Portal Server Error: " + str(error))
try:
# Start Interval SQL Recording
start_interval_recording_server()
except Exception as error:
logger.primary_logger.critical("-- Interval SQL Recording Server Error: " + str(error))
try:
# Start High/Low Trigger SQL Recording
start_trigger_high_low_recording_server()
except Exception as error:
logger.primary_logger.critical("-- High/Low Trigger SQL Recording Server Error: " + str(error))
try:
# Start Variance Trigger SQL Recording
start_trigger_variance_recording_server()
except Exception as error:
logger.primary_logger.critical("-- Variance Trigger SQL Recording Server Error: " + str(error))
try:
# Start Hardware Interactions Server
start_hardware_interactive_server()
except Exception as error:
logger.primary_logger.critical("-- Hardware Interactions Server Error: " + str(error))
try:
# Start Display Server
start_display_server()
except Exception as error:
logger.primary_logger.critical("-- Display Server Error: " + str(error))
try:
# Start the "Call Home" Check-in server.
start_sensor_checkins()
except Exception as error:
logger.primary_logger.critical("-- Checkins (Sending) Server Error: " + str(error))
try:
# Start Automatic Upgrades Server
if running_as_service and running_with_root:
start_automatic_upgrades_server()
else:
log_msg = "Kootnet Sensors must be running as a service with root privileges"
logger.primary_logger.info(" -- Automatic Upgrades Server Disabled - " + log_msg)
except Exception as error:
logger.primary_logger.critical("-- Automatic Upgrades Server Error: " + str(error))
try:
# Start Reports Email Server
start_report_email_server()
except Exception as error:
logger.primary_logger.critical("-- Reports Email Server Error: " + str(error))
try:
# Start Graph Email Server
start_graph_email_server()
except Exception as error:
logger.primary_logger.critical("-- Graph Email Server Error: " + str(error))
try:
# Start MQTT Broker Server
start_mqtt_broker_server()
except Exception as error:
logger.primary_logger.critical("-- MQTT Broker Server Error: " + str(error))
try:
# Start MQTT Publisher Server
start_mqtt_publisher_server()
except Exception as error:
logger.primary_logger.critical("-- MQTT Publisher Server Error: " + str(error))
try:
# Start MQTT Subscriber Server
start_mqtt_subscriber_server()
except Exception as error:
logger.primary_logger.critical("-- MQTT Subscriber Server Error: " + str(error))
try:
# Start Luftdaten Online Service Server
start_luftdaten_server()
except Exception as error:
logger.primary_logger.critical("-- Luftdaten Server Error: " + str(error))
try:
# Start Weather Underground Online Service Server
start_weather_underground_server()
except Exception as error:
logger.primary_logger.critical("-- Weather Underground Server Error: " + str(error))
try:
# Start Open Sense Map Online Service Server
start_open_sense_map_server()
except Exception as error:
logger.primary_logger.critical("-- Open Sense Map Server Error: " + str(error))
try:
# Updates cached variables that may change like IP and hostname every hour
start_cached_variables_refresh()
except Exception as error:
logger.primary_logger.critical("-- Cached Variables Update Server Error: " + str(error))
init_time_seconds = round((datetime.utcnow() - program_initialization_start_time).total_seconds(), 3)
logger.primary_logger.debug(" -- Thread Initializations Complete: " + str(init_time_seconds) + " Seconds")
while True:
sleep(3600)