Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
@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
@Mapperz that link is dead – DPSSpatial Oct 17 '14 at 17:22
new link… – Mapperz Oct 20 '14 at 14:29
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 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

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:

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

##...Perfom geodatabase tasks here

#Restart previously running map services
for mapservice in lstStarted:['D:\GIS\Admin\AGSSOMv10.0\AGSSOM.exe', '-s', mapservice])
share|improve this answer
+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

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)

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

At ArcGIS for Server 10.1+ you can use the ArcGIS Server Administration Toolkit - 10.1+

From the description (emphases mine):

The ArcGIS Server Administration Toolkit provides you the tools and scripts to help you administer your ArcGIS Server. These tools haven been written in Python and connect to the REST Admin of an ArcGIS Server allowing you to quickly and easily perform some common administrative functions, including: - List item

  • Stopping, starting or deleting a service
  • Renaming a service
  • Modifying the log level and clearing old logs
  • Upload and registering an SOE
  • Creating a featureclass from the locations a map service was viewed at (by inspecting the logs)
  • Publishing Service Definitions (.SD)

The tools inside this kit are presented in three main ways: Tools, Code, and standalone executable.

share|improve this answer

As of ArcGIS Server 10.3, several Python-based command line utilities come bundled with ArcGIS server.

Per esri's documentation they are usually installed here:

C:\Program Files\ArcGIS\Server\tools\admin

The manage service utility is great for starting, stopping or deleting services:

python -u admin -p admin -s -n Beirut/Parcels -o start

share|improve this answer
This should be the accepted answer. – Blairg23 Jun 21 at 20:55

Your Answer


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.