parser.add_argument('-b', '--bypass-scheduler', action='store_true', help='Bypass scheduler and sync/vote immediately', dest='bypass') args = parser.parse_args() return args if __name__ == '__main__': atexit.register(cleanup) signal.signal(signal.SIGINT, signal_handler) # ensure another instance of Sentinel is not currently running mutex_key = 'SENTINEL_RUNNING' # assume that all processes expire after 'timeout_seconds' seconds timeout_seconds = 90 is_running = Transient.get(mutex_key) if is_running: printdbg("An instance of Sentinel is already running -- aborting.") sys.exit(1) else: Transient.set(mutex_key, misc.now(), timeout_seconds) # locked to this instance -- perform main logic here main() Transient.delete(mutex_key)
def signal_handler(signum, frame): print("Got a signal [%d], cleaning up..." % (signum)) Transient.delete('SENTINEL_RUNNING') sys.exit(1)
def cleanup(): Transient.delete(mutex_key)
def clear_schedule(self): Transient.delete(self.transient_key_scheduled)