Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Detect instance runmode programmatically in AEM as cloud service

Avatar

Level 6

Hi All,

 

Is there any alternative to detect run-mode of instance in AEM as cloud service as slingSettingsService shows as deprecated?

 

The use case is to execute code only on author or publish instances but not both.

 

Thanks,

Ram

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Not sure if this blog article has been specifically been written for you But it adresses your question quite good:

 

https://blog.osoco.de/2021/07/the-truth-about-aem-run-modes/

 

 

View solution in original post

3 Replies

Avatar

Community Advisor

Hi @rampai 

 

The solution is still in planning phase and no API is exposed like SlingSettingService to get the run mode.

https://github.com/Adobe-Consulting-Services/acs-aem-commons/issues/2476

 

In the mean time you can create an OSGi service and set the run mode config value in OSGi configuration and read it in your code. That should resolve the issue.

Here is an article which will give a good idea:

https://cqdump.joerghoh.de/2018/09/12/referencing-runmodes-in-java/

 

Thanks!

Avatar

Community Advisor

Hello,

 

Please check https://medium.com/adobetech/custom-runmodes-on-aem-as-a-cloud-service-79b757f51a6b for custom runmodes (not to be used or used cautiously) which discusses about some good practices.

It seems to provide an example of refactored code.

From the reference above, we can try this

@Property(label = "Environment Type",
        description = "Should be dev/stage/prod/local - default is local")
private static final String ENVIRONMENT_TYPE = "environment.type";
private String environmentType;

@Activate
@Modified
protected void activate(final Map<String, String> config) {
    environmentType = PropertiesUtil.toString(config.get(ENVIRONMENT_TYPE), DEFAULT_ENVIRONMENT_TYPE);
    log.debug("Environment Type Service Activated with Environment Type of {}", environmentType);
}



public String getEnvironmentType() {
    return environmentType;
}

Avatar

Correct answer by
Employee Advisor

Not sure if this blog article has been specifically been written for you But it adresses your question quite good:

 

https://blog.osoco.de/2021/07/the-truth-about-aem-run-modes/