-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnebula.py
executable file
·100 lines (82 loc) · 2.57 KB
/
nebula.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# This file is part of Nebula media asset management.
#
# Nebula 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.
#
# Nebula 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
#
from __future__ import print_function
import os
import sys
##
# Env setup
##
if sys.version_info[:2] < (3, 0):
reload(sys)
sys.setdefaultencoding('utf-8')
nebula_root = os.path.abspath(os.getcwd())
##
# Vendor imports
##
vendor_dir = os.path.join(nebula_root, "vendor")
if os.path.exists(vendor_dir):
for pname in os.listdir(vendor_dir):
pname = os.path.join(vendor_dir, pname)
pname = os.path.abspath(pname)
if not pname in sys.path:
sys.path.insert(0, pname)
from nx import *
config["nebula_root"] = nebula_root
##
# Start agents only if this script is executed (not imported)
##
if __name__ == "__main__":
from nx.storage_monitor import StorageMonitor
from nx.service_monitor import ServiceMonitor
from nx.system_monitor import SystemMonitor
def are_running(agents):
for agent in agents:
if agent.is_running:
break
else:
return False
return True
def shutdown(agents):
logging.info("Shutting down agents")
for agent in agents:
agent.shutdown()
while are_running(agents):
time.sleep(.5)
agents = []
for Agent in [StorageMonitor, ServiceMonitor, SystemMonitor]:
try:
agents.append(Agent())
except:
log_traceback()
shutdown(agents)
critical_error("Unable to start {}".format(Agent.__name__))
while True:
try:
time.sleep(1)
except KeyboardInterrupt:
break
print()
try:
logging.warning("Shutting down nebula. Please wait...")
shutdown(agents)
logging.goodnews("Exiting gracefully")
sys.exit(0)
except KeyboardInterrupt:
logging.warning("Immediate shutdown enforced. This may cause problems")
sys.exit(1)