Expand my Community achievements bar.

order of precedence of Sling run modes

Avatar

Former Community Member

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%2...
  [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

9 Replies

Avatar

Level 7

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/

Avatar

Level 4

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.

Avatar

Level 2

I have been searching for the answer to this question after the Adobe certification. Could someone from the community update the correct answer here and maybe the documentations too.

smacdonald2008kautuksahni

anjalishyamsundar

Here is the documentation link, which describes the run mode order of resolution.

Run Modes

Starting CQ with a specific run mode

If you have defined configurations for multiple run modes then you need to define which is to be used upon startup. There are several methods for specifying which run mode to use; the order of resolution is:

  1. sling.properties file
  2. -r option
  3. system properties (-D)
  4. Filename detection

Avatar

Level 2

I am sorry, but it seems that this needs to be verified again by one of your sysadmins as I get the impression that incorrect information is being copied over and over, even in the documentation. It is still like this in https://docs.adobe.com/content/help/en/experience-manager-65/deploying/configuring/configure-runmode...

 

I tested it on my local system and it clearly shows precedence is like this: system properties (-D) > sling.properties file > -r option > filename detection.

 

You don't just have to take my word for it, here is my test report so you can reproduce the results or point out where I misinterpreted the results:

 

Tests performed with AEM 6.5 quickjar with running an AEM 6.5.3 author on port 4502 in the background. Primary runmode these days is called 'installation runmode'.

 

TEST CASE 1: FRESH INSTALLATION

filename: aem65-publish-4503.jar
crx-quickstart/conf/sling.properties: sling.run.modes=author,slingprops
-r: author,commandoption
-Dsling.run.modes: author,systemprops

COMMAND: java -jar aem65-publish-4503.jar -r author,commandoption -Dsling.run.modes=author,systemprops

 

RESULTS:

Console

Setting properties from filename 'C:/tools/aem/aem65/lab/test/aem65-publish-4503.jar'
Option '-r' set to 'publish' from filename aem65-publish-4503.jar
Setting 'sling.run.modes' to 'author,slingprops' from sling.properties.
Ignoring value 'author,commandoption' from command line.
Ignoring value 'publish' from filename.


Browser tab opens on port 8080 => hinting installation runmode is author as port 4502 is occupied by my author instance running the background.

 

System overview shows runmodes: author,systemprops

=> It looks like the system properties won the competition here!

 

TEST CASE 2: EXISTING INSTALLATION, but as the documentation states that  -r can be used to activate A custom runmode, I used a single runmode for the -r option (as who know it only supports specifying one runmode)

COMMAND: java -jar aem65-publish-4503.jar -r commandoption -Dsling.run.modes=author,systemprops

 

RESULT

Console
S

etting properties from filename 'C:/tools/aem/aem65/lab/test/aem65-publish-4503.jar'
Option '-r' set to 'publish' from filename aem65-publish-4503.jar
Setting 'sling.run.modes' to 'author,slingprops' from sling.properties.
Ignoring value 'commandoption' from command line.
Ignoring value 'publish' from filename.


Browser tab opens on port 8080 => hinting installation runmode is still author (logical as this can't change after initial installation)

 

System overview still shows runmodes: author,systemprops

=> The system properties are still winning

 

TEST CASE 3: EXISTING INSTALLATION, but only use sling.properties

COMMAND: java -jar aem65-publish-4503.jar

 

RESULT

Console

Setting properties from filename 'C:/tools/aem/aem65/lab/test/aem65-publish-4503.jar'
Option '-r' set to 'publish' from filename aem65-publish-4503.jar
Setting 'sling.run.modes' to 'author,slingprops' from sling.properties.
Ignoring value '' from command line.
Ignoring value 'publish' from filename.

 

 

Browser tab opens on port 8080 => hinting installation runmode is still author (logical as this can't change after initial installation)

System overview shows runmodes: author,slingprops

 

TEST CASE 4: EXISTING INSTALLATION, but add the -r commandline option back

COMMAND: java -jar aem65-publish-4503.jar -r commandoption

 

RESULT

Console

Setting properties from filename 'C:/tools/aem/aem65/lab/test/aem65-publish-4503.jar'
Option '-r' set to 'publish' from filename aem65-publish-4503.jar
Setting 'sling.run.modes' to 'author,slingprops' from sling.properties.
Ignoring value 'commandoption' from command line.
Ignoring value 'publish' from filename.

 

 

Browser tab opens on port 8080 => hinting installation runmode is still author (logical as this can't change after initial installation)

System overview shows runmodes: author,slingprops

=> Looks like the sling properties take precedence over the -r command line option

 

TEST CASE 5: EXISTING INSTALLATION, but now removing the sling.properties and with the -r commandline option

COMMAND: java -jar aem65-publish-4503.jar -r commandoption

 

RESULT

Console

Setting properties from filename 'C:/tools/aem/aem65/lab/test/aem65-publish-4503.jar'
Option '-r' set to 'publish' from filename aem65-publish-4503.jar
Setting 'sling.run.modes' to 'commandoption' from command line.
Ignoring value 'publish' from filename.

 

 

Browser tab opens on port 8080 => hinting installation runmode is still author (logical as this can't change after initial installation)

System overview shows runmodes: author,commandoption

 

=> CONCLUSION: CONSOLE OUTPUT SEEMS TO HINT TOWARDS CORRECT PRECEDENCE (apart from system properties which are not mentioned there)

ACTUALLY: system properties > sling properties > -r command option > filename

 

Strategy to confirm this is to perform subsequent fresh installs with inverted filename runmode this time and by incrementally including the runmode options in the above list back to front.

 

TEST CASE A: FRESH INSTALLATION, only filename runmode specified (no custom runmode can be specified this way)

COMMAND: java -jar aem65-author-p666.jar (basically the same as double clicking the jar file in Windows)

RESULT

Console

Setting properties from filename 'C:/tools/aem/aem65/lab/test/aem65-author-p666.jar'
Option '-quickstart.server.port' set to '666' from filename aem65-author-p666.jar

 

 

Browser tab opens on port 666

System overview shows runmodes: author

 

This is the expected result as this is the default way of working (except for the custom port)

 

TEST CASE B: FRESH INSTALLATION, including the command option -r for setting custom runmode

COMMAND: java -jar aem65-author-p666.jar -r commandoption

RESULT

Console

Setting properties from filename 'C:/tools/aem/aem65/lab/test/aem65-author-p666.jar'
Option '-quickstart.server.port' set to '666' from filename aem65-author-p666.jar
Setting 'sling.run.modes' to 'commandoption' from command line.

 

Browser tab opens on port 666

System overview shows runmodes: author,commandoption

 

=> Proof that the -r command option takes precedence over the filename!

 

TEST CASE B2: FRESH INSTALLATION, including the command option -r for setting custom runmode, but also changing installation runmode

COMMAND: java -jar aem65-author-p666.jar -r publish,commandoption

RESULT

Console

Setting properties from filename 'C:/tools/aem/aem65/lab/test/aem65-author-p666.jar'
Option '-quickstart.server.port' set to '666' from filename aem65-author-p666.jar
Setting 'sling.run.modes' to 'publish,commandoption' from command line.

 

Browser tab opens on port 666

System overview shows runmodes: publish,commandoption

 

TEST CASE C: FRESH INSTALLATION, including sling properties sling.run.modes=publish,slingprops in addition to the commandline option -r

COMMAND: java -jar aem65-author-p666.jar -r publish,commandoption

RESULT

Console

Setting properties from filename 'C:/tools/aem/aem65/lab/test/aem65-author-p666.jar'
Option '-quickstart.server.port' set to '666' from filename aem65-author-p666.jar
Setting 'sling.run.modes' to 'publish,slingprops' from sling.properties.
Ignoring value 'publish,commandoption' from command line.

 

Browser tab opens on port 666

System overview shows runmodes: publish,slingprops

 

=> Proof that the sling properties take precedence over the filename and the -r command option

 

TEST CASE FRESH INSTALLATION, including system property -Dsling.run.modes=publish,systemprops in addition to sling properties sling.run.modes=author,slingprops and commandline option -r
This time I changed the installation runmode mentioned in the sling properties and the commandline option back to author. Should the system properties take precedence over all these as expected from the initial results, this would make it clear where the publish installation runmode would come from.

COMMAND: java -jar aem65-author-p666.jar -Dsling.run.modes=publish,systemprops -r author,commandoption

RESULT

Console

Setting properties from filename 'C:/tools/aem/aem65/lab/test/aem65-author-p666.jar'
Option '-quickstart.server.port' set to '666' from filename aem65-author-p666.jar
Setting 'sling.run.modes' to 'author,slingprops' from sling.properties.
Ignoring value 'author,commandoption' from command line.

 

Browser tab opens on port 666

System overview shows runmodes: publish,systemprops

=> Proof that the system properties take precedence over the sling.properties file, the -r command option and JAR filename

 

TO CLOSE THE ISSUE FULLY, WILL NOW PERFORM THE SAME WITH THE EXISTING INSTALLATION

 

TEST CASE E: EXISTING publish INSTALLATION, only filename runmode specified (no custom runmode can be specified this way)
Made sure to comment out the sling.run.modes property in the crx-quickstart\conf\sling.properties file

COMMAND: java -jar aem65-author-p666.jar (basically the same as double clicking the jar file in Windows)

RESULT

Console

Setting properties from filename 'C:/tools/aem/aem65/lab/test/aem65-author-p666.jar'
Option '-quickstart.server.port' set to '666' from filename aem65-author-p666.jar

 

Startup removes the commented line #sling.run.modes=author,slingprops from the sling.properties file!

 

Browser tab opens on port 666

System overview shows runmodes: publish

 

=> This is logical as a installation run mode can't be changed after installation. So the 'author' run mode from the file name is actually not impacting the instance runmode. The fact that the custom run mode 'systemprops' is no longer active is simply because it is no longer specified. It wasn't persisted anywhere as it was only specified on the command line.

 

TEST CASE F: EXISTING publish INSTALLATION, including the command option -r for setting custom runmode, but also attempting to set installation runmode just to make sure
Still no run modes specified in sling.properties!

COMMAND: java -jar aem65-author-p666.jar -r author,commandoption

RESULT

Console

Setting properties from filename 'C:/tools/aem/aem65/lab/test/aem65-author-p666.jar'
Option '-quickstart.server.port' set to '666' from filename aem65-author-p666.jar
Setting 'sling.run.modes' to 'author,commandoption' from command line.

 

Browser tab opens on port 666

System overview shows runmodes: publish,commandoption

 

=> Installation run mode still doesnt change after installation, but we now have a custom runmode again. But as this is the only place where a custom runmode is specified, it is the one from the -r command line option.

 

TEST CASE G: EXISTING publish INSTALLATION, including sling properties sling.run.modes=author,slingprops in addition to the commandline option -r
Added line sling.run.modes=author,slingprops at the bottom of the sling.properties file.

COMMAND: java -jar aem65-author-p666.jar -r author,commandoption

RESULT

The startup process moves the sling.run.modes property from the bottom of the sling.properties file to line 17. So this file is indeed being rewritten with every server startup!

Console

Setting properties from filename 'C:/tools/aem/aem65/lab/test/aem65-author-p666.jar'
Option '-quickstart.server.port' set to '666' from filename aem65-author-p666.jar
Setting 'sling.run.modes' to 'author,commandoption' from command line.

Browser tab opens on port 666

System overview shows runmodes: publish,slingprops

 

=> Installation run mode still doesnt change after installation, but again we have proof that the sling properties take precedence over the -r command option as now the custom runmode comes from the sling.properties file.

 

TEST CASE H: EXISTING publish INSTALLATION, including system property -Dsling.run.modes=author,systemprops in addition to sling properties sling.run.modes=author,slingprops and commandline option -r
This time I also changed the installation runmode mentioned in the system properties to author. This shouldn't matter as installation run modes can't be changed after installation.

COMMAND: java -jar aem65-author-p666.jar -Dsling.run.modes=author,systemprops -r author,commandoption

RESULT

Console

Setting properties from filename 'C:/tools/aem/aem65/lab/test/aem65-author-p666.jar'
Option '-quickstart.server.port' set to '666' from filename aem65-author-p666.jar
Setting 'sling.run.modes' to 'author,slingprops' from sling.properties.
Ignoring value 'author,commandoption' from command line.

Browser tab opens on port 666

System overview shows runmodes: publish,systemprops


=> Installation run mode still doesnt change after installation although the system properties mention runmode 'author' + Proof that the system properties take precedence over the sling properties and the -r command option as now the custom runmode comes from the system properties mentioned on the command line.

Avatar

Level 1

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.

Avatar

Level 1

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

Avatar

Level 2

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.