def __init__(self, module):
        '''
        Constructor
        '''
        guid = generateGUID()


        log.info("Unique ActionBundle execution ID generated: " + guid)

        pid = getProcessPIDByPathAndIdentifier(module.targetDeploymentPath, module.subModule.processIdentifier)

        # If process exists...
        if pid:

            # Kill process using pid
            killProcess(pid)

            # Construct the email notification
            emailSender = readPropertyFromPropertiesFileWithFallback("emailNotificationSenderAddress", scriptGlobals.scriptVarSectionName, lib.OptParser.options.envprops, scriptGlobals.emailNotificationSenderAddress)
            emailRecipients = module.emailNotificationRecipientList
            emailSubject = "Server KILL: " + module.subModule.name + "@"+ getCurrentHostname() + " (" + module.friendlyServerName + ")"
            emailText = killApplicationServerNotificationTemplate(module.name, getCurrentHostname(), guid)


            # Email all required parties
            SendEmail(emailSender,
                      emailRecipients,
                      emailSubject,
                      emailText,
                      scriptGlobals.smtpHost,
                      scriptGlobals.smtpPort)
    def __init__(self, module):
        '''
        Constructor
        '''
        ActionBundle.__init__(self, module)

        # Initialize application server object
        # appServer = ApplicationServer(module, scriptGlobals.appsrvProperties)

        # Generate a unique ActionBundle execution id
        guid = generateGUID()
        log.info("Unique ActionBundle execution ID generated: " + guid)

        # Check if Server is running
        if getProcessPIDByPathAndIdentifier(module.targetDeploymentPath, module.subModule.processIdentifier): die("\n\nThe " + module.subModule.name + " server at '" + module.targetDeploymentPath + "' is up. Installation will not continue\n")

        # Run script
        moduleDeployPath = module.targetDeploymentPath  + "/"  + module.subModule.name
        path2 = moduleDeployPath +  "/"  + module.subModule.installUpdateScript
        ChangePathPermissions(path2, 0744)
        path2=path2 + " CREATE YES "
        ExecuteOSCommand(path2, None)

        # Find version/revision info
        manifestFilePath=moduleDeployPath + "/META-INF/MANIFEST.MF"
        versionInfo = grepFile(module.versionInformationRegex, manifestFilePath)
        buildInfo = grepFile(module.buildInformationRegex, manifestFilePath)
        revisionInfo = grepFile(module.revisionInformationRegex, manifestFilePath)

        versionInfo = (versionInfo.replace(module.versionInformationRegex, "")).strip()
        if buildInfo != None:
            buildInfo = (buildInfo.replace(module.buildInformationRegex, "")).strip()

        revisionInfo = (revisionInfo.replace(module.revisionInformationRegex, "")).strip()

        # Construct the email notification
        emailSender = readPropertyFromPropertiesFileWithFallback("emailNotificationSenderAddress", scriptGlobals.scriptVarSectionName, lib.OptParser.options.envprops, scriptGlobals.emailNotificationSenderAddress)
        emailRecipients = scriptGlobals.globalNotificationEmailList
        emailSubject = "MSM Installation: " + module.name + "@"+ getCurrentHostname() + " (" + module.friendlyServerName + ")"
        emailText = detailedCleanInstallationReportTemplate(module.subModule.name,
                                                    versionInfo,
                                                    lib.OptParser.options.action,
                                                    getCurrentHostname(),
                                                    os.getcwd(),
                                                    guid,
                                                    " ".join(platform.uname()),
                                                    getpass.getuser(),
                                                    buildInfo,
                                                    revisionInfo,
                                                    lib.OptParser.options.envprops,
                                                    scriptGlobals.workingDir)

        # Email all required parties
        SendEmail(emailSender,
                  emailRecipients,
                  emailSubject,
                  emailText,
                  scriptGlobals.smtpHost,
                  scriptGlobals.smtpPort)
    def __init__(self, module):
        '''
        Constructor
        '''
        ActionBundle.__init__(self, module)

        # Generate a unique ActionBundle execution id
        guid = generateGUID()
        log.info("Unique ActionBundle execution ID generated: " + guid)

        # Check if standalone is running
        if getProcessPIDByPathAndIdentifier(module.targetDeploymentPath, module.subModule.processIdentifier): die("\n\nThe " + module.subModule.name + " server at '" + module.targetDeploymentPath + "' is up. Configuration will not continue\n")

        # Check if module is already installed
        for k, v in module.relativeCopyableFilesOrFolders.items():
            exactLocation = module.targetDeploymentPath + scriptGlobals.osDirSeparator + v
            if not os.path.isdir(exactLocation):
                die(module.subModule.name + " is Not already installed to:" + module.targetDeploymentPath + ". Maybe you want to make a clean Installation !!")

        # Get Previous Hudson data
        previousManifilePath = module.targetDeploymentPath + scriptGlobals.osDirSeparator + module.subModule.name + scriptGlobals.osDirSeparator + "META-INF" + scriptGlobals.osDirSeparator + "MANIFEST.MF"
        previousVersionInfo = grepFile(module.versionInformationRegex, previousManifilePath)
        previousBuildInfo = grepFile(module.buildInformationRegex, previousManifilePath)
        previousRevisionInfo = grepFile(module.revisionInformationRegex, previousManifilePath)
        previousRevisionInfo = (previousRevisionInfo.replace(module.revisionInformationRegex, "")).strip()
        previousVersionInfo = (previousVersionInfo.replace(module.versionInformationRegex, "")).strip()
        if previousBuildInfo != None:
            previousBuildInfo = (previousBuildInfo.replace(module.buildInformationRegex, "")).strip()

        # Construct the email notification
        emailSender = readPropertyFromPropertiesFileWithFallback("emailNotificationSenderAddress", scriptGlobals.scriptVarSectionName, lib.OptParser.options.envprops, scriptGlobals.emailNotificationSenderAddress)
        emailRecipients = scriptGlobals.globalNotificationEmailList
        emailSubject = "MSM Installation: " + module.name + "@"+ getCurrentHostname() + " (" + module.friendlyServerName + ")"
        emailText = detailedCleanInstallationReportTemplate(module.subModule.name,
                                                    previousVersionInfo,
                                                    lib.OptParser.options.action,
                                                    getCurrentHostname(),
                                                    os.getcwd(),
                                                    guid,
                                                    " ".join(platform.uname()),
                                                    getpass.getuser(),
                                                    previousBuildInfo,
                                                    previousRevisionInfo,
                                                    lib.OptParser.options.envprops,
                                                    scriptGlobals.workingDir)

        # Email all required parties
        SendEmail(emailSender,
                  emailRecipients,
                  emailSubject,
                  emailText,
                  scriptGlobals.smtpHost,
                  scriptGlobals.smtpPort)

        # end
    def __init__(self, module):
        '''
        Constructor
        '''
        guid = generateGUID()
        log.info("Unique ActionBundle execution ID generated: " + guid)

      #  appServer = ApplicationServer(module, scriptGlobals.appsrvProperties)
        pid = getProcessPIDByPathAndIdentifier(module.targetDeploymentPath, module.subModule.processIdentifier)

        bin_path=module.targetDeploymentPath  + "/"  + module.subModule.name +  "/bin/"

        if pid:
            log.info("\n\nAlready existing process running from path '" + module.targetDeploymentPath + "' with pid '" + pid + "'.\n")
            log.info("\n\Proceeding with Killing the Server")
            # Kill process using pid
            killProcess(pid)

        # Delete all cached directories
        log.info("Proceeding to delete nohup file")
        try:
            deleteDirOrFile(bin_path + "nohup.out")
        except OSError: # If directory doesn't exist ignore the raised error
                pass

        # Change directory to run the binary from inside the binpath
        pwd = os.getcwd()
        os.chdir(bin_path)
        ChangePathPermissions(bin_path + "start.sh", 0744)
        runProcess("nohup ./start.sh")
        os.chdir(pwd)

        # Construct the email notification
        emailSender = readPropertyFromPropertiesFileWithFallback("emailNotificationSenderAddress", scriptGlobals.scriptVarSectionName, lib.OptParser.options.envprops, scriptGlobals.emailNotificationSenderAddress)
        emailRecipients = module.emailNotificationRecipientList
        emailSubject = "Server START: " + module.subModule.name + "@"+ getCurrentHostname() + " (" + module.friendlyServerName + ")"
        emailText = startApplicationServerNotificationTemplate(module.name, getCurrentHostname(), guid)

        # Email all required parties
        SendEmail(emailSender,
                      emailRecipients,
                      emailSubject,
                      emailText,
                      scriptGlobals.smtpHost,
                      scriptGlobals.smtpPort)
    def __init__(self, module):
        '''
        Constructor
        '''
        guid = generateGUID()
        log.info("Unique ActionBundle execution ID generated: " + guid)
                      
        appServer = ApplicationServer(module, scriptGlobals.appsrvProperties)
        pid = getProcessPIDByPathAndIdentifier(module.targetDeploymentPath, appServer.processIdentifier)
        
        if pid: 
            log.error("Already existing process running from path '" + module.targetDeploymentPath + "' with pid '" + pid + "'.")
        else:
            # Delete all cached directories
            log.info("Proceeding to delete all cached folders")
            try:
                for i in appServer.relativeCacheFolders:
                    deleteDirOrFile(module.targetDeploymentPath + scriptGlobals.osDirSeparator + i)
            except OSError: # If directory doesn't exist ignore the raised error
                pass
            
            # Change directory to run the binary from inside the binpath
            pwd = os.getcwd()
            os.chdir(module.targetDeploymentPath + appServer.binPath)
            runProcess("." + scriptGlobals.osDirSeparator + appServer.startCommand)
            os.chdir(pwd)

            # Construct the email notification
            emailSender = readPropertyFromPropertiesFileWithFallback("emailNotificationSenderAddress", scriptGlobals.scriptVarSectionName, lib.OptParser.options.envprops, scriptGlobals.emailNotificationSenderAddress)            
            emailRecipients = module.emailNotificationRecipientList
            emailSubject = "Server START: " + module.name + "@"+ getCurrentHostname() + " (" + module.friendlyServerName + ")"
            emailText = startApplicationServerNotificationTemplate(module.name, getCurrentHostname(), guid) 
            
            # Email all required parties
            SendEmail(emailSender, 
                      emailRecipients,
                      emailSubject, 
                      emailText, 
                      scriptGlobals.smtpHost, 
                      scriptGlobals.smtpPort)              
    def __init__(self, module):
        """
        Constructor
        """
        ActionBundle.__init__(self, module)

        versionInfo = module.executionContext["versionInfo"]
        revisionInfo = module.executionContext["revisionInfo"]
        #        previousVersionInfo = module.executionContext['previousVersionInfo']
        #        previousRevisionInfo = module.executionContext['previousRevisionInfo']
        guid = module.executionContext["guid"]

        # Construct the email notification
        emailSender = readPropertyFromPropertiesFileWithFallback(
            "emailNotificationSenderAddress",
            scriptGlobals.scriptVarSectionName,
            lib.OptParser.options.envprops,
            scriptGlobals.emailNotificationSenderAddress,
        )

        emailRecipients = scriptGlobals.globalNotificationEmailList
        emailSubject = (
            "CRM Installation: " + module.name + "@" + getCurrentHostname() + " (" + module.friendlyServerName + ")"
        )
        emailText = detailedInstallationReportTemplate(
            module.name,
            lib.OptParser.options.action,
            getCurrentHostname(),
            os.getcwd(),
            guid,
            " ".join(platform.uname()),
            getpass.getuser(),
            versionInfo,
            revisionInfo,
            lib.OptParser.options.envprops,
        )

        # Email all required parties
        SendEmail(emailSender, emailRecipients, emailSubject, emailText, scriptGlobals.smtpHost, scriptGlobals.smtpPort)
    def __init__(self, module):
        """
        Constructor
        """
        ActionBundle.__init__(self, module)

        # Initialize application server object
        appServer = ApplicationServer(module, scriptGlobals.appsrvProperties)

        # Generate a unique ActionBundle execution id
        guid = generateGUID()
        log.info("Unique ActionBundle execution ID generated: " + guid)

        # Since MSM is deployed on JBOSS some paths have an %s to allow a configurable
        # profile, so do a little sprintf to fix them
        sprintfOnDictionaryValues(module.relativeConfigurationFiles, module.targetDeploymentProfile)
        sprintfOnDictionaryValues(module.relativeCopyableFilesOrFolders, module.targetDeploymentProfile)

        # For JbosswebappPath = "/server/" + module.targetDeploymentProfile + "/deploy/" + module.subModule.name + ".war"
        # for Tomcat webappPath =  "/webapps/" + module.subModule.name
        webappPath = "/webapps/" + module.subModule.name

        # Check if module exists.
        for k, v in module.relativeCopyableFilesOrFolders.items():
            exactTargetLocation = module.targetDeploymentPath + scriptGlobals.osDirSeparator + v
            if exactTargetLocation.find(webappPath) != -1:
                if not os.path.isdir(exactTargetLocation):
                    die(
                        "\n\n"
                        + module.subModule.name
                        + " is not installed under:"
                        + module.targetDeploymentPath
                        + ". Please first run a clean installation"
                    )

        # Get Previous Hudson data
        previousManifilePath = module.targetDeploymentPath + webappPath + "/META-INF/MANIFEST.MF"
        previousVersionInfo = grepFile(module.versionInformationRegex, previousManifilePath)
        previousBuildInfo = grepFile(module.buildInformationRegex, previousManifilePath)
        previousRevisionInfo = grepFile(module.revisionInformationRegex, previousManifilePath)
        previousRevisionInfo = (previousRevisionInfo.replace(module.revisionInformationRegex, "")).strip()
        previousVersionInfo = (previousVersionInfo.replace(module.versionInformationRegex, "")).strip()
        if previousBuildInfo != None:
            previousBuildInfo = (previousBuildInfo.replace(module.buildInformationRegex, "")).strip()

        # Construct the email notification
        emailSender = readPropertyFromPropertiesFileWithFallback(
            "emailNotificationSenderAddress",
            scriptGlobals.scriptVarSectionName,
            lib.OptParser.options.envprops,
            scriptGlobals.emailNotificationSenderAddress,
        )
        emailRecipients = scriptGlobals.globalNotificationEmailList
        emailSubject = (
            "MSM Installation: "
            + module.subModule.name
            + "@"
            + getCurrentHostname()
            + " ("
            + module.friendlyServerName
            + ")"
        )
        emailText = detailedCleanInstallationReportTemplate(
            module.subModule.name,
            previousVersionInfo,
            lib.OptParser.options.action,
            getCurrentHostname(),
            os.getcwd(),
            guid,
            " ".join(platform.uname()),
            getpass.getuser(),
            previousBuildInfo,
            previousRevisionInfo,
            lib.OptParser.options.envprops,
            scriptGlobals.workingDir,
        )

        # Email all required parties
        SendEmail(emailSender, emailRecipients, emailSubject, emailText, scriptGlobals.smtpHost, scriptGlobals.smtpPort)
    def __init__(self, module):
        """
        Constructor
        """
        ActionBundle.__init__(self, module)

        # Initialize application server object
        appServer = ApplicationServer(module, scriptGlobals.appsrvProperties)

        # Generate a unique ActionBundle execution id
        guid = generateGUID()
        log.info("Unique ActionBundle execution ID generated: " + guid)

        # Check if Tomcat is running
        if getProcessPIDByPathAndIdentifier(module.targetDeploymentPath, appServer.processIdentifier):
            die("\n\nThe Jboss server at '" + module.targetDeploymentPath + "' is up. Installation will not continue")

        # Since MSM is deployed on JBOSS some paths have an %s to allow a configurable
        # profile, so do a little sprintf to fix them
        sprintfOnDictionaryValues(module.relativeConfigurationFiles, module.targetDeploymentProfile)
        sprintfOnDictionaryValues(module.relativeCopyableFilesOrFolders, module.targetDeploymentProfile)

        # For JbosswebappPath = "/server/" + module.targetDeploymentProfile + "/deploy/" + module.subModule.name + ".war"
        # for Tomcat webappPath =  "/webapps/" + module.subModule.name
        webappPath = "/webapps/" + module.subModule.name
        # Check if module exists.
        for k, v in module.relativeCopyableFilesOrFolders.items():
            exactTargetLocation = module.targetDeploymentPath + scriptGlobals.osDirSeparator + v
            if exactTargetLocation.find(webappPath) != -1:
                if os.path.isdir(exactTargetLocation):
                    log.info(
                        "\n##############################################################\n"
                        + module.subModule.name
                        + " is already installed under:"
                        + module.targetDeploymentPath
                        + ". Please manually backup and remove to run a clean installation (unless you want to update)\n##############################################################"
                    )
                    die()

        # Prepare directory to unpack package
        unzippedPackagePath = createDirectoriesRecursively(
            scriptGlobals.workingDir + scriptGlobals.osDirSeparator + "unzippedPackage"
        )

        # Extract MSM package into tmp dir
        ExtractZipToDir(module.moduleFilename, unzippedPackagePath)
        CreateDirectory(unzippedPackagePath + "/bin/" + module.subModule.name)
        ExtractZipToDir(
            unzippedPackagePath + "/bin/" + module.subModule.name + ".war",
            unzippedPackagePath + "/bin/" + module.subModule.name,
        )

        # Configure xxx.properties in tmp/../conf using envprops
        for k, v in module.relativeConfigurationFiles.items():
            exactExtractedLocation = unzippedPackagePath + scriptGlobals.osDirSeparator + k
            ConfigureTemplateFile(module.name, lib.OptParser.options.envprops, exactExtractedLocation)
            CheckFileConfigurationIsComplete(exactExtractedLocation)

        # Copy relativeCopyableFilesOrFolders to specified locations on Server (values)
        for k, v in module.relativeCopyableFilesOrFolders.items():
            exactExtractedLocation = unzippedPackagePath + scriptGlobals.osDirSeparator + k
            exactTargetLocation = module.targetDeploymentPath + scriptGlobals.osDirSeparator + v
            CopyDirOrFile(exactExtractedLocation, exactTargetLocation)

        # Copy tmp/../conf/xxx.properties to to specified locations on Server (values)
        for k, v in module.relativeConfigurationFiles.items():
            exactExtractedLocation = unzippedPackagePath + scriptGlobals.osDirSeparator + k
            exactTargetLocation = module.targetDeploymentPath + scriptGlobals.osDirSeparator + v
            CopyDirOrFile(exactExtractedLocation, exactTargetLocation)

        # Find version/revision info
        revisionInfo = grepFile(
            module.revisionInformationRegex,
            unzippedPackagePath + scriptGlobals.osDirSeparator + module.relativeVersionInformationPath,
        )
        revisionInfo = (revisionInfo.replace(module.revisionInformationRegex, "")).strip()
        versionInfo = grepFile(
            module.versionInformationRegex,
            unzippedPackagePath + scriptGlobals.osDirSeparator + module.relativeVersionInformationPath,
        )
        versionInfo = (versionInfo.replace(module.versionInformationRegex, "")).strip()
        buildInfo = grepFile(
            module.buildInformationRegex,
            unzippedPackagePath + scriptGlobals.osDirSeparator + module.relativeVersionInformationPath,
        )
        if buildInfo != None:
            buildInfo = (buildInfo.replace(module.buildInformationRegex, "")).strip()

        # Run CREATE/UPDATE/UPGRADE script
        if module.subModule.installUpdateScript != "":
            path1 = module.targetDeploymentPath + webappPath + "/" + module.subModule.installUpdateScript
            ChangePathPermissions(path1, 0744)
            path1 = path1 + " CREATE YES "
            ExecuteOSCommand(path1, None)

        # Construct the email notification
        emailSender = readPropertyFromPropertiesFileWithFallback(
            "emailNotificationSenderAddress",
            scriptGlobals.scriptVarSectionName,
            lib.OptParser.options.envprops,
            scriptGlobals.emailNotificationSenderAddress,
        )
        emailRecipients = scriptGlobals.globalNotificationEmailList
        emailSubject = (
            "MSM Installation: "
            + module.subModule.name
            + "@"
            + getCurrentHostname()
            + " ("
            + module.friendlyServerName
            + ")"
        )
        emailText = detailedCleanInstallationReportTemplate(
            module.subModule.name,
            versionInfo,
            lib.OptParser.options.action,
            getCurrentHostname(),
            os.getcwd(),
            guid,
            " ".join(platform.uname()),
            getpass.getuser(),
            buildInfo,
            revisionInfo,
            lib.OptParser.options.envprops,
            scriptGlobals.workingDir,
        )

        # Email all required parties
        SendEmail(emailSender, emailRecipients, emailSubject, emailText, scriptGlobals.smtpHost, scriptGlobals.smtpPort)
    def __init__(self, module):
        """
        Constructor
        """
        ActionBundle.__init__(self, module)

        # Initialize application server object
        appServer = ApplicationServer(module, scriptGlobals.appsrvProperties)

        # Generate a unique ActionBundle execution id
        guid = generateGUID()
        log.info("Unique ActionBundle execution ID generated: " + guid)

        # Check if Tomcat is running
        if getProcessPIDByPathAndIdentifier(module.targetDeploymentPath, appServer.processIdentifier):
            die("\n\nThe Jboss server at '" + module.targetDeploymentPath + "' is up. Installation will not continue")

        # Since MSM is deployed on JBOSS some paths have an %s to allow a configurable
        # profile, so do a little sprintf to fix them
        sprintfOnDictionaryValues(module.relativeConfigurationFiles, module.targetDeploymentProfile)
        sprintfOnDictionaryValues(module.relativeCopyableFilesOrFolders, module.targetDeploymentProfile)

        # For JbosswebappPath = "/server/" + module.targetDeploymentProfile + "/deploy/" + module.subModule.name + ".war"
        # for Tomcat webappPath =  "/webapps/" + module.subModule.name
        webappPath = "/webapps/" + module.subModule.name

        # Check if module exists.
        for k, v in module.relativeCopyableFilesOrFolders.items():
            exactTargetLocation = module.targetDeploymentPath + scriptGlobals.osDirSeparator + v
            if exactTargetLocation.find(webappPath) != -1:
                if not os.path.isdir(exactTargetLocation):
                    die(
                        "\n\n"
                        + module.subModule.name
                        + " is not installed under:"
                        + module.targetDeploymentPath
                        + ". Please first run a clean installation"
                    )

        # Get Previous Hudson data
        previousManifilePath = module.targetDeploymentPath + webappPath + "/META-INF/MANIFEST.MF"
        previousVersionInfo = grepFile(module.versionInformationRegex, previousManifilePath)
        previousBuildInfo = grepFile(module.buildInformationRegex, previousManifilePath)
        previousRevisionInfo = grepFile(module.revisionInformationRegex, previousManifilePath)
        previousVersionInfo = (previousVersionInfo.replace(module.versionInformationRegex, "")).strip()
        if previousBuildInfo != None:
            previousBuildInfo = (previousBuildInfo.replace(module.buildInformationRegex, "")).strip()

        previousRevisionInfo = (previousRevisionInfo.replace(module.revisionInformationRegex, "")).strip()

        # Prepare directory to keep backups
        previousVersionBackupPath = createDirectoriesRecursively(
            scriptGlobals.workingDir + scriptGlobals.osDirSeparator + "previousVersionBackup"
        )

        # Backup webapps
        if lib.OptParser.action != "install-nodb-nobackup":
            for k, v in module.relativeCopyableFilesOrFolders.items():
                exactLocation = module.targetDeploymentPath + scriptGlobals.osDirSeparator + v
                exactBackupLocation = previousVersionBackupPath + scriptGlobals.osDirSeparator + k
                CopyDirOrFile3(exactLocation, exactBackupLocation)

        # Prepare directory to unpack package
        unzippedPackagePath = createDirectoriesRecursively(
            scriptGlobals.workingDir + scriptGlobals.osDirSeparator + "unzippedPackage"
        )

        # Extract MSM package into tmp dir
        ExtractZipToDir(module.moduleFilename, unzippedPackagePath)
        CreateDirectory(unzippedPackagePath + "/bin/" + module.subModule.name)
        ExtractZipToDir(
            unzippedPackagePath + "/bin/" + module.subModule.name + ".war",
            unzippedPackagePath + "/bin/" + module.subModule.name,
        )

        # Configure xxx.properties in tmp/../conf using envprops
        for k, v in module.relativeConfigurationFiles.items():
            exactExtractedLocation = unzippedPackagePath + scriptGlobals.osDirSeparator + k
            ConfigureTemplateFile(module.name, lib.OptParser.options.envprops, exactExtractedLocation)
            CheckFileConfigurationIsComplete(exactExtractedLocation)

        # Copy tmp/../conf/xxx.properties to to specified locations on Server (values)
        for k, v in module.relativeConfigurationFiles.items():
            exactExtractedLocation = unzippedPackagePath + scriptGlobals.osDirSeparator + k
            exactTargetLocation = module.targetDeploymentPath + scriptGlobals.osDirSeparator + v
            CopyDirOrFile(exactExtractedLocation, exactTargetLocation)

        # Construct the email notification
        emailSender = readPropertyFromPropertiesFileWithFallback(
            "emailNotificationSenderAddress",
            scriptGlobals.scriptVarSectionName,
            lib.OptParser.options.envprops,
            scriptGlobals.emailNotificationSenderAddress,
        )
        emailRecipients = scriptGlobals.globalNotificationEmailList
        emailSubject = (
            "MSM Installation: "
            + module.subModule.name
            + "@"
            + getCurrentHostname()
            + " ("
            + module.friendlyServerName
            + ")"
        )
        emailText = detailedUpdateInstallationReportTemplate(
            module.subModule.name,
            previousVersionInfo,
            lib.OptParser.options.action,
            getCurrentHostname(),
            os.getcwd(),
            guid,
            " ".join(platform.uname()),
            getpass.getuser(),
            previousBuildInfo,
            previousRevisionInfo,
            lib.OptParser.options.envprops,
            previousVersionInfo,
            previousBuildInfo,
            previousRevisionInfo,
            scriptGlobals.workingDir,
        )

        # Email all required parties
        SendEmail(emailSender, emailRecipients, emailSubject, emailText, scriptGlobals.smtpHost, scriptGlobals.smtpPort)
    def __init__(self, module):
        '''
        Constructor
        '''
        ActionBundle.__init__(self, module)

        # Initialize application server object
       # appServer = ApplicationServer(module, scriptGlobals.appsrvProperties)

        # Generate a unique ActionBundle execution id
        guid = generateGUID()
        log.info("Unique ActionBundle execution ID generated: " + guid)

        # Check if Server is running
        if getProcessPIDByPathAndIdentifier(module.targetDeploymentPath, module.subModule.processIdentifier): die("\n\nThe " + module.subModule.name + " server at '" + module.targetDeploymentPath + "' is up. Installation will not continue\n")

        # Check if module exists.
        for k, v in module.relativeCopyableFilesOrFolders.items():
            exactTargetLocation = module.targetDeploymentPath + scriptGlobals.osDirSeparator + v
            if os.path.isdir(exactTargetLocation):
                log.info("\n###############################################################################################\n" + module.subModule.name
                        + " is already installed under:" + module.targetDeploymentPath
                        + ". Please manually backup and remove to run a clean installation (unless you want to update)\n###############################################################################################")
                die()
					
        # Prepare directory to unpack package
        unzippedPackagePath = createDirectoriesRecursively(scriptGlobals.workingDir + scriptGlobals.osDirSeparator + "unzippedPackage")

        # Extract MSM package into tmp dir
        ExtractZipToDir(module.moduleFilename, unzippedPackagePath)

        filenameToExtract = "META-INF/MANIFEST.MF"
        zipFilename = unzippedPackagePath +  "/bin/" + module.subModule.name + "/lib/" + module.subModule.name +".jar"
        location = unzippedPackagePath +  "/bin/" + module.subModule.name + "/META-INF"
        ExtractFileFromZipToDir(zipFilename, filenameToExtract, location)

        # Configure xxx.properties in tmp/../conf using envprops
        for k, v in module.relativeConfigurationFiles.items():
            exactExtractedLocation = unzippedPackagePath + scriptGlobals.osDirSeparator + k
            ConfigureTemplateFile(module.name, lib.OptParser.options.envprops,  exactExtractedLocation)
            CheckFileConfigurationIsComplete(exactExtractedLocation)

        # Copy relativeCopyableFilesOrFolders to specified locations on Server (values)
        for k, v in module.relativeCopyableFilesOrFolders.items():
            exactExtractedLocation = unzippedPackagePath + scriptGlobals.osDirSeparator + k
            exactTargetLocation = module.targetDeploymentPath + scriptGlobals.osDirSeparator + v
            CopyDirOrFile(exactExtractedLocation, exactTargetLocation)

        # Copy tmp/../conf/xxx.properties to to specified locations on Server (values)
        for k, v in module.relativeConfigurationFiles.items():
            exactExtractedLocation = unzippedPackagePath + scriptGlobals.osDirSeparator + k
            exactTargetLocation = module.targetDeploymentPath + scriptGlobals.osDirSeparator + v
            CopyDirOrFile(exactExtractedLocation, exactTargetLocation)

        if (module.subModule.name == "mrouter"):
            exactExtractedLocation = unzippedPackagePath + scriptGlobals.osDirSeparator + module._locations['relativeStartupScript']
            ChangePathPermissions(exactExtractedLocation, 0777)
            CopyDirOrFile2(exactExtractedLocation, module.targetDeploymentPath)

        # Find version/revision info
        versionInfo = grepFile(module.versionInformationRegex, unzippedPackagePath +  scriptGlobals.osDirSeparator + module.relativeVersionInformationPath)
        versionInfo = (versionInfo.replace(module.versionInformationRegex, "")).strip()
        revisionInfo = grepFile(module.revisionInformationRegex, unzippedPackagePath +  scriptGlobals.osDirSeparator + module.relativeVersionInformationPath)
        revisionInfo = (revisionInfo.replace(module.revisionInformationRegex, "")).strip()
        buildInfo = grepFile(module.buildInformationRegex, unzippedPackagePath +  scriptGlobals.osDirSeparator + module.relativeVersionInformationPath)
        if buildInfo != None:
            buildInfo = (buildInfo.replace(module.buildInformationRegex, "")).strip()


        moduleDeployPath = module.targetDeploymentPath  + "/"  + module.subModule.name
        path1 = moduleDeployPath +  "/bin"
        ChangePathPermissions(path1, 0744)
        path2 = moduleDeployPath +  "/"  + module.subModule.installUpdateScript
        path2=path2 + " CREATE YES "
        ExecuteOSCommand(path2, None)
  ##ExecuteOSCommandAndCaptureOutput(path1,"ERROR", None, None)
  ##THIS    ExecuteOSCommand(path1, None)
  ##ExecuteOSCommandAndCaptureOutput("cd " + path1, None, None)

        
        # Construct the email notification
        emailSender = readPropertyFromPropertiesFileWithFallback("emailNotificationSenderAddress", scriptGlobals.scriptVarSectionName, lib.OptParser.options.envprops, scriptGlobals.emailNotificationSenderAddress)        
        emailRecipients = scriptGlobals.globalNotificationEmailList
        emailSubject = "MSM Installation: " + module.name + "@"+ getCurrentHostname() + " (" + module.friendlyServerName + ")"
        emailText = detailedCleanInstallationReportTemplate(module.subModule.name,
                                                    versionInfo,
                                                    lib.OptParser.options.action,
                                                    getCurrentHostname(),
                                                    os.getcwd(),
                                                    guid,
                                                    " ".join(platform.uname()),
                                                    getpass.getuser(),
                                                    buildInfo,
                                                    revisionInfo,
                                                    lib.OptParser.options.envprops,
                                                    scriptGlobals.workingDir)
          
        # Email all required parties
        SendEmail(emailSender, 
                  emailRecipients,
                  emailSubject, 
                  emailText,
                  scriptGlobals.smtpHost, 
                  scriptGlobals.smtpPort)        
    def __init__(self, module):
        '''
        Constructor
        '''
        ActionBundle.__init__(self, module)

        # Initialize application server object
