How To: Stop GIS services using ArcGIS API for Python
ArcGIS Server services can be stopped from ArcGIS Server Manager, ArcCatalog, or the catalog window in ArcGIS Pro. In some cases, there may be several services which need to 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.
The following steps describe how to stop services in a GIS folder using the stop() function.
- Import the necessary libraries.
from arcgis.gis import GIS import arcgis.gis.admin
- Specify the GIS server details.
gis = GIS("<portal url>", "<portal admin username>", "<portal admin password>")
- Retrieve available folder in the server, and specify it in a parameter.
services = gis_servers.services.list()
Note: If the desired server folder array location is known in the list, the script can be modified to: gis_servers = gis.admin.servers.list() "" 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.
- Loop through the list and stop all services for all servers in a federated environment.
for service in services: for service in server.services.list(): service.stop()
Note: To stop specific services, the code can be modified as follows: for service in services: 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 is a sample of the full code.
from arcgis.gis import GIS import arcgis.gis.admin gis = GIS("https://machine.domain.com", "admin", "password") gis_servers = gis.admin.servers.list() for server in gis_servers: for service in server.services.list(): service.stop()