Re-starting a device server using Starter

The following script stops the DGG2/PETRA-3 server and starts it.

#!/usr/bin/env python
import PyTango
import sys
import time

tangoHost = "hasppXX"
starterHost = "hasppXXeh1"
portNo = 10000
serverName = "DGG2/PETRA-3"

try :
    starterProxy = PyTango.DeviceProxy( "//%s:%s/tango/admin/%s" % ( tangoHost, portNo, starterHost))
except :
    print( "Failed with exception !")
    print( sys.exc_info()[0])
    exit

runningServers = starterProxy.command_inout("DevGetRunningServers", True)

if not serverName in runningServers:
    print( " %s not in runningServers" % serverName)
    sys.exit()

starterProxy.command_inout("DevStop", serverName)

while 1:
    stoppedServers = starterProxy.command_inout("DevGetStopServers", True)
    if serverName in stoppedServers:
        break

print( " %s stopped" % serverName)
time.sleep(2)

starterProxy.command_inout("DevStart", serverName)

while 1:
    runningServers = starterProxy.command_inout("DevGetRunningServers", True)
    if serverName in runningServers:
        break

print( " %s started" % serverName)