Redundancy : trigger failover by scripting

Hello,

Is it possible to trigger a failover using scripting ?

Thanks !

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.

Can you explain what you use case for this is?

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

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.

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).

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.

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

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.

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 ?

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

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).

3 Likes

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.

2 Likes

thank you

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

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

1 Like

Hello,

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

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.

1 Like

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.

1 Like