#        appServer = ApplicationServer(module, scriptGlobals.appsrvProperties)

        # Generate a unique ActionBundle execution id
        guid = generateGUID()
        log.info("Unique ActionBundle execution ID generated: " + guid)

        # Check if standalone is running
        if getProcessPIDByPathAndIdentifier(module.targetDeploymentPath, module.subModule.processIdentifier): die("\n\nThe " + module.subModule.name + " server at '" + module.targetDeploymentPath + "' is up. Installation will not continue\n")

        exists="true"
        # Check if module is already installed
        for k, v in module.relativeCopyableFilesOrFolders.items():
            exactLocation = module.targetDeploymentPath + scriptGlobals.osDirSeparator + v
            if not os.path.isdir(exactLocation):
                exists = "false"
                #die(module.subModule.name + " is Not already installed to:" + module.targetDeploymentPath + ". Maybe you want to make a clean Installation !!")

        previousVersionInfo=""
        previousBuildInfo=""
        previousRevisionInfo=""
        if (exists == "true"):
        # Get Previous Hudson data
            previousManifilePath = module.targetDeploymentPath + scriptGlobals.osDirSeparator + module.subModule.name + scriptGlobals.osDirSeparator + "META-INF" + scriptGlobals.osDirSeparator + "MANIFEST.MF"
            previousVersionInfo = grepFile(module.versionInformationRegex, previousManifilePath)
            previousBuildInfo = grepFile(module.buildInformationRegex, previousManifilePath)
            previousRevisionInfo = grepFile(module.revisionInformationRegex, previousManifilePath)
            previousVersionInfo = (previousVersionInfo.replace(module.versionInformationRegex, "")).strip()
            previousRevisionInfo = (previousRevisionInfo.replace(module.revisionInformationRegex, "")).strip()
            if previousBuildInfo != None:
                previousBuildInfo = (previousBuildInfo.replace(module.buildInformationRegex, "")).strip()

        # Prepare directory to keep backups
        previousVersionBackupPath = createDirectoriesRecursively(scriptGlobals.workingDir + scriptGlobals.osDirSeparator + "previousVersionBackup")


        # Backup standalone
        if (lib.OptParser.action !="install-nodb-nobackup" and exists == "true"):
            for k, v in module.relativeCopyableFilesOrFolders.items():
                exactLocation = module.targetDeploymentPath + scriptGlobals.osDirSeparator + v
                exactBackupLocation = previousVersionBackupPath + scriptGlobals.osDirSeparator + k
                CopyDirOrFile3(exactLocation, exactBackupLocation)
                if  exactLocation.find(module.subModule.name) != -1 :
                    DeleteDirOrFile(exactLocation)

        # Prepare directory to unpack package
        unzippedPackagePath = createDirectoriesRecursively(scriptGlobals.workingDir + scriptGlobals.osDirSeparator + "unzippedPackage")

        # Extract MSM package into tmp dir
        ExtractZipToDir(module.moduleFilename, unzippedPackagePath)
 #       CreateDirectory(unzippedPackagePath + "/bin/" + module.subModule.name)
 #       ExtractZipToDir(unzippedPackagePath + "/bin/" + module.subModule.name + ".war", unzippedPackagePath + "/bin/" + module.subModule.name)


        filenameToExtract = "META-INF/MANIFEST.MF"
        zipFilename = unzippedPackagePath +  "/bin/" + module.subModule.name + "/lib/" + module.subModule.name +".jar"
        location = unzippedPackagePath +  "/bin/" + module.subModule.name + "/META-INF"
        ExtractFileFromZipToDir(zipFilename, filenameToExtract, location)


        # Configure xxx.properties in tmp/../conf using envprops
        for k, v in module.relativeConfigurationFiles.items():
            exactExtractedLocation = unzippedPackagePath + scriptGlobals.osDirSeparator + k
            ConfigureTemplateFile(module.name, lib.OptParser.options.envprops,  exactExtractedLocation)
            CheckFileConfigurationIsComplete(exactExtractedLocation)

        # Copy relativeCopyableFilesOrFolders to specified locations on Server (values)
        for k, v in module.relativeCopyableFilesOrFolders.items():
            exactExtractedLocation = unzippedPackagePath + scriptGlobals.osDirSeparator + k
            exactTargetLocation = module.targetDeploymentPath + scriptGlobals.osDirSeparator + v
            CopyDirOrFile(exactExtractedLocation, exactTargetLocation)

        # Copy tmp/../conf/xxx.properties to to specified locations on Server (values)
        for k, v in module.relativeConfigurationFiles.items():
            exactExtractedLocation = unzippedPackagePath + scriptGlobals.osDirSeparator + k
            exactTargetLocation = module.targetDeploymentPath + scriptGlobals.osDirSeparator + v
            CopyDirOrFile(exactExtractedLocation, exactTargetLocation)

        if (module.subModule.name == "mrouter"):
            exactExtractedLocation = unzippedPackagePath + scriptGlobals.osDirSeparator + module._locations['relativeStartupScript']
            ChangePathPermissions(exactExtractedLocation, 0777)
            CopyDirOrFile2(exactExtractedLocation, module.targetDeploymentPath)

        path1 = module.targetDeploymentPath  + "/"  + module.subModule.name +  "/bin"
        ChangePathPermissions(path1, 0744)

        # Find version/revision info
        versionInfo = grepFile(module.versionInformationRegex, unzippedPackagePath +  scriptGlobals.osDirSeparator + module.relativeVersionInformationPath)
        versionInfo = (versionInfo.replace(module.versionInformationRegex, "")).strip()
        revisionInfo = grepFile(module.revisionInformationRegex, unzippedPackagePath +  scriptGlobals.osDirSeparator + module.relativeVersionInformationPath)
        revisionInfo = (revisionInfo.replace(module.revisionInformationRegex, "")).strip()
        buildInfo = grepFile(module.buildInformationRegex, unzippedPackagePath +  scriptGlobals.osDirSeparator + module.relativeVersionInformationPath)
        if buildInfo != None:
            buildInfo = (buildInfo.replace(module.buildInformationRegex, "")).strip()

        if (lib.OptParser.action == "install-update" or lib.OptParser.action == "_customUpgrade"):
            moduleDeployPath = module.targetDeploymentPath  + "/"  + module.subModule.name
            path1 = moduleDeployPath +  "/bin"
            ChangePathPermissions(path1, 0744)
            path2 = moduleDeployPath +  "/"  + module.subModule.installUpdateScript
            if (lib.OptParser.action == "_customUpgrade"):
                path2=path2 + " UPGRADE YES "
            else:
                path2=path2 + " UPDATE YES "
            ExecuteOSCommand(path2, None)

        # Construct the email notification
        emailSender = readPropertyFromPropertiesFileWithFallback("emailNotificationSenderAddress", scriptGlobals.scriptVarSectionName, lib.OptParser.options.envprops, scriptGlobals.emailNotificationSenderAddress)
        emailRecipients = scriptGlobals.globalNotificationEmailList
        emailSubject = "MSM Installation: " + module.name + "@"+ getCurrentHostname() + " (" + module.friendlyServerName + ")"
        emailText = detailedUpdateInstallationReportTemplate(module.subModule.name,
                                                    versionInfo,
                                                    lib.OptParser.options.action,
                                                    getCurrentHostname(),
                                                    os.getcwd(),
                                                    guid,
                                                    " ".join(platform.uname()),
                                                    getpass.getuser(),
                                                    buildInfo,
                                                    revisionInfo,
                                                    lib.OptParser.options.envprops,
                                                    previousVersionInfo,
                                                    previousBuildInfo,
                                                    previousRevisionInfo,
                                                    scriptGlobals.workingDir)

        # Email all required parties
        SendEmail(emailSender,
                  emailRecipients,
                  emailSubject,
                  emailText,
                  scriptGlobals.smtpHost,
                  scriptGlobals.smtpPort)
    def __init__(self, module):
        '''
        Constructor
        '''
        ActionBundle.__init__(self, module)

        # Generate a unique ActionBundle execution id
        guid = generateGUID()
        log.info("Unique ActionBundle execution ID generated: " + guid)

        # Check if standalone is running
        if getProcessPIDByPathAndIdentifier(module.targetDeploymentPath, module.subModule.processIdentifier): die("\n\nThe " + module.subModule.name + " server at '" + module.targetDeploymentPath + "' is up. Configuration will not continue\n")

        # Check if module is already installed
        for k, v in module.relativeCopyableFilesOrFolders.items():
            exactLocation = module.targetDeploymentPath + scriptGlobals.osDirSeparator + v
            if not os.path.isdir(exactLocation):
                die(module.subModule.name + " is Not already installed to:" + module.targetDeploymentPath + ". Maybe you want to make a clean Installation !!")

        # Get Previous Hudson data
        previousManifilePath = module.targetDeploymentPath + scriptGlobals.osDirSeparator + module.subModule.name + scriptGlobals.osDirSeparator + "META-INF" + scriptGlobals.osDirSeparator + "MANIFEST.MF"
        previousVersionInfo = grepFile(module.versionInformationRegex, previousManifilePath)
        previousBuildInfo = grepFile(module.buildInformationRegex, previousManifilePath)
        previousRevisionInfo = grepFile(module.revisionInformationRegex, previousManifilePath)
        previousVersionInfo = (previousVersionInfo.replace(module.versionInformationRegex, "")).strip()
        if previousBuildInfo != None:
            previousBuildInfo = (previousBuildInfo.replace(module.buildInformationRegex, "")).strip()

        previousRevisionInfo = (previousRevisionInfo.replace(module.revisionInformationRegex, "")).strip()

        # Prepare directory to keep backups
        previousVersionBackupPath = createDirectoriesRecursively(scriptGlobals.workingDir + scriptGlobals.osDirSeparator + "previousVersionBackup")


        # Backup standalone
        for k, v in module.relativeCopyableFilesOrFolders.items():
            exactLocation = module.targetDeploymentPath + scriptGlobals.osDirSeparator + v
            exactBackupLocation = previousVersionBackupPath + scriptGlobals.osDirSeparator + k
            CopyDirOrFile3(exactLocation, exactBackupLocation)
        #    if  exactLocation.find(module.subModule.name) != -1 :
        #        DeleteDirOrFile(exactLocation)

        # Prepare directory to unpack package
        unzippedPackagePath = createDirectoriesRecursively(scriptGlobals.workingDir + scriptGlobals.osDirSeparator + "unzippedPackage")

        # Extract MSM package into tmp dir
        ExtractZipToDir(module.moduleFilename, unzippedPackagePath)

        filenameToExtract = "META-INF/MANIFEST.MF"
        zipFilename = unzippedPackagePath +  "/bin/" + module.subModule.name + "/lib/" + module.subModule.name +".jar"
        location = unzippedPackagePath +  "/bin/" + module.subModule.name + "/META-INF"
        ExtractFileFromZipToDir(zipFilename, filenameToExtract, location)


        # Configure xxx.properties in tmp/../conf using envprops
        for k, v in module.relativeConfigurationFiles.items():
            exactExtractedLocation = unzippedPackagePath + scriptGlobals.osDirSeparator + k
            ConfigureTemplateFile(module.name, lib.OptParser.options.envprops,  exactExtractedLocation)
            CheckFileConfigurationIsComplete(exactExtractedLocation)

        # Copy tmp/../conf/xxx.properties to to specified locations on Server (values)
        for k, v in module.relativeConfigurationFiles.items():
            exactExtractedLocation = unzippedPackagePath + scriptGlobals.osDirSeparator + k
            exactTargetLocation = module.targetDeploymentPath + scriptGlobals.osDirSeparator + v
            CopyDirOrFile(exactExtractedLocation, exactTargetLocation)

        # Construct the email notification
        emailSender = readPropertyFromPropertiesFileWithFallback("emailNotificationSenderAddress", scriptGlobals.scriptVarSectionName, lib.OptParser.options.envprops, scriptGlobals.emailNotificationSenderAddress)
        emailRecipients = scriptGlobals.globalNotificationEmailList
        emailSubject = "MSM Installation: " + module.name + "@"+ getCurrentHostname() + " (" + module.friendlyServerName + ")"
        emailText = detailedUpdateInstallationReportTemplate(module.subModule.name,
                                                    previousVersionInfo,
                                                    lib.OptParser.options.action,
                                                    getCurrentHostname(),
                                                    os.getcwd(),
                                                    guid,
                                                    " ".join(platform.uname()),
                                                    getpass.getuser(),
                                                    previousBuildInfo,
                                                    previousRevisionInfo,
                                                    lib.OptParser.options.envprops,
                                                    previousVersionInfo,
                                                    previousBuildInfo,
                                                    previousRevisionInfo,
                                                    scriptGlobals.workingDir)

        # Email all required parties
        SendEmail(emailSender,
                  emailRecipients,
                  emailSubject,
                  emailText,
                  scriptGlobals.smtpHost,
                  scriptGlobals.smtpPort)
