Scale down Kubernetes deployments after work hours
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

23 lines
535 B

import contextlib
import signal
import sys
class GracefulShutdown:
shutdown_now = False
safe_to_exit = False
def __init__(self):
signal.signal(signal.SIGINT, self.exit_gracefully)
signal.signal(signal.SIGTERM, self.exit_gracefully)
def exit_gracefully(self, signum, frame):
self.shutdown_now = True
if self.safe_to_exit:
sys.exit(0)
@contextlib.contextmanager
def safe_exit(self):
self.safe_to_exit = True
yield
self.safe_to_exit = False