Select to view content in your preferred language

Stopping Service via Python

1312
10
02-27-2024 05:38 AM
JoshBillings
Frequent Contributor

Hello all,

I am using the code below to stop a service on ArcGIS Server. This work flawlessly on this particular server. 

When I try to use this code on a service on a different server, I get a KeyError: 'folders' error on line 8. Not sure what this error is indicating.

Does anyone know why this would work on one server but not the other? Thanks!

from arcgis import *
from arcgis.gis import server

s = server.Server("hhtps://server-url.com",username='username',password='password')

cdir = s.content

serv = cdir.get("Service Name",folder = "Folder")

serv.service.stop()

 

0 Kudos
10 Replies
JohXENIE
Emerging Contributor

Hello @JoshBillings ,

i use the service.properties.serviceName == "name_service" for a specific service name. I use this in a toolbox with multiples parameters the service_name = arcpy.GetParameterAsText(0)

Hope this could help 🙂

# arcpy.GetParameterAsText(4) => folder_name in arcgis server manager
services = server1.services.list(folder=arcpy.GetParameterAsText(4))
for
service in services:
if service.properties.serviceName == service_name:
service.stop()
arcpy.AddMessage(service.status)

0 Kudos