Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine runmode in Adobe CQ

How do I programmatically know which run-mode the instance is running? I created a custom tag that provides the config depending on the instance run-mode, but I can not determine the current run-mode.
I found a method that returns a list of run-mods instance:

SlingSettings settings = ...get from BundleContext...
Set<String> currentRunModes = settings.getRunModes();

But I can not get the objects SlingSettings or BundleContext. How can I get these objects or perhaps there is another way to get the current run-mode?

like image 586
Gleb Avatar asked Sep 03 '12 10:09

Gleb


People also ask

How do I check my Runmode in AEM?

Note: Only primary run modes (ex: author,publish) are applicable for renaming jar. 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.

What is Runmode in AEM?

Run modes allow you to tune your AEM instance for a specific purpose; for example author or publish, test, development, intranet or others. You can: Define collections of configuration parameters for each run mode.

How do I change my AEM Runmode?

Important: The run mode of an instance cannot be changed from author to publish, or vice versa, once an AEM instance has been installed. Some run modes, such as the author run mode and the publish run mode, are mutually exclusive. If both are specified, only the first run mode is used.


2 Answers

SlingSetttings is the right way - If it's from Java the simplest way to get it is with an SCR @Reference annotation in a class that's an SCR @Component, saves you from having to go through BundleContext.

If it's from a Sling script, you can use sling.getService(....) to get the SlingSettings.

Note that the cases where you need to read the run modes are rare, usually you'd rather setup your OSGi configurations to depend on the run modes and have the OSGi components modify their behavior based on that.

like image 50
Bertrand Delacretaz Avatar answered Nov 15 '22 16:11

Bertrand Delacretaz


You can also try this:

RunModeService runModeService = getSlingScriptHelper().getService(RunModeService.class);
author = runModeService.isActive("author");
like image 30
Joydeep Bhattacharya Avatar answered Nov 15 '22 15:11

Joydeep Bhattacharya