# \[FEATURE\] Gateway startup script - detecting the cause of startup

**URL:** <https://forum.inductiveautomation.com/t/feature-gateway-startup-script-detecting-the-cause-of-startup/65292>\
**Category:** Ignition\
**Tags:** scripting, ignition81\
**Created:** [October 17, 2022, 4:43pm UTC](https://forum.inductiveautomation.com/t/feature-gateway-startup-script-detecting-the-cause-of-startup/65292 "2022-10-17T16:43:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [October 17, 2022, 4:43pm UTC](https://forum.inductiveautomation.com/t/feature-gateway-startup-script-detecting-the-cause-of-startup/65292/1 "2022-10-17T16:43:00Z")

</div>

Since Ignition 8.1.18, **gateway startup** script is executed:

- each time the gateway master or backup became active (before 8.1.18, only the first node becoming active)
- each time shared script lib are saved

It would be usefull if we could have an information to know the **resaon of the startup**.  
For example to avoid to re-execute some traits in the startup script (or all the startup script) if the cause is "shared script lib are saved" which can occur very frequently during development.

We can't achieve this by storing a memory flag "startup-done" with system.util.getGlobals() because we wiuld have to reset it on gateway restart or gateway failover.

---

<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:** [October 17, 2022, 5:23pm UTC](https://forum.inductiveautomation.com/t/feature-gateway-startup-script-detecting-the-cause-of-startup/65292/2 "2022-10-17T17:23:30Z")

</div>

> [@mazeyrat](#):
>
> each time shared script lib are saved

This has always been true. One of the uses of `system.util.getGlobals()` is to place a flag to distinguish the "real" first gateway startup from later ones.

---

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [October 17, 2022, 5:57pm UTC](https://forum.inductiveautomation.com/t/feature-gateway-startup-script-detecting-the-cause-of-startup/65292/3 "2022-10-17T17:57:11Z")

</div>

Yes sure this behavior has not changed.

In my use case, I build some cache data at the gateway startup, I need to rebuild the cache each time the gateway became active. (especially with a redundant gateway).

So the gateway startup is just fine; but I would like to avoid to rebuid my cache each time the script is triggered by lib change and script save.  
If I use a flag, I need to reset it on gateway failover...

Master =\> startup =\> flag True **Failover** =\> Backup =\> startup =\> flag True **Failover** =\> Master flag True ☹ avoid script startup **Failover** =\> backup flag True ☹ avoid script startup.

To achieve my goal, I use a listener for the redundant state change in a module, but it's a bit cumbersome...

If I could know the reason in startup script, (reason = startup, reason = script reload), I could simply do nothing in case of script reload.

I think it could be really usefull in many case where you don't wan't to execute all the startup script at each script save

---

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [October 18, 2022, 6:53pm UTC](https://forum.inductiveautomation.com/t/feature-gateway-startup-script-detecting-the-cause-of-startup/65292/4 "2022-10-18T18:53:24Z")

</div>

You can vote for this:

> **[Gateway startup script - add a parameter with the reason of execution | Voters...](https://ideas.inductiveautomation.com/ignition-features-and-ideas/p/gateway-startup-script-add-a-parameter-with-the-reason-of-execution)**

---

<div class="post-metadata">

**Author:** ![Deville\_Xavier](https://avatars.discourse-cdn.com/v4/letter/d/df705f/32.png) [@Deville\_Xavier](https://forum.inductiveautomation.com/u/Deville_Xavier)\
**Post date:** [July 7, 2023, 11:52am UTC](https://forum.inductiveautomation.com/t/feature-gateway-startup-script-detecting-the-cause-of-startup/65292/5 "2023-07-07T11:52:06Z")

</div>

Hi, I face the same problem. Would it be possible for you to share this module with the community ? Thanks 🙂

> [@mazeyrat](#):
>
> To achieve my goal, I use a listener for the redundant state change in a module, but it's a bit cumbersome...
