How to Run Services at Startup in Moqui

Hello Moqui Community,

I need to run certain services when Moqui starts up to initialize settings and seed data. I’m looking for the best way to do this and any advice on handling it efficiently.

Specifically, I’d like to know:
What’s the most effective method to run services at startup?
Are there any issues to watch out for, like running services repeatedly?
Any guidance or examples would be greatly appreciated!

Thank you!

1 Like

On the run command on the server you can specify an additional parameter to make it look like this:

java -cp . MoquiStart port=80 types=seed

See this for more info on the parameters possible: moqui-framework/framework/src/start/java/MoquiStart.java at 60dd57c890c1083de5f182b595226508725c885f · moqui/moqui-framework · GitHub

To run a service on startup, my favorite way is to manually run a service in the data files. Once you’ve gotten your seed data running on startup, you would add a line into the file that looks like this (link):

<entity-facade-xml type="seed">
    <mantle.party.PartyServices.create-Account firstName="John" lastName="Doe"/>
</entity-facade-xml>
1 Like

Thanks for your help :heart: How can I access the output values of a service that runs at startup?

Hi @Mathan

The whole idea of data loading is for things to run themselves. If on the other hand you want the output from one service to put it in another service or something then at that point this is complexity that goes beyond what the data loading system is designed for. If you need a more elaborate logic, then one possibility is to create a higher level service that then chains the service calls however you want.

2 Likes

Thank you, @taher, for the quick response :smiley:
I understand now that the data loading system is designed for automatic, standalone execution without output handling between services. I was considering creating a higher-level service to manage any necessary chaining and output handling, so your advice confirms that this is the right direction.

Thanks again for the clarification!

1 Like