# GatewayHook initializeScriptManager lifecycle question

**URL:** <https://forum.inductiveautomation.com/t/gatewayhook-initializescriptmanager-lifecycle-question/100872>\
**Category:** Module Development\
**Tags:** ignition81\
**Created:** [January 14, 2025, 5:53pm UTC](https://forum.inductiveautomation.com/t/gatewayhook-initializescriptmanager-lifecycle-question/100872 "2025-01-14T17:53:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sholom\_Ellenbogen1](https://avatars.discourse-cdn.com/v4/letter/s/d2c977/32.png) [@Sholom\_Ellenbogen1](https://forum.inductiveautomation.com/u/Sholom_Ellenbogen1)\
**Post date:** [January 14, 2025, 5:53pm UTC](https://forum.inductiveautomation.com/t/gatewayhook-initializescriptmanager-lifecycle-question/100872/1 "2025-01-14T17:53:07Z")

</div>

I am having a problem where the script manager doesnt seem to be initializing properly sometimes which makes me think it might be a race condition in the startup of my module. At what point in the gateway starting lifecycle is this initializeScriptManager called?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [January 14, 2025, 5:56pm UTC](https://forum.inductiveautomation.com/t/gatewayhook-initializescriptmanager-lifecycle-question/100872/2 "2025-01-14T17:56:02Z")

</div>

After `setup`, and then again any time as needed, e.g. modules stopped/started, gateway scripting project changing, whatever.

---

<div class="post-metadata">

**Author:** ![Sholom\_Ellenbogen1](https://avatars.discourse-cdn.com/v4/letter/s/d2c977/32.png) [@Sholom\_Ellenbogen1](https://forum.inductiveautomation.com/u/Sholom_Ellenbogen1)\
**Post date:** [January 14, 2025, 5:58pm UTC](https://forum.inductiveautomation.com/t/gatewayhook-initializescriptmanager-lifecycle-question/100872/3 "2025-01-14T17:58:52Z")

</div>

is that before `startup` then or after that?

---

<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 14, 2025, 6:01pm UTC](https://forum.inductiveautomation.com/t/gatewayhook-initializescriptmanager-lifecycle-question/100872/4 "2025-01-14T18:01:40Z")

</div>

Setup \>\> Startup \>\> Shutdown

"After Setup" doesn't mean "After Startup". And it is called many times after that as you edit projects.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [January 14, 2025, 6:04pm UTC](https://forum.inductiveautomation.com/t/gatewayhook-initializescriptmanager-lifecycle-question/100872/5 "2025-01-14T18:04:51Z")

</div>

In practice I think it's between `setup` and `startup` the first time, then possible again any time after.

But the docs suggest the only guarantee you get is after `setup`.

---

<div class="post-metadata">

**Author:** ![Sholom\_Ellenbogen1](https://avatars.discourse-cdn.com/v4/letter/s/d2c977/32.png) [@Sholom\_Ellenbogen1](https://forum.inductiveautomation.com/u/Sholom_Ellenbogen1)\
**Post date:** [January 14, 2025, 6:12pm UTC](https://forum.inductiveautomation.com/t/gatewayhook-initializescriptmanager-lifecycle-question/100872/6 "2025-01-14T18:12:23Z")

</div>

Ah I see, that might be my issue. I initialize my spring context in the `startup` not in `setup`. I wonder if after `setup` is done I have `startup` and `initializeScriptManager` running at the same time and there being a race condition.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 14, 2025, 6:20pm UTC](https://forum.inductiveautomation.com/t/gatewayhook-initializescriptmanager-lifecycle-question/100872/7 "2025-01-14T18:20:18Z")

</div>

> [@Sholom\_Ellenbogen1](#):
>
> spring

🙈

I've never seen anyone have much luck trying to embed Spring inside Ignition via a module.

---

<div class="post-metadata">

**Author:** ![Sholom\_Ellenbogen1](https://avatars.discourse-cdn.com/v4/letter/s/d2c977/32.png) [@Sholom\_Ellenbogen1](https://forum.inductiveautomation.com/u/Sholom_Ellenbogen1)\
**Post date:** [January 15, 2025, 12:21am UTC](https://forum.inductiveautomation.com/t/gatewayhook-initializescriptmanager-lifecycle-question/100872/8 "2025-01-15T00:21:41Z")

</div>

haha, yeah its not easy but it does seem to be working now. I think it was the spring context not being initialized in time.
