createDirectoriesRecursively(scriptGlobals.workingDir) log.info("Working directory '" + scriptGlobals.workingDir + "'") # Start per-execution logger log.addHandler(createCustomLogger(scriptGlobals.workingDir + scriptGlobals.osDirSeparator + guid + ".log", scriptGlobals.customLoggingFormat, logging.DEBUG)) # Get Module Properties file isRequiredFileEmpty(parser.options.module) moduleProperties = extractFileFromZipToDir(parser.options.module, scriptGlobals.modulePropertiesFile, scriptGlobals.workingDir) log.info("Module properties file '" + moduleProperties + "'") # Initialize module to be deployed module = Module(parser.options.module, moduleProperties, parser.options.envprops) # Initialize Pre-Execution Logic prelogic = initClassFromStringWithModule(module.preExecutionLogicClass, module) # Initialize & Execute ActionBundles for actionbundleClass in module.actionBundleGroupClasses[parser.options.action]: ab = initClassFromStringWithModule(actionbundleClass, module) # Initialize Post-Execution Logic postlogic = initClassFromStringWithModule(module.postExecutionLogicClass, module) # import code; code.interact(local=locals()) except (Exception, KeyboardInterrupt): # Actions for rollback exist and this is not Rollback mode? if (len(scriptGlobals.executedActionList) > 0) and (not type(sys.exc_info()[1]) == RollbackTriggerException): log.error(str(sys.exc_info()[0]) + " " + str(sys.exc_info()[1])) answer = getAnswerFromUser(str(sys.exc_info()[0]) + " detected. \n\nSelect your action:\n\n(R) Rollback all actions performed so far \n(<any other key>) Show Exception & Quit")
def __init__(self, module): ''' Constructor ''' guid = generateGUID() log.info("Unique ActionBundle execution ID generated: " + guid) appServer = ApplicationServer(module, scriptGlobals.appsrvProperties) # Construct the email notification emailSender = readPropertyFromPropertiesFileWithFallback("emailNotificationSenderAddress", scriptGlobals.scriptVarSectionName, lib.OptParser.options.envprops, scriptGlobals.emailNotificationSenderAddress) emailRecipients = module.emailNotificationRecipientList emailSubject = "Server RESTART Notification: " + module.name + "@"+ getCurrentHostname()+ " (" + module.friendlyServerName + ")" + " server will restart in " + scriptGlobals.httpServerExecutionTime + " seconds." killOperationURL = "http://" + getCurrentHostname() + ":" + str(scriptGlobals.httpServerPort) + "/stopDelayedRestart.foo" emailText = restartPendingNotificationTemplate(module.name, getCurrentHostname(), killOperationURL, guid) # Email all required parties SendEmail(emailSender, emailRecipients, emailSubject, emailText, scriptGlobals.smtpHost, scriptGlobals.smtpPort) # Start timer that will hit the timeout URL when the time ends timeoutURL = "http://" + getCurrentHostname() + ":" + str(scriptGlobals.httpServerPort) + "/timeOut.foo" timer = Timer(int(scriptGlobals.httpServerExecutionTime), timeoutURL) timer.start() # Expose cancellation URL server = launchHTTPServer(int(scriptGlobals.httpServerPort), FireworksHTTPRequestHandler) if server.result == 0: log.info("Grace period timed-out, proceeding to restart the server...") # Initialize Stop Action Bundle ab = initClassFromStringWithModule(module.moduleStopAB, module) log.info("Sleeping for 20 seconds to allow proper server stop...") time.sleep(20) # Initialize Kill Action Bundle (just in case :-)) ab = initClassFromStringWithModule(module.moduleKillAB, module) time.sleep(5) # Initialize Start Action Bundle ab = initClassFromStringWithModule(module.moduleStartAB, module) elif server.result == 1: log.info("Cancelled by external client.") timer.stop() # Construct the email notification emailSender = readPropertyFromPropertiesFileWithFallback("emailNotificationSenderAddress", scriptGlobals.scriptVarSectionName, lib.OptParser.options.envprops, scriptGlobals.emailNotificationSenderAddress) emailRecipients = module.emailNotificationRecipientList emailSubject = "Server RESTART Cancelled: " + module.name + "@"+ getCurrentHostname()+ " (" + module.friendlyServerName + ")" + " server restart was cancelled" killOperationURL = "http://" + getCurrentHostname() + ":" + str(scriptGlobals.httpServerPort) + "/stopDelayedRestart.foo" emailText = restartCancellationNotificationTemplate(module.name, getCurrentHostname(), guid) # Email all required parties SendEmail(emailSender, emailRecipients, emailSubject, emailText, scriptGlobals.smtpHost, scriptGlobals.smtpPort)