Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Is it possible to programmatically stop and start ArcGIS Server map services using Python?

share|improve this question
1  
    
@Mapperz Unfortunately the OP is referring to an ESRI-specific web service, not one created as a Windows service running on the desktop. –  Michael Todd Dec 7 '11 at 5:52
add comment

3 Answers 3

up vote 7 down vote accepted

For individual services, such as you could command-line to maintain ArcIMS? No; there is a commandline tool you can download from the Code Gallery (AGSSOM) that gives you the core of major areas.

But there is no granular 'service specific' level control that you can use at this time to Start/Stop/Refresh/Add/Remove AGS services. There is on ideas.arcgis.com several places with requests to improve control of services from a more automatable location.

share|improve this answer
    
Thanks. I found AGSSOM right after I posted. Was still hoping there was a more direct method. However, AGSSOM will work for what I need to do through calls to a batch file from a Python script. –  Jeff Berry Dec 7 '11 at 0:52
    
There are several requests out to ESRI for various options, we will have to see what is really exposed at 10.1 and beyond. –  D.E.Wright Dec 7 '11 at 18:40
add comment

For those that are interested, using AGSSOM as recommended by D.E. Wright, I've put together the following code. This will stop all services allowing you to perform necessary geodatabase tasks, and then restart previously running services.

import os, subprocess

#Get list of currently running map services
stream = os.popen('D:\GIS\Admin\AGSSOMv10.0\AGSSOM.exe -list')
mapservices = stream.readlines()
lstStarted = []

for item in mapservices:
    itemSplit = item.split(',')
    if len(itemSplit) > 1:
        if itemSplit[1].find("Started.") > -1:
            lstStarted.append(itemSplit[0])

#Shutdown all map services
subprocess.call(['D:\GIS\Admin\AGSSOMv10.0\AGSSOM.exe', '-x', '*all*'])

##...Perfom geodatabase tasks here

#Restart previously running map services
for mapservice in lstStarted:
    subprocess.call(['D:\GIS\Admin\AGSSOMv10.0\AGSSOM.exe', '-s', mapservice])
share|improve this answer
1  
+1 Wow; that is very nice; that opens the door to some of the issues people see. It allows you to start creating a tool to do more of those core functions without too much stress. Very nice Jeff! –  D.E.Wright Dec 10 '11 at 21:18
    
Thats pretty cool but stream = os.popen('D:\GIS\Admin\AGSSOMv10.0\AGSSOM.exe -list') dosn't give any results. Out of python 'D:\GIS\Admin\AGSSOMv10.0\AGSSOM.exe -list' give the correct output. Any Suggestions? –  user6687 Apr 2 '12 at 14:50
add comment

In the same vein as what Jeff Berry posted in his answer, I wrote a small function that will manage the map services using the AGSSOM tools. In my case I call services individually by name, stopping and starting one at a time.

import subprocess

def manageMapServices(command, svc, svcType):
    PathToAGSSOM = r"C:\Windows\AGSSOMUtils\AGSSOM"
    server = "AGSSOM"
    p = subprocess.Popen(PathToAGSSOM + " " + server + " " + command + " " + svc + " " + svcType)
    p.wait()

Then, you can call a service by name using -x to stop and -s to start:

manageMapServices("-s", "Folder/Service", "MapServer")
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.