Hi,
Run Modes is the most interesting feature in AEM. This allows you to tune your AEM instance for a specific purpose; for e.g., author/publish, QA, development, intranet or others.
Why Run Modes?
Uniquely identify an environment and instances
Unique configurations based on environment
OSGI Component Creation for a specific environment
Bundle Creation for a specific environment
There are two types of run modes:
Primary Run Mode
Secondary Run Mode
Primary Run Modes are:
Author: This instance is used for the complete development and authoring purpose.
Publish: This is the actual environment which can be accessed by end users.
nosamplecontent: This instance is having no sample content(like geometrixx,we-retail not available).It is highly recommended in production environment because it is very secure and it provides no sample configurations.lt makes your instance production ready, by disabling CRXDE lite, webdav etc
samplecontent: having sample content like geometrixx-all package.This is just for the help of developers,not required on any server.
Note: Primary Run Modes can’t be change once the aem jar is started.So at the time of AEM instance startup only, we need to finalize which primary run mode is required.
Combination of primary run modes also happen:
Author+samplecontent
Author+nosamplecontent
Publish+samplecontent
Publish+nosamplecontent
Secondary Run Modes are:
Dev Server
QA Server
UAT Server
Prod Server
We can create our own customized run modes on the basis of location( i.e., us,uk), language or any other basis.
Where we define Run mode?
By Changing in sling:properties file
Steps to follow:
Go to crx-quickstart/conf directory of aem instance and add the below line:
sling.run.modes= author,dev
Fig- Set the run mode in sling.properties file |
Using the -r option: When you start the AEM instance by command prompt then set “-r” option in the command.
Example: java -jar jar-name -r dev,sameplecontent
By Renaming Jar: cq5-<run-mode>-p<port-number>
Example: publish instance : cq5-publish -p4503.jar
Author instance : cq5-author-p4502.jar
Note: Only primary run modes (ex: author,publish) are applicable for renaming jar.
By adding JVM arguments: When you start the AEM instance by command prompt then set the jvm parameter in the command. This will be something like this:
Java -jar JAR_NAME -Dsling.run.modes=publish,prod,us
How to check the run mode of a running AEM instances?
Go to Felix Console.
Go to Status tab in Navigation and click on sling settings option.
Here you can see the Run Modes
Fig - Check the run mode of running AEM instance |
You can directly go to http://localhost:4502/system/console/status-slingsettings
USE CASE OF RUN MODE IN THE PROJECT
Problem Statement:
In Felix Configurations, there is a configuration named as DAY CQ MAIL SERVICE. Now lets say we have a requirement of using smtp.port=25 in author, Dev,US server but smtp.port=465 in Author,QA,UK Server. (Here US and UK are the location of servers)
Solution:
Create Run Modes:
Go to Crxde.
Go to /apps/my-project
Create Configurations for Author,Dev Server which is in US:
Create a folder (sling:folder) with the name config.author.dev.us
Create a sling:osgiConfig type of node named com.day.cq.mailer.DefaultMailService.config.
Note:Node name should be the same name as the Persistent Identity (PID) of the configuration in the OSGi Console.
Add the following properties in this config for Dev Server:
Fig - Adding the mail service configuration for DEV,US run mode |
Run an AEM instance on Author,Dev,US Environment by using any of the option explained above.
Check the run mode of running AEM instance
Fig- AEM instance is in AUTHOR,DEV,US run mode |
Now Check the mail Configurations
|
Create Configurations for Author,QA Server which is in UK:
Create a folder (sling:folder) with the name config.author.qa
Create a sling:osgiConfig type of node named com.day.cq.mailer.DefaultMailService.config
Add the following properties in this config for QA Server:
Fig - Adding the mail service configuration for QA,UK run mode |
Run an AEM instance on Author, QA,UK Environment by using any of the option explained above.
Check the run mode of running AEM instance
Fig- AEM instance is in AUTHOR,QA,UK run mode |
Now Check the mail Configurations in Felix Console
Fig- Check the configuration in felix console for QA,UK run mode aem instance |
The minimum possible configurations for AEM environments.
Fig- Minimal possible configuration in any AEM project |
Note: Every run mode tries to find out the best possible match available for configuration.
If multiple configurations for the same PID are applicable, the configuration with the highest number of matching run modes is applied.
OSGi Component Creation for a specific environment
Run Modes helps to create OSGi component for the specific environment.
Problem Statement: To make OSGi Component to be available only for publish instance.
Solution: To solve this problem, follow these two steps:
Annotate the component with “ConfigurationPolicy.REQUIRE”
Make this configuration available under config.publish.
Sample code of OSGi Component
package com.aem.sgaem.project.services; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.ConfigurationPolicy; import org.apache.felix.scr.annotations.Service; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Component(label = "SGAEM - OSGi Configuration for Publish Run Mode", immediate = true, policy = ConfigurationPolicy.REQUIRE) @Service(ComponentPublish.class) public class ComponentPublish { private static final Logger LOGGER = LoggerFactory.getLogger(ComponentPublish.class); @Activate protected void activate() { LOGGER.debug("Run Modes Activated"); } }
�� Here “policy= ConfigurationPolicy.REQUIRE” means that this component should be available as configuration created under config nodes. But Initially, this configuration will not exist in felix console components
So, to make it visible in Felix console of publish instance, You need to create configuration of this component (using Pid of OSGi Component) under config.publish node.
Fig- Node name same as Pid of OSGi Component |
After addition of this configuration, you can see, the component will be available in Felix console in publish instance.
Note: In other run modes, this component will not get executed because it is specified only for publish instance. If you want to use it in other run modes, you need to make it in other config as well. (eg: config.author,config.qa)
Run Modes is not only used for configurations, they can also be used to differentiate bundles based on the environments.
Isn’t it sounds interesting??
Problem Statement: Let Suppose, You have multiple bundles in a single project. like
“Bundle A” for “Author” Environment.
“Bundle B” for “Publish” Environment
Solution: So we need to make environment specific configuration for install folder.
Install.author (nt:folder)
=> Bundle A.jar
Install.publish (nt:folder)
=> Bundle B.jar
Fig- sgaem-test.jar for author and sgaem-bundle.jar for publish instance |
Note: If you are in publish instance, You will not able to see bundle "sgaem-test" in felix console and vice-Versa for author instance.
Hi,
This is good information for the AEM platform, so I'm moving the post to the platform topic.
This topic is specific to the Communities capability.
- JK
Thanks JK Kendall
Good one Saurabh to put all together related to Run modes at one shot.
Thanks a lot for sharing the information with the community.
Looking foreword to many more such content here.
~kautuk
Views
Replies
Total Likes
Thanks for sharing the information
Thanks.
hi Saurabh,
Thanks for this knowledgeable article can you please add how to read the properties from sling:osgiConfig nodes. I have tried it using the help of ConfigurationAdmin is this only way to read the properties or do we have some other way as well.
Thanks
Sahil Garg
Nice one but it would be wise to see how you could address cloud configuration with run mode such like S&P or facebook or google etc.
Views
Likes
Replies
Views
Likes
Replies