SOLUTION: Using AGSSOM in python to start/stop AGS 10.0 services

Discussion created by rastrauch Champion on Sep 21, 2011
Latest reply on Aug 17, 2012 by sarbajit
I found the AGSSOM script in the Code Gallery is a great utility for starting/stopping AGS services
http://resources.arcgis.com/gallery/file/net-web-adf/details?entryID=16BABD9A-1422-2418-8828-AC5EE09678BA  at the cmd/DOS window.  What I was looking for was a way to automate this in Python (specifically, stop a list of services so I could update data sources without locks, and restart the services).

After much effort and some technical help (from DreamInCode and Esri), it works.  I thought I would include the minimum code here in case it will help others.   I have not included the "for x in List" portion, but I can if that would be helpful for others. This also works for services within specific subfolders.  BTW - it uses what python.org says is obsolete (os.system), but I could not get the replacement (subprocess.Popen) to work sucessfully.

import arcpy
import os
from os import system
commandLine = "c:\\ArcGIS\\AGSSOM\\bin\\x86\\Release\AGSSOM \\myServerName  -x  myServiceFolder/myServiceName MapServer
stopService = os.system(command_line)
if not stopService:
    print "OK"
    arcpy.AddMessage("not stopped")
    print "not stopped"
#end of code

The if...else is in there just so I can see what it does.

Initialization is extremely slow (90 seconds?) if you have Geoprocessing-Geoprocessing Options-Background Processing checked, so you can either just be patient and wait for it, or uncheck it and it zips along...at lesat after running it once.  I personally like it checked for my other scripts.

I placed my AGSSOM folder under c:\ArcGIS.  If you located it somewhere else, make sure to change the path.  Placing it in the "path" variable and/or in the system folder didn't seem to work.  I may look into it again, but this works so maybe not.  I'm running on a Win7 64 bit, accessing the services on a Win2008 64-bit server.  Just FYI.

To start the services, replace the "-x" with "-s".   I also plan to try to build the list from the -list command, but haven't got far yet. 

I hope this helps others.  -ras
p.s.  I don't expect this to work "as is" in 10.1 due to python and administration changes, but I think it will be easier anyway.

I put this under the wrong forum heading.....it should be under ArcGIS Server - General .   If someone at esri can move it.  thanks...-ras