March 15, 2020
Estimated Post Reading Time ~

Setting Up Run Modes in AEM

Run Modes in aem is used to tune up aem instance according to environmental needs. For example, we want to have separate log levels at development,QA and production environment. Instead of going manually and changing them in Felix console, we can create run modes that change log configurations automatically when we start the instance. Similarly, we can also install separate bundles according to run modes.

Wondering what is run modes? How to setup or create run modes in aem? What are the advantages of using run modes? Then this tutorial is for you.

After completing this tutorial you will have a clear understanding of:-
·       Different types of run modes.
·       Steps to set up run modes.
·       Steps to create run modes.

Types of Run modes:


Run modes are basically categorized into two categories:-
·       Primary Run Mode(author, publish).
·       Secondary or Customized Run Mode(dev,qa).
Primary Run Modes:-
Primary run modes used at the time of installation and are fixed for the entire lifetime of that installation. There are two primary run modes provided by adobe author and publish.
Note:- We cannot change the primary run mode after installation, as the crx-quickstart folder is created after the first installation according to run mode.
Secondary Run Modes:-
Secondary or Customized run modes are applied on each startup and can be changed with a restart of AEM instance. These are custom run modes defined for specific environment like development (config.author.dev), Testing(config.author.qa) or production(config.author.prod).
Run modes are identified by adding a suffix to folder name.
·       config -> applicable for all run modes
·       config.author -> used in author run mode
·       config.publish -> used in publish run mode
·       config.<standard-run-mode>.<environment-specific-mode> -> used in the applicable run mode like dev,qa,prod etc.
Don’t worry we will see how to use them in detail below.

Steps to Set up run modes:-


Follow the below steps to set up primary or secondary run modes:-
Set up only primary run mode:-
If we don’t want secondary run modes, we can directly use primary run modes by renaming the aem jar file.
The naming convention for CQ 5.6 and earlier:-
cq-<optional-version-or-identifier>-<standard-run-mode>-<port-number>
The naming convention for AEM6 and Later:-
·       aem-<optional-version-or-indentifier>-<standard-run-mode>-<port-number>
·       aem-6.0.0.20140515-author-4502.jar (For author environment)
·       aem-6.0.0.20140515-publish-4503.jar (For prod environment)
Note:- If there are any other digits in the filename, then the port number must be prefixed with -p, It is recommended that you always prefix the port number with -p. aem-6.0.0.20140515-author-p4502.jar,aem-6.0.0.20140515-publish-p4503.jar
Set up secondary run modes:-
There are two ways to set up secondary or environment-specific run modes:-
Using Sling Properties file:-
·       Go to  <cq-installation-dir>/crx-quickstart/conf/sling.properties
·       Add the following properties (below example is for the author, dev)
§  sling.jcrinstall.folder.name.regexp=.*/(install|config)?
§  sling.run.modes=author,dev
·       In above case config.author.dev will get picked up
Note:- If this node is not found then config.author will be picked, and the config node
In nutshell, we can provide a comma separate list of run modes. For example author,dev,en. If no standard mode is specified CQ assumes it is author mode through quickstart.
Using System Properties or JVM Arguments:-
·       Go to <cq-installation-dir>/crx-quickstart/conf/sling.properties and system property (In start script):
·       In sling property file add
§  sling.jcrinstall.folder.name.regexp=.*/(install|config)?
Note:- This is because there is a bug in AEM that by default this regex is set up for the author.
·       In startup script use
§  -Dsling.run.modes=publish,prod
§  java -Xmx512m -jar aem-quickstart-6.1.jar -Dsling.run.modes=publish,prod
·       In above case config.publish.prod will get picked up
Note:- If this node is not found then config.publish will be picked, and the config node
Now the quick question that arises in our mind is – What will happen if I define run modes by both types of sling properties and system properties? which will take precedence?
Following is the order of precedence for run mode (From top to bottom, Top being highest)
1.    From jar file  — Custom or secondary run modes not supported.
2.    From System property(-D) ( -Dsling.run.modes=publish,prod,test3 )
3.    From -r option (java -jar cq-56-p4545.jar -r author,test2)
4.    From Sling property —  At starting this file is not available.
A.   Create crx-quickstart folder parallel to your jar file
B.   Inside it create a config folder.
C.   inside it create a sling.properties file.
D.   add below line to it sling.run.modes=author,test1.
Note:- Go your command prompt and start the aem jar ( It should not have a primary run mode in its name else it will take priority).

Create run modes:-


Let's take a use case for understanding run modes better. For example, by default, the log level is set as information but you want that on development environment it should be Debug. In order to accomplish it lets add a run mode for the development environment. Follow the below steps to create run modes in aem.
·       Go to Crxde.
·       Go to /apps/<myproject>/.
·       Create folder runmodes.
·       Under runmodes create folder config.author.dev. Make sure the config.author.dev is of type sling:Folder.
·       Create a node of type sling:OsgiConfig under the config.author.dev folder. Node name should be the same name as the Persistent Identity (PID) of the configuration in the OSGi Console.

§ 
Go to Felix console config manager and search for Apache Sling Logging Configuration.


·       Add property org.apache.sling.commons.log.level on org.apache.sling.commons.log.LogManager for changing log level specific to the environment.
·       Now restart the instance by giving -Dsling.run.modes=author,dev JVM argument.
§  java -XX:MaxPermSize=256m -Xmx1024M -jar AEM_6.1_Quickstart-author-4502.jar -Dsling.run.modes=author,dev
·       Go to Felix console configuration, open Apache Sling Logging Configuration. Your run mode should be updated to debug.




By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.