Writing a Liferay Deployment Script Part 6

Created: 14 January 2017  Modified:

In part 5 of this article we showed a way to stop a Liferay server using Apache Ant. Today we will look into starting a server. A person might say that you just run the start script and you are done. More is needed to verify that the server starts correctly. Furthermore if we need to perform actions after a successful startup we need to delay until the startup is complete. All the tasks we need to accomplish this have already been discussed. So we will start with the whole script and touch on the various areas

startup.xml

 <project name="serverStart" default="start" basedir=".">

  <target name="start">
    <echo message="Server Start"/>
    <exec executable="${tomcatBin}/startup.sh" failonerror="true">
    </exec>
    
    <echo message="Waiting for the following log file to appear."/>
    <echo message="${catalinaLog}"/>
    <waitfor maxwait="300" maxwaitunit="second">
      <available file="${catalinaLog}"/>
    </waitfor>
    <fail message="Catalina log file missing.">     
       <condition>
         <not><available file="${catalinaLog}"/></not>
       </condition>
    </fail>

    <echo message="Waiting for the following log file to appear."/>
    <echo message="${liferayLog}"/>
    <waitfor maxwait="300" maxwaitunit="second">
      <available file="${liferayLog}"/>
    </waitfor>
    <fail message="Liferay log file missing.">     
       <condition>
         <not><available file="${liferayLog}"/></not>
       </condition>
    </fail>

    <echo message="Waiting for Liferay License to be Registered."/>
    <waitfor maxwait="1200" maxwaitunit="second">
      <resourcecontains resource="${liferayLog}" substring="License registered"/>
    </waitfor>
    <fail message="Liferay license not registered.">     
       <condition>
         <not><resourcecontains resource="${liferayLog}" substring="License registered"/></not>
       </condition>
    </fail>

    <echo message="Waiting for Liferay Root to be deployed."/>
    <waitfor maxwait="1200" maxwaitunit="second">
      <resourcecontains resource="${catalinaLog}" substring="ROOT.xml has finished"/>
    </waitfor>
    <fail message="Liferay ROOT not deployed.">     
       <condition>
         <not><resourcecontains resource="${catalinaLog}" substring="ROOT.xml has finished"/></not>
       </condition>
    </fail>

    <echo message="Waiting for Liferay sync admin to be deployed."/>
    <waitfor maxwait="1200" maxwaitunit="second">
      <resourcecontains resource="${catalinaLog}" substring="sync-admin-portlet has finished"/>
    </waitfor>
    <fail message="Liferay Sync Admin not deployed.">     
       <condition>
         <not><resourcecontains resource="${catalinaLog}" substring="sync-admin-portlet has finished"/></not>
       </condition>
    </fail>

    <echo message="Waiting for Liferay sync web to be deployed."/>
    <waitfor maxwait="1200" maxwaitunit="second">
      <resourcecontains resource="${catalinaLog}" substring="sync-web has finished"/>
    </waitfor>
    <fail message="Liferay Sync Web not deployed.">     
       <condition>
         <not><resourcecontains resource="${catalinaLog}" substring="sync-web has finished"/></not>
       </condition>
    </fail>

    <echo message="Waiting for Liferay resources importer to be deployed."/>
    <waitfor maxwait="1200" maxwaitunit="second">
      <resourcecontains resource="${catalinaLog}" substring="resources-importer-web has finished"/>
    </waitfor>
    <fail message="Liferay Resources Importer not deployed.">     
       <condition>
         <not><resourcecontains resource="${catalinaLog}" substring="resources-importer-web has finished"/></not>
       </condition>
    </fail>

    <echo message="Waiting for Liferay open social to be deployed."/>
    <waitfor maxwait="1200" maxwaitunit="second">
      <resourcecontains resource="${catalinaLog}" substring="opensocial-portlet has finished"/>
    </waitfor>
    <fail message="Liferay Opensocial not deployed.">     
       <condition>
         <not><resourcecontains resource="${catalinaLog}" substring="opensocial-portlet has finished"/></not>
       </condition>
    </fail>

    <echo message="Waiting for Liferay kaleo designer to be deployed."/>
    <waitfor maxwait="1200" maxwaitunit="second">
      <resourcecontains resource="${catalinaLog}" substring="kaleo-designer-portlet has finished"/>
    </waitfor>
    <fail message="Liferay Kaleo Designer not deployed.">     
       <condition>
         <not><resourcecontains resource="${catalinaLog}" substring="kaleo-designer-portlet has finished"/></not>
       </condition>
    </fail>
    
    <echo message="Waiting for Liferay web form to be deployed."/>
    <waitfor maxwait="1200" maxwaitunit="second">
      <resourcecontains resource="${catalinaLog}" substring="web-form-portlet has finished"/>
    </waitfor>
    <fail message="Liferay Kaleo Designer not deployed.">     
       <condition>
         <not><resourcecontains resource="${catalinaLog}" substring="web-form-portlet has finished"/></not>
       </condition>
    </fail>

    <echo message="Waiting for Liferay kaleo forms to be deployed."/>
    <waitfor maxwait="1200" maxwaitunit="second">
      <resourcecontains resource="${catalinaLog}" substring="kaleo-forms-portlet has finished"/>
    </waitfor>    
    <fail message="Liferay Kaleo Forms not deployed.">     
       <condition>
         <not><resourcecontains resource="${catalinaLog}" substring="kaleo-forms-portlet has finished"/></not>
       </condition>
    </fail>

    <echo message="Waiting for Liferay calendar to be deployed."/>
    <waitfor maxwait="1200" maxwaitunit="second">
      <resourcecontains resource="${catalinaLog}" substring="calendar-portlet has finished"/>
    </waitfor>    
    <fail message="Liferay Calendar not deployed.">     
       <condition>
         <not><resourcecontains resource="${catalinaLog}" substring="calendar-portlet has finished"/></not>
       </condition>
    </fail>

    <echo message="Waiting for Liferay notifications to be deployed."/>
    <waitfor maxwait="1200" maxwaitunit="second">
      <resourcecontains resource="${catalinaLog}" substring="notifications-portlet has finished"/>
    </waitfor>    
    <fail message="Liferay Notifications not deployed.">
       <condition>
         <not><resourcecontains resource="${catalinaLog}" substring="notifications-portlet has finished"/></not>
       </condition>
    </fail>

    <echo message="Waiting for Liferay marketplace to be deployed."/>
    <waitfor maxwait="1200" maxwaitunit="second">
      <resourcecontains resource="${catalinaLog}" substring="marketplace-portlet has finished"/>
    </waitfor>    
    <fail message="Liferay Marketplace not deployed.">
       <condition>
         <not><resourcecontains resource="${catalinaLog}" substring="marketplace-portlet has finished"/></not>
       </condition>
    </fail>

    <echo message="Waiting for Liferay server startup."/>
    <waitfor maxwait="1200" maxwaitunit="second">
      <resourcecontains resource="${catalinaLog}" substring="Server startup in"/>
    </waitfor>    
    <fail message="Liferay Startup message missing.">
       <condition>
         <not><resourcecontains resource="${catalinaLog}" substring="Server startup in"/></not>
       </condition>
    </fail>
  </target>
</project>

Very similar to our previous examples we execute the startup script, wait for the log files to appear and monitor the log files. Once the correct messages appear in the log file appear we have a successful startup. Keep in mind that multiple starts and stops being recorded in the log file will give you false positive results with the log files. You will need to move or truncate the existing log file. This concludes this series of articles.

tags: liferay - 6.2 - java - deploy - command line
   Less Is More