Starting and stopping ArcGIS Server map services using Python?

For those that are using ArcGIS 10.0, and interested in 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])

At ArcGIS 10.0, for individual services, such as you could command-line to maintain ArcIMS, 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.


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 manageservice.py -u admin -p admin -s http://gisserver.domain.com:6080 -n Beirut/Parcels -o start