Run Modes in aem is used to tune up aem instance according to environment need. 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 which change log configurations automatically when we start the instance. Similarly we can also install separate bundles according to run modes.
Wondering what are 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 tutorials you will have a clear understanding about:-
Types of Run modes:
- 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 from adobe author and publish.
Note:- We cannot changes primary run mode after installation, as crx-quickstart folder is created after 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 details below.
Steps to Set up 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.
Naming convention for CQ 5.6 and earlier:-
Naming convention for AEM6 and Later:-
- aem-188.8.131.5240515-author-4502.jar (For author environment)
- aem-184.108.40.20640515-publish-4503.jar (For prod environment)
Set up secondary run modes:-
There are two ways to setup 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 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 nut shell 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
Note:- This is because there is bug in AEM that by default this regex is set up for author.
- In start up script use
- 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 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. Only applicable for primary run mode.
2) From Sling property — Highest precedence in case of secondary run mode.
3) From -r option (java -jar cq-56-p4545.jar -r dev)
4) From System property (least priority)
Create run modes:-
Lets 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 development environment. Follow 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.
- Add property org.apache.sling.commons.log.level on org.apache.sling.commons.log.LogManager for changing log level specific to 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.