Restart module in a Script or in Command Line scripts

Looks like it has been asked twice now with no results or help, I am wondering if anyone has figured out an answer to either of these posts?

We have a scenario where the gateway comes online and sometimes the OPC server seems to fault out on powering up. We would like to check that status and restart the OPC module.

1 Like

setSeverEnabled on false than true probably triggers a restart for that connection idk
(most other connection services have a similar function)
https://docs.inductiveautomation.com/display/DOC81/system.opc.setServerEnabled

That function controls Ignition’s connections to servers, not the native OPC server itself.

You are correct that is just for the connection and not the module it self. The issue happened again this morning which required a user to login into the plc and get the module restarted, kind of annoying problem a larger system issue I need to dig into.

Hm:/
You can run scripts in cmd with
https://docs.inductiveautomation.com/display/DOC81/system.util.execute
Maybe there is a way to restart the server through the command prompt

Ok so I guess that leads back to my original question can you restart a module with command line scripts? I know you can do this but how does it interact with a module?

Not an external script. A gateway scoped jython script can do it, if you go far enough under the hood, to the ModuleManager class’s restartModule() method.

You get the ModuleManager from the GatewayContext.

Any of this is utterly unsupported and the API can be changed at IA’s whim.

The OPC server itself doesn't have any status that could be "faulted".

Either an OPC connection is faulted for some reason, or the entire module failed to start. Can you confirm which it is, and if it's somehow the whole module provide some logs from startup?

hmm what if you let the command prompt surf to the accept button to the correct module?
you’ll have to get the link for your own server tho as the numbers probably change depending on number of modules you have

I am thinking its failing to start outright? Here is the wrapper log I grabbed quick. wrapper.log.txt (864.9 KB)

Okay, I see… sometimes when the module starts up it fails to bind to the configured ports because they are still in use or being held onto by the OS… :thinking:

So little more transparency this is a Beckhoff unit. I am wondering for some reason if Twincat consumes that port on start up for its OPC server it has on another port and then creates like a race condition if its not released soon enough ignition will fail.

Maybe, I don’t have any experience with those. I feel like I’ve seen this once or twice before and it’s just a consequence of running on Windows and its mediocre TCP stack.

I’ll poke around and see if there’s anything different we can be doing on our side to help.

1 Like

Ok so I gave the system a restart after disabling the twincat OPC start up and ignition came back on fine, so I am guess running the service with a delayed start up the race condition will be solved. such a interesting scenario

How would you access theses functions?

import com.inductiveautomation.ignition.gateway.model

returns
ImportError: No module named model

Are you running the script in the gateway? (Not in the script console… that is designer scope.)

Wanted to comment with a solution here.
First steps are getting the module ID that needs to be reset.

#this can be removed once the ID is known
#start a logger to get to get the IDs of the installed modules, this will output to the gateway logs
logger = system.util.getLogger("myLogger")
#this will print all the 
results = system.util.getModules()
for row in range(results.rowCount):
	names = results.getValueAt(row, "Id")
	logger.info(names)

From this the following script can be used to reset the module. This has to be run somewhere that is gateway scoped for scripting.

#Import Java Libraries
import java.util

#Import Inductive Libraries
from com.inductiveautomation.ignition.gateway import IgnitionGateway
from com.inductiveautomation.ignition.gateway.model import ModuleManager
	
#Instantiate Gateway and Module Manager
IGW = IgnitionGateway.get()
moduleManager = IGW.getModuleManager()

#Declare the  module ID as a string
moduleID = 'MODULE ID FROM LOGS HERE'
#Reset the module
moduleManager.restartModule(moduleID)
1 Like