English

How To: Stop GIS services using ArcGIS API for Python

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 which 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 following 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 following parameter, 'verify_cert=False'.
  1. Retrieve available folders in the server, and specify it in a parameter.
gis_servers = gis.admin.servers.list()
Note:
If the desired server folder array location is known in the list, the script can be modified to:

servers = gis.admin.servers.list()[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 all services for all servers in a federated environment.
for server in gis_servers:
    for service in server.services.list():
        service.stop()
Note:
To stop specific services, the code can be modified as follows:

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

The code sample searches for the service name with SampleWorldCities and stops it.

The following shows the full code:

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.list()

#To stop all services
for server in gis_servers:
    for service in server.services.list():
        service.stop()

#To stop specific service(s)
for server in gis_servers:
    for service in server.services.list():
        if service.properties.serviceName == "SampleWorldCities":
            service.stop()

Related Information

Last Published: 2/16/2021

Article ID: 000019994

Software: ArcGIS API for Python 1.8.4, 1.8.3, 1.8.2, 1.8.1, 1.8.0, 1.7.1, 1.7.0, 1.6.1, 1.6, 1.5.3, 1.5.2, 1.5.1, 1.5, 1.4.1, 1.4, 1.3, 1.2.4, 1.2.3, 1.2.2, 1.2.1, 1.2, 1.0.1, 1.0 Portal for ArcGIS 10.7.1, 10.7, 10.6.1, 10.6