# Add code to run a CAS crawl

Add code to AppConfig.xml that specifies the CAS crawl to run. Depending on your environment, you may need a script that runs a full CAS crawl and a script that runs an incremental CAS crawl. In either case, the code typically locks the crawl (to wait for any running crawls to complete), runs the crawl, and release the lock.

To add code to run a CAS crawl:

1. Open the AppConfig.xml file in a text editor.
2. To run a full CAS crawl, add code that locks the crawl, runs the crawl, and releases the lock. For example:

       <!--
           ########################################################################
           # full crawl script
           #
        -->

         <script id="Endeca_fullCasCrawl">
           <log-dir>./logs/provisioned_scripts</log-dir>
           <provisioned-script-command>./control/runcommand.bat Endeca_fullCasCrawl run</provisioned-script-command>
           <bean-shell-script>
             <![CDATA[
           crawlName = "Endeca";

           log.info("Starting full CAS crawl '" + crawlName + "'.");

           // obtain lock
           if (LockManager.acquireLock("crawl_lock_" + crawlName)) {

             CAS.runBaselineCasCrawl(crawlName);

             LockManager.releaseLock("crawl_lock_" + crawlName);
           }
           else {
             log.warning("Failed to obtain lock.");
           }

           log.info("Finished full CAS crawl '" + crawlName + "'.");
             ]]>
           </bean-shell-script>
         </script>

3. To run a incremental CAS crawl, add code that locks the crawl, runs the crawl, and releases the lock. For example:

          <!--
           ########################################################################
           # incremental crawl script
           #
         -->
         <script id="Endeca_incrementalCasCrawl">
           <log-dir>./logs/provisioned_scripts</log-dir>
           <provisioned-script-command>./control/runcommand.bat Endeca_incrementalCasCrawl run</provisioned-script-command>
           <bean-shell-script>
             <![CDATA[
           crawlName = "Endeca";

          	log.info("Starting incremental CAS crawl '" + crawlName + "'.");

           // obtain lock
           if (LockManager.acquireLock("crawl_lock_" + crawlName)) {

             CAS.runIncrementalCasCrawl(crawlName);

             LockManager.releaseLock("crawl_lock_" + crawlName);
           }
           else {
             log.warning("Failed to obtain lock.");
           }

           log.info("Finished incremental CAS crawl '" + crawlName + "'.");
             ]]>
           </bean-shell-script>
         </script>