# Gateway Startup script only on actual startup

**URL:** <https://forum.inductiveautomation.com/t/gateway-startup-script-only-on-actual-startup/42744>\
**Category:** Ignition\
**Created:** [January 29, 2021, 3:19pm UTC](https://forum.inductiveautomation.com/t/gateway-startup-script-only-on-actual-startup/42744 "2021-01-29T15:19:14Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 29, 2021, 4:12pm UTC](https://forum.inductiveautomation.com/t/gateway-startup-script-only-on-actual-startup/42744/2 "2021-01-29T16:12:19Z")

</div>

I recommend setting a flag in the dictionary from system.util.getGlobals() (but beware of [breakage](http://forum.inductiveautomation.com/t/system-util-getglobals-not-persisted-across-designer-save/33869/17) 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](https://docs.oracle.com/javase/8/docs/api/java/lang/Runtime.html#addShutdownHook-java.lang.Thread-) 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.

---

_[View the full topic](https://forum.inductiveautomation.com/t/gateway-startup-script-only-on-actual-startup/42744)._
