I have glanced through many Gateway startup script questions, some of which don't even have answers, so I'm guessing the community is tired of looking at them, but here's mine. I recently upgraded to v8.3, but I doubt that is the cause of my issue.
I would like to disable the device connections to my PLC's on startup if Ignition is NOT running on my production server. This is for when I restore a backup to a test machine or clone the production server VM for testing. I have some datalogging that does handshaking with the Ignition server, and when other machines start sending the handshakes, madness ensues (among other issues).
I created a separate project just for Gateway events so I don't lose track of where I put the events.
Here is my Gateway startup script. When testing on the weekends, I replace the != with == to verify it works.
def onStartup():
srvr= system.net.getHostName()
lgr = system.util.getLogger("GatewayStartupCheck")
lgr.info("Server name was found to be " + srvr + " BEFORE disabling devices")
if srvr != 'PAS-OT-IGN':
lgr.info("Server name matched 'PAS-OT-IGN' so disabling devices")
deviceDataset = system.device.listDevices()
lgr.info("Fetched device dataset")
for rw in deviceDataset:
lgr.info("Processing " + rw["Name"])
system.device.setDeviceEnabled(rw["Name"], 0)
The script works because every time I save the project with the change, my devices end up disabled and I see all of the log entries. However, when I actually restart the gateway I only get
"Server name was found to be PAS-OT-IGN BEFORE disabling devices"
and
"Server name matched 'PAS-OT-IGN' so disabling devices"
Since I don't get
"Fetched device dataset"
I conclude that the command
system.device.listDevices()
is stopping execution while other services are starting up. I was thinking that something like
system.util.invokeLater
would be handy, but that is gone in v8.3 and only worked in the Vision client context anyway.
I could put the code in a timer script I guess, but it seems messy to be running it every X milliseconds, and if I run it infrequently enough, then some of the damage will get done before it executes for the first time.
Can anyone see something I missed or have a better idea?
An obvious answer is to restore a backup to a machine that can't reach the PLCs first and then disable everything. That's quite a bit of work when I'm doing frequent restores and will often require the help of our IT department, which has limited resources (meaning I have to wait when I really need to keep iterating when I am catching bugs).