2016-12-30 02:51:56 -05:00
|
|
|
#! /bin/python
|
|
|
|
|
2017-05-23 01:44:47 -04:00
|
|
|
import os, time, signal, traceback
|
2016-12-30 02:51:56 -05:00
|
|
|
import RPi.GPIO as GPIO
|
|
|
|
|
2017-05-22 02:32:19 -04:00
|
|
|
from auxilary import fallbackLogger
|
2017-05-29 21:15:38 -04:00
|
|
|
from sharedLogging import MasterLogger
|
|
|
|
|
|
|
|
logger = MasterLogger(__name__, 'DEBUG')
|
2017-05-22 02:32:19 -04:00
|
|
|
|
|
|
|
def printTrace(t):
|
2017-05-23 01:50:01 -04:00
|
|
|
fallbackLogger(__name__, 'CRITICAL', '\n' + t)
|
2017-05-22 02:32:19 -04:00
|
|
|
|
2016-12-30 02:51:56 -05:00
|
|
|
def clean():
|
|
|
|
GPIO.cleanup()
|
|
|
|
|
|
|
|
try:
|
|
|
|
stateMachine.__del__()
|
|
|
|
except NameError:
|
|
|
|
pass
|
2017-05-22 02:32:19 -04:00
|
|
|
|
2016-12-30 02:51:56 -05:00
|
|
|
try:
|
|
|
|
logger.info('Terminated root process - PID: %s', os.getpid())
|
2017-05-29 21:15:38 -04:00
|
|
|
logger.unmountGluster()
|
2016-12-30 02:51:56 -05:00
|
|
|
except NameError:
|
|
|
|
pass
|
2017-05-22 02:32:19 -04:00
|
|
|
except Exception:
|
|
|
|
printTrace(traceback.format_exc())
|
2016-12-30 02:51:56 -05:00
|
|
|
|
|
|
|
def sigtermHandler(signum, stackFrame):
|
|
|
|
logger.info('Caught SIGTERM')
|
2017-05-23 01:43:39 -04:00
|
|
|
raise SystemExit
|
2016-12-30 02:51:56 -05:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
try:
|
|
|
|
os.chdir(os.path.dirname(os.path.realpath(__file__)))
|
|
|
|
|
|
|
|
GPIO.setwarnings(False)
|
|
|
|
GPIO.setmode(GPIO.BCM)
|
2017-05-22 02:32:19 -04:00
|
|
|
|
2017-05-29 21:15:38 -04:00
|
|
|
logger.mountGluster()
|
|
|
|
|
2016-12-30 02:51:56 -05:00
|
|
|
from notifier import criticalError
|
|
|
|
|
2017-05-21 14:29:17 -04:00
|
|
|
from stateMachine import StateMachine
|
|
|
|
stateMachine = StateMachine()
|
2017-05-22 02:32:19 -04:00
|
|
|
|
2017-05-21 14:29:17 -04:00
|
|
|
# TODO: segfaults are annoying :(
|
|
|
|
#~ signal.signal(signal.SIGSEGV, sig_handler)
|
2016-12-30 02:51:56 -05:00
|
|
|
signal.signal(signal.SIGTERM, sigtermHandler)
|
|
|
|
|
|
|
|
while 1:
|
|
|
|
time.sleep(31536000)
|
|
|
|
|
|
|
|
except Exception:
|
2017-05-22 02:32:19 -04:00
|
|
|
t = traceback.format_exc()
|
2016-12-30 02:51:56 -05:00
|
|
|
|
|
|
|
try:
|
|
|
|
criticalError(t)
|
|
|
|
except NameError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
try:
|
|
|
|
logger.critical(t)
|
|
|
|
except NameError:
|
2017-05-22 02:32:19 -04:00
|
|
|
printTrace(t)
|
|
|
|
|
|
|
|
finally:
|
2016-12-30 02:51:56 -05:00
|
|
|
clean()
|