Core: ModuleFactory should check whether GP 'module.isStarted' already exists

Hi all / @dkayiwa,

I’m talking about this:

// save the state of this module for future restarts
saveGlobalProperty(moduleId + ".started", "true", ...); 

What if the GP moduleId + ".started" already exists and is already set to be false? ModuleFactory#startModuleInternal would just override it to be true without asking…

In one of our CI envs we anticipate that a certain module will be there and we want to disable it in advance under certain circumstances by toggling the GP to false (even before it’s ever created by Core.)

Cc @frederic.deniger @mddubey

1 Like

Because of this basically in ModuleFactory#saveGlobalProperty:

if (gp == null) {
    gp = new GlobalProperty(key, value, desc);
} else {
    gp.setPropertyValue(value);
}

Thanks @mddubey for pointing me to the exact block :wink:

Any module with that property set to false, will not be started by the openmrs platform, according to this method: https://github.com/openmrs/openmrs-core/blob/2.3.0/api/src/main/java/org/openmrs/module/ModuleFactory.java#L277-L303

FWIW, this is the module startup order:

Therefore, the line you brought up, will be run only by those modules which either do not have that global property, or have it with a value of true.

Thanks @dkayiwa!

@frederic.deniger can you confirm?

Hello Dimitri and Daniel,

it’s not what I noticed in our deployment process:

  1. before starting OpenMRS, a script deactivates the plugin with UPDATE global_property gp SET property_value = 'false' WHERE property = 'oauth2login.started';. It’s a script included in our Docker image.
  2. FYI, the module is included as a bundle. Maybe it changes some order in the initalisation process
  3. The module is started despite the property oauth2login.started set to false
  4. I restart OpenMRS ( a docker-compose restart) and the module is deactivated

I will try to check it again but as I run the exact same scripts I believe that, at the first time, the property is resetted somewhere.

Thanks for your help

You probably set the property late after OpenMRS has already started.

Will try again but the script setting the property is called before OpenMRS is started

image

Ok I found my issue: SQL. UPDATE global_property gp SET property_value = 'false' WHERE property = 'oauth2login.started'; will do nothing if the property is not present.

Sorry for the noise concerning this point.

1 Like

FYI, here is the updated script I used to create or update the oauth2login.started GP:

INSERT INTO global_property (uuid, property, property_value) VALUES('b4129999-eede-4588-8764-696b9a8e6e5a','oauth2login.started' ,'false') ON DUPLICATE KEY UPDATE property='oauth2login.started', property_value='false';

Thanks

1 Like