#!/usr/bin/env python3
# Copyright (c) 2006-2010 Arastra, Inc.  All rights reserved.
# Arastra, Inc. Confidential and Proprietary.

import faulthandler
import signal
import sys
import NorCalInit # pylint: disable=import-self

faulthandler.enable()

# If SystemD service times out a SIGTERM is sent to the entire process tree. 
# We can can catch it and print out a traceback before exiting.
def handleSigTerm( signum, frame ):
   faulthandler.dump_traceback( sys.stdout )
   sys.exit( 1 )

signal.signal( signal.SIGTERM, handleSigTerm )


ret = NorCalInit.main() # pylint: disable=c-extension-no-member
# BUG167297: If successful, make sure sysdb is started after NorCalInit.
if ret == 0:
   NorCalInit.killallSysdb() # pylint: disable=c-extension-no-member
sys.exit( ret )
