Gateway Startup script only on actual startup

I recommend setting a flag in the dictionary from system.util.getGlobals() (but beware of breakage in v8.0 not fixed until 8.1). Skip your core logic in your startup event if the flag is already present in that dictionary.

True shutdown is more trouble. I recommend not using the shutdown event, but rather adding a shutdown hook to the Java VM. Do so in the startup event. Consider keeping that logic unconditional in the startup event, so that edits will register any changes made to your hook. Use the getGlobals() dictionary to hold a copy of the hook thread so you can unregister the prior handler if the event re-executes.

If you use a JVM shutdown hook, be sure to follow its rules.