Gateway shutdown project order

Hello,

I am wondering what the ORDER of project gateway “shutdown” events is on a gateway with multiple projects?

Also, are they synchronous to one another?

I have a gateway with some inheritable projects and some are not.
Each have Gateway Shutdown events.

I KNOW that the Gateway Shutdown event fires each time a project is saved and when the gateway is shutdown. In the event, there is no way to determine if it is firing because of a SAVE of a project or the gateway is actually shutting down.
That is why I created a non-inheritable project with ONLY a Gateway Shutdown Event.

What I need is a way to be the FIRST project to detect the Gateway shutdown, before all other projects.

Thanks

They can all run simultaneous, depending on available cores in the execution manager, and you have no control over the order. Sorry. You will need to re-architect your scripts to tolerate that.

What I have observed in the wrapper.log is that when the gateway is shutdown, it does not FIRST fire the gateway shutdown event. It does that later.

In my case I just happened to have some scripting running when the gateway shut down.
Usually this script takes about 3 seconds to execute. It executes randomly.
So there is a chance that it could be in the middle of execution when the gateway shuts down.
That is exactly what occurred at this time!

However what I noticed is that an exception was raised first.
Then 5 seconds later, the Gateway shutdown event was fired.

I can understand this exception firing since it was executing when the gateway was shut down.
But I would think that the next thing to occur would be the PROJECT gateway shutdown scripts
would fire.
That is not the case.

I did not receive a project gateway shutdown script until 5 seconds AFTER the exception was raised.
In between that time, in the wrapper.log file, the gateway was stopping a lot of modules and such.

From these observations, I am thinking that when the gateway shuts down, it just starts shutting down
and then RANDOMLY fires the project gateway shutdown events whenever it wants to. Regardless
of where it is at in it’s shutdown order. It might be the case that some modules are shutdown before a project gateways shutdown event occurs! Which is what I experienced.

What happens when a gateway shuts down?
Does it first start to go through all modules and shut them down, then disconnect gateway networks, then shutdown opc connections etc.
Maybe I could detect the FIRST thing that the gateway does during a shutdown and use that as my
way to tell when the gateway is shutting down?

thanks

In looking at the wrapper.log file in more detail, I noticed the following was one of the first things to occur:

INFO | jvm 1 | 2021/05/25 06:05:45 | I [IgnitionGateway ] [11:05:44]: Ignition[state=RUNNING] ContextState = STOPPING

I believe this occurred when we stopped the service.
Is there some way I can detect the “ContextState = STOPPING” above?

I took a quick look and it seems the project shutdown scripts are run synchronously with the rest of the gateway shutdown process and serially, but not in any defined order.

Consider adding a shutdown hook to java itself:

https://docs.oracle.com/javase/8/docs/api/java/lang/Runtime.html#addShutdownHook-java.lang.Thread-

Beware of code lifetime issues. You might fire several of these if you don’t actively remove old ones. (system.util.getGlobals() is your friend. Except for some versions of Ignition, where you need to use my LifeCycle module.)

hmmm. So do you have a suggestion of how I can detect when a gateway is shutdown…kind of right at the very beginning?

I can’t think of anything that would guarantee a chance to execute some code before the rest of the gateway has started shutting down.