Example #13
0
    log.info("Printing final report ...")

    # All executed actions are in the executedActionList, use it to print out their report() functions
    produceFinalReport(scriptGlobals.executedActionList)

#finally: # finaly block not supported in Python 2.4 after else: blocks :-(

# Serialize the list queue
fireworksStateFilename = serializeListToFile(scriptGlobals.executedActionList, scriptGlobals.workingDir + scriptGlobals.osDirSeparator + guid + ".fsf")
log.info("Fireworks state file is '" + fireworksStateFilename + "'. You can use this for Rollback operations using the -r switch")
log.info("To perform rollbacks you will need to retain the working directory the script used in this execution '" + scriptGlobals.workingDir + "'")

# Construct the email notification
emailSender = readPropertyFromPropertiesFileWithFallback("emailNotificationSenderAddress", scriptGlobals.scriptVarSectionName, parser.options.envprops, scriptGlobals.emailNotificationSenderAddress)
emailRecipients = scriptGlobals.globalNotificationEmailList
emailSubject = "Fireworks Execution Report: " + module.name + "@"+ getCurrentHostname() + " (" + module.friendlyServerName + ")"
emailText = detailedExecutionReportTemplate(scriptGlobals.version,
                                            scriptGlobals.revision,
                                            scriptGlobals.buildDate,
                                            module.name,
                                            parser.options.action, 
                                            getCurrentHostname(),
                                            scriptGlobals.workingDir,
                                            os.getcwd(), 
                                            guid,
                                            fireworksStateFilename,
                                            " ".join(platform.uname()),
                                            getpass.getuser())
  
# Email all required parties
sendEmail(emailSender, 
 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)