# Redundancy : trigger failover by scripting

**URL:** <https://forum.inductiveautomation.com/t/redundancy-trigger-failover-by-scripting/63137>\
**Category:** Ignition\
**Created:** [August 18, 2022, 7:20am UTC](https://forum.inductiveautomation.com/t/redundancy-trigger-failover-by-scripting/63137 "2022-08-18T07:20:14Z")\
**Posts on this page:** 16\
**Page:** 1

<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:** [August 18, 2022, 7:20am UTC](https://forum.inductiveautomation.com/t/redundancy-trigger-failover-by-scripting/63137/1 "2022-08-18T07:20:14Z")

</div>

Hello,

Is it possible to trigger a failover using scripting ?

Thanks !

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [August 18, 2022, 1:03pm UTC](https://forum.inductiveautomation.com/t/redundancy-trigger-failover-by-scripting/63137/2 "2022-08-18T13:03:15Z")

</div>

not sure about newer versions but in older versions on a project that I setup with redundancy I would call a batch file thru a gateway script that would stop the gateway service. this was on the primary gateway. You would have to manually start it back up to fail back to primary.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 18, 2022, 2:01pm UTC](https://forum.inductiveautomation.com/t/redundancy-trigger-failover-by-scripting/63137/3 "2022-08-18T14:01:06Z")

</div>

Can you explain what you use case for this is?

---

<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:** [August 18, 2022, 2:04pm UTC](https://forum.inductiveautomation.com/t/redundancy-trigger-failover-by-scripting/63137/4 "2022-08-18T14:04:43Z")

</div>

Thanks for the idea but I would like to force the failover without shutting down the gateway.

---

<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:** [August 18, 2022, 2:11pm UTC](https://forum.inductiveautomation.com/t/redundancy-trigger-failover-by-scripting/63137/5 "2022-08-18T14:11:22Z")

</div>

I need to force a failover, the same action done by the event of pressing the button in the redundancy settings in the gateway. But I would like to trigger this action by scripting so that it is not necessary to log to the gateway settings.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 18, 2022, 2:19pm UTC](https://forum.inductiveautomation.com/t/redundancy-trigger-failover-by-scripting/63137/6 "2022-08-18T14:19:47Z")

</div>

> [@Deville\_Xavier](#):
>
> I would like to force the failover without shutting down the gateway.

That isn't how Ignition's redundancy works. The Gateway service hast be stopped in some way for a failover to occur. There is no scripting method available that will, by it's self, stop the Gateway Service (for obvious reasons).

> [@Deville\_Xavier](#):
>
> I need to force a failover

Okay, but why? I understand what you would like to accomplish, but I don't understand what you are trying to determine by forcing a failover.

---

<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:** [August 18, 2022, 2:57pm UTC](https://forum.inductiveautomation.com/t/redundancy-trigger-failover-by-scripting/63137/7 "2022-08-18T14:57:24Z")

</div>

> [@lrose](#):
>
> I don’t understand what you are trying to determine by forcing a failover.

It is our customer specification, for instance we would like to trigger a failover if the master's CPU is above a certain value.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 18, 2022, 3:08pm UTC](https://forum.inductiveautomation.com/t/redundancy-trigger-failover-by-scripting/63137/8 "2022-08-18T15:08:14Z")

</div>

~~The only way to force a failover is to shutdown the gateway service.~~

You could use `system.util.sendMessage()` to send a message handler on the gateway and then use `system.util.execute()` to run the gateway shutdown `.bat` (on windows) file.

You would still have to manually restart the service.

~~However, I wouldn’t recommend this. If you need to force a failover due to some OS issue, then you need to be looking at the OS at which point you can just run the shutdown script manually.~~

EDIT: Nope, I’m just wrong.

---

<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:** [August 18, 2022, 3:18pm UTC](https://forum.inductiveautomation.com/t/redundancy-trigger-failover-by-scripting/63137/9 "2022-08-18T15:18:17Z")

</div>

Thank you for your answer. So the action performed by the gateway when the button"forceFailover" is pressed is only to stop and start the active gateway ?

---

<div class="post-metadata">

**Author:** ![kcollins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kcollins/32/19646_2.png) [@kcollins](https://forum.inductiveautomation.com/u/kcollins)\
**Post date:** [August 18, 2022, 3:32pm UTC](https://forum.inductiveautomation.com/t/redundancy-trigger-failover-by-scripting/63137/10 "2022-08-18T15:32:36Z")

</div>

We don’t currently have a supported mechanism for this, but the most basic action can be achieved with:

```python
from com.inductiveautomation.ignition.gateway.redundancy.types import ActivityLevel
from com.inductiveautomation.ignition.gateway import IgnitionGateway

redundancy_manager = IgnitionGateway.get().getRedundancyManager()
redundancy_manager.requestPeerActivityLevel(ActivityLevel.Active)

```

The above effectively requests the peer to become Active. There are some _System_ tags available for discovering the current state of redundancy (that might be handy for deciding when to invoke the above).

---

<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:** [August 18, 2022, 7:32pm UTC](https://forum.inductiveautomation.com/t/redundancy-trigger-failover-by-scripting/63137/11 "2022-08-18T19:32:40Z")

</div>

> [@lrose](#):
>
> The only way to force a failover is to shutdown the gateway service.

This is not correct. That action is in the gateway web interface, so there clearly has to be code in java to make it happen.

---

<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:** [August 19, 2022, 6:51am UTC](https://forum.inductiveautomation.com/t/redundancy-trigger-failover-by-scripting/63137/12 "2022-08-19T06:51:36Z")

</div>

thank you

---

<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:** [October 19, 2022, 8:14am UTC](https://forum.inductiveautomation.com/t/redundancy-trigger-failover-by-scripting/63137/14 "2022-10-19T08:14:19Z")

</div>

This works well, is there a way to set the Redundancy mode to Independent by scripting ?

---

<div class="post-metadata">

**Author:** ![kcollins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kcollins/32/19646_2.png) [@kcollins](https://forum.inductiveautomation.com/u/kcollins)\
**Post date:** [October 19, 2022, 2:18pm UTC](https://forum.inductiveautomation.com/t/redundancy-trigger-failover-by-scripting/63137/15 "2022-10-19T14:18:26Z")

</div>

> [@Deville\_Xavier](#):
>
> set the Redundancy mode to Independent by scripting ?

No, redundancy roles are something that are intended to be fixed.

---

<div class="post-metadata">

**Author:** ![e.sagnelonge](https://avatars.discourse-cdn.com/v4/letter/e/7cd45c/32.png) [@e.sagnelonge](https://forum.inductiveautomation.com/u/e.sagnelonge)\
**Post date:** [November 8, 2022, 1:21pm UTC](https://forum.inductiveautomation.com/t/redundancy-trigger-failover-by-scripting/63137/16 "2022-11-08T13:21:36Z")

</div>

Hello,

You can do this by changing the NodeRole of your redundancy using the RedundancyManager from a Gateway scope.

```auto
from com.inductiveautomation.ignition.gateway.redundancy.types import NodeRole
from com.inductiveautomation.ignition.gateway import IgnitionGateway

redundancyManager = IgnitionGateway.get().getRedundancyManager() #RedundancyManager
settings = redundancyManager.getSettings() #RedundancySettings

#NodeRole
settings.setNodeRole(NodeRole.Independent)
#settings.setNodeRole(NodeRole.Master)
#settings.setNodeRole(NodeRole.Backup)

redundancyManager.applySettings(settings)

```

I only tried it on Ignition 8.1.22.

---

<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:** [November 8, 2022, 1:38pm UTC](https://forum.inductiveautomation.com/t/redundancy-trigger-failover-by-scripting/63137/17 "2022-11-08T13:38:46Z")

</div>

Be aware that licensed backup gateways are locked to the backup role. Changing it via scripting won't permanently stick, if it works at all.
