HOW TO

Stop GIS services using ArcGIS API for Python

Last Published: February 27, 2025

Summary

ArcGIS Server services can be stopped from ArcGIS Server Manager, ArcCatalog, or the catalog window in ArcMap. In some cases, there may be several services that must be stopped, and stopping them manually is tedious. For federated ArcGIS Servers, the ArcGIS API for Python's stop() function may be used to automate the process.

Procedure

The steps describe how to stop services in a GIS folder using the stop() function.

  1. Import the necessary libraries.
from arcgis.gis import GIS
import arcgis.gis.admin
  1. Specify the GIS server details.
gis = GIS("<portal url>", "<portal admin username>", "<portal admin password>")
Note:
To bypass the certificate verification, add the parameter, 'verify_cert=False'.
  1. Retrieve available folders in the server, and specify it in a parameter.
gis_servers = gis.admin.servers.get(role="HOSTING_SERVER")
Note:
If the desired server folder array location is known in the list, the script can be modified to:

gis_servers = gis.admin.servers.get(role="HOSTING_SERVER")[0]

"[0]" can be modified to specify the exact location of the service in the array. In the example, the script grabs the first service in the list.
  1. Loop through the list and stop the services.
  • To stop all services:
for server in gis_servers:
    for service in server.services.list():
        service.stop()
  • To stop a specific service:
for server in gis_servers:
    for service in server.services.list():
        print (service)
        if service.properties.serviceName == "<service name>":
            service.stop()

The following is the full script to stop the SampleWorldCities service:

from arcgis.gis import GIS
import arcgis.gis.admin

gis = GIS("https://machine.domain.com/portal", "admin", "password", verify_cert=False)
gis_servers = gis.admin.servers.get(role="HOSTING_SERVER")

for server in gis_servers:
    for service in server.services.list():
        print (service)
        if service.properties.serviceName == "SampleWorldCities":
            service.stop()

Article ID: 000019994

Software:
  • Portal for ArcGIS
  • ArcGIS Server
  • ArcGIS API for Python 1 x

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options