May 17, 2020
Estimated Post Reading Time ~

Run Modes in AEM

Run modes in AEM allow you to configure AEM instances for specific purposes.
For example, We can configure environment-specific OSGI Services metadata manually from Felix console, But the problem here is whenever a new build is deployed the OSGI metadata reset to default values, so again we have to configure. Instead of doing manually in Felix console, we can create run mode config nodes in repository, the sling will take this configuration automatically when we start the instance or config node update based on run mode values.

Run Mode types in AEM:
There are two types of run modes.
Standard run modes – author,publish,samplecontent,nosamplecontent
Custom run modes – dev,qa,stage,prod ..etc.

Standard run modes set up:
We can configure standard run modes directly by renaming jar file, Standard run modes are used at installation time and then fixed for the entire lifetime of the instance, they cannot be changed.

The naming convention to for AEM 5.6.1 and later is:

aem-<optional-version-or-indentifier>-<standard-run-mode>-<port-number>

1. author – Run mode for the author instance.
2. publish – Run mode for publish instance.
3. samplecontent – Run mode will install sample content.
4. nosamplecontent – Run mode will not install sample content.

Custom run modes set up:
We can define custom run modes in different ways, below are ways.

Using the sling.properties file :
The sling.properties file can be used to define the required run mode:
Edit the configuration file:
<cq-installation-dir>/crx-quickstart/conf/sling.properties
Add the following properties; the following example is for author:
sling.run.modes=author

Using the -R option:
A custom run mode can be activated by using the -r option when launching the quickstart. For example, use the following command to launch an AEM instance with run mode set to dev.

java -jar cq-56-p4545.jar -r dev

Using a system property in the start script:
A system property in the start script can be used to specify the run mode.
For example, use the following to launch an instance as a production publish instance located in the US:

-Dsling.run.modes=publish,prod,us

Order of precedence of run modes:
Here my question is what happens if we did all the above custom run mode configuration at a time, which one will take precedence.

below are the order of precedence of run modes.
Start jar (by double-clicking) – In this, you do not have the option to set the run mode in a sling.properties, start script first time. JAR's name takes precedence.
Unpack jar and specify run mode as system properties in start script – JAR name doesn’t come to picture here. In this, you do not have the option to set the run mode in sling.properties. System properties take precedence.
Even if we change the run mode in JAR name, it doesn’t change the installation time run mode. For custom run mode, the JAR file name is not applicable. Order of precedence is sling.properties -> specifying -r option (command line jar option) -> system properties (start script).

Read Sling run modes in Java:
We can read sling run modes directly from the SlingSettingsService OSGI service.

[code language=”java”] import org.apache.sling.settings.SlingSettingsService;[/code]

[code language=”java”]@Reference
private SlingSettingsService slingSettingsService;[/code]

[code language=”java”]slingSettingsService.getRunModes(); [/code]


By aem4beginner

No comments:

Post a Comment

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