Ejemplo n.º 1
0
def start_shudder():
    logging.info('Started shudder.')

    uncatchable = ['SIG_DFL', 'SIGSTOP', 'SIGKILL']
    for i in [x for x in dir(signal) if x.startswith("SIG")]:
        if not i in uncatchable:
            signum = getattr(signal, i)
            signal.signal(signum, receive_signal)

    queue_url = queue.create_queue()
    sns_connection, subscription_arn = queue.subscribe_sns(queue_url)
    while True:
        message = queue.poll_queue(queue_url)
        if message or metadata.poll_instance_metadata():
            queue.clean_up_sns(sns_connection, subscription_arn, queue_url)
            if 'endpoint' in CONFIG:
                call_endpoint(CONFIG["endpoint"])
            if 'endpoints' in CONFIG:
                for endpoint in CONFIG["endpoints"]:
                    call_endpoint(endpoint)
            if 'commands' in CONFIG:
                for command in CONFIG["commands"]:
                    run_command(message, command)
            logging.info('Sending a COMPLETE lifecycle action.')
            queue.complete_lifecycle_action(message)
            logging.info('Finished successfully. Exiting now.')
            sys.exit(0)
        logging.info('Waiting for TERMINATION trigger.')
        time.sleep(10)
Ejemplo n.º 2
0
        if message or metadata.poll_instance_metadata():
            queue.clean_up_sns(sns_connection, subscription_arn, sqs_queue)
            if 'endpoint' in CONFIG:
                requests.get(CONFIG["endpoint"])
            if 'endpoints' in CONFIG:
                for endpoint in CONFIG["endpoints"]:
                    requests.get(endpoint)
            if 'commands' in CONFIG:
                for command in CONFIG["commands"]:
                    print 'Running command: %s' % command
                    process = subprocess.Popen(command)
                    while process.poll() is None:
                        time.sleep(30)
                        """Send a heart beat to aws"""
                        try:
                          queue.record_lifecycle_action_heartbeat(message)
                        except:
                          logging.exception('Error sending hearbeat for')
                          logging.info(message)
                        
            """Send a complete lifecycle action"""
            queue.complete_lifecycle_action(message)
            running = False
        time.sleep(5)
      except ConnectionError:
        logging.exception('Connection issue')
      except:
        logging.exception('Something went wrong')
    logging.info('Success')
    sys.exit(0)
Ejemplo n.º 3
0
            signum = getattr(signal,i)
            signal.signal(signum,receive_signal)

    sqs_connection, sqs_queue = queue.create_queue()
    sns_connection, subscription_arn = queue.subscribe_sns(sqs_queue)
    while True:
      try:
        message = queue.poll_queue(sqs_connection, sqs_queue)
        if message or metadata.poll_instance_metadata():
            queue.clean_up_sns(sns_connection, subscription_arn, sqs_queue)
            if 'endpoint' in CONFIG:
                requests.get(CONFIG["endpoint"])
            if 'endpoints' in CONFIG:
                for endpoint in CONFIG["endpoints"]:
                    requests.get(endpoint)
            if 'commands' in CONFIG:
                for command in CONFIG["commands"]:
                    print 'Running command: %s' % command
                    process = subprocess.Popen(command)
                    while process.poll() is None:
                        time.sleep(30)
                        """Send a heart beat to aws"""
                        queue.record_lifecycle_action_heartbeat(message)
            """Send a complete lifecycle action"""
            queue.complete_lifecycle_action(message)
            sys.exit(0)
        time.sleep(5)
      except ConnectionError:
        logging.exception('Connection issue')
      except:
        logging.exception('Something went wrong')