order of precedence of Sling run modes | Community
Skip to main content
August 26, 2016

order of precedence of Sling run modes

  • August 26, 2016
  • 4 replies
  • 11124 views

I have a doubt over this question

    Question: What is the correct order of precedence to setup runmodes in aem? (From left to right, left beign the highest)?

    A. System property, Sling properties file, jar file
    B. jar file, sling properties file, system property
    C. Sling properties file, jar file, system property
    D. jar file, System property, Sling properties file
    
    Answer : B

I had gone through various docs and had done multiple experiments over this.

Acc to [Adobe documentation][1] the order is - Sling.properties, System property, jar file

Similarly, [this Adobe doc][2] has a contradictory opinion - jar file, sling.properties, system property

Also, [Apache Sling Doc][3] says that any property to option D `(-D)` set in manner, n=v, overwrites same named properties in the sling.properties file. which means system property has higher precedence then sling.properties.

Now,  these are all according to docs, what I had experimented is-

I made a path ${dir}/crx-quickstart/conf and created a file sling.properties and wrote `sling.run.modes=publish`. Then renamed the jar file as `cq-author-7502.jar`. Then run this jar with the command `java -jar cq-author-7502.jar -Dsling.run.modes=prod`

This is my observation:<br/>
1. When the jar runs, `Setting 'sling.run.modes' to 'publish' from sling.properties.` this message is shown in the terminal.<br/>
2. The instance up in author mode. And<br/>
3. When I checked the instance-mode in [felix console][4], it was prod<br/>

I am totally confused about the order of precedence. As everything seems contradictory to me. 

It would be grateful if anyone can put some light on it..

Thank you

  [1]: https://docs.adobe.com/docs/en/cq/5-6-1/deploying/configure_runmodes.html#Starting%20CQ%20with%20a%20specific%20run%20mode
  [2]: https://helpx.adobe.com/in/experience-manager/kb/RunModeSetUp.html
  [3]: https://sling.apache.org/documentation/the-sling-engine/the-sling-launchpad.html
  [4]: http://localhost:7502/system/console/status-slingprops

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

4 replies

AnkurAhlawat-1
Level 6
October 26, 2017

I was also confused with order of precedence, but when i tested all the option. I get below order of precedence.

Following is the order of precedence for run mode (From top to bottom, Top being highest)

From jar file  —Custom or secondary run modes not supported.

From System property(-D) ( -Dsling.run.modes=publish,prod,test3 )

From -r option (java -jar cq-56-p4545.jar -r author,test2)

From Sling property —  At starting this file is not available. Create crx-quickstart folder parallel to your jar file Inside it create config folder. inside it  create sling.properties file. add below line to it sling.run.modes=author,test1. Note:- Go your your command prompt and start the aem jar ( It should not have primary run mode in its name else it will take priority).

I think above documentation should be verified and updated accordingly.

Read more at AEMCQ5Tutorials: Set Up Run Modes in AEM http://www.aemcq5tutorials.com/tutorials/set-up-run-modes-in-aem/

Level 4
November 7, 2018

Hello Ankur, Please see below. I tried to install AEM  (6.2) from command line. It took run mode from -r option instead of jar name.

$ java -jar cq-author-p2400.jar -r publish

Loading quickstart properties: default

Loading quickstart properties: instance

Low-memory action set to fork

Using 64bit VM settings, min.heap=1024MB, min permgen=256MB, default fork arguments=[-Xmx1024m, -XX:MaxPermSize=256m]

The JVM reports a heap size of 1801 MB, meets our expectation of 1024 MB +/- 20

Setting properties from filename 'D:/AEM_Setup/aem-setup/sample install/cq-author-p2400.jar'

Option '-quickstart.server.port' set to '2400' from filename cq-author-p2400.jar

Setting 'sling.run.modes' to 'publish' from command line.

Level 4
November 7, 2018

There are two conflicting articles.

1. Run Modes - docs.adobe.com

2.Set run modes 

bit confused on this.

umangm67314486
November 20, 2017

I tried to work out maximum scenarios and found that when run modes is defined in all places then order of precedence is:

Jar file name  ← JVM parameter (System Property) ← sling property ← -r option

Primary run mode will not change after initial install of aem instance even if we change jar name or JVM parameter. But if we have given different primary run mode in JVM parameter and jar file name at time of initial install then jar file name takes precedence.

November 21, 2017

The run mode specified in the naming of the jar file takes precedence. If run modes are not specified in the naming of the jar file, the values in the sling.properties file are used. If run modes are not specified in either the naming of the jar file or the sling.properties file, the system property (or JVM argument) is used.

For ref: Set run modes

Level 2
February 20, 2020

I know years have passed, but for other people seeing this I will say this. In my experience the system properties have highest precedence for determining runmode. Somewhere above on this page I added a 'full test report' with all my test cases and their results to prove it.

 

So according to my extensive testing the runmode precedence is actually like: system properties (-D) > sling.properties > -r option > JAR filename.

So to me your observation is easily explained assuming you were talking about a fresh installation:

You have 2 types of runmodes:
* installation / fixed (used to be called primary): like author, publish, (no)samplecontent

* custom

 

At start the system will start with a default installation runmode of author, then it will look if your JAR filename matches pattern <prefix>-<installation_runmode>-p<port>.jar. If it does it will use that.

Then it will look for a sling.properties and check system properties.

 

As system properties have the highest precedence that will be used if you set it on the command line. As it takes precedence it means that other means of setting your runmode are actually ignored.

In your case the system properties only mentioned a custom runmode of 'prod', so this is the reason why that custom runmode is showing up in your Felix console of course, but the installation run mode author will likely come from the JAR filename.