pyledriver/main.py

49 lines
981 B
Python
Raw Normal View History

2016-12-30 02:51:56 -05:00
#! /bin/python
import os, time, signal, traceback, logging
2016-12-30 02:51:56 -05:00
import RPi.GPIO as GPIO
2017-05-30 01:01:30 -04:00
from sharedLogging import unmountGluster # this should be first program module
from stateMachine import StateMachine
from exceptionThreading import excChildListener, excStopper
2017-05-29 21:15:38 -04:00
logger = logging.getLogger(__name__)
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())
unmountGluster()
2017-05-22 02:32:19 -04:00
except Exception:
logger.critical(traceback.format_exc())
2016-12-30 02:51:56 -05:00
def sigtermHandler(signum, stackFrame):
excStopper.set()
2016-12-30 02:51:56 -05:00
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)
stateMachine = StateMachine()
2017-05-22 02:32:19 -04:00
2016-12-30 02:51:56 -05:00
signal.signal(signal.SIGTERM, sigtermHandler)
excChildListener()
2016-12-30 02:51:56 -05:00
except Exception:
logger.critical(traceback.format_exc())
2017-05-22 02:32:19 -04:00
finally:
2016-12-30 02:51:56 -05:00
clean()