Start/Stop services in different folder directories

1594
4
Jump to solution
04-01-2022 09:15 AM
JeremiahJones
New Contributor II

I have looked at and replicated the example here ->How To: Stop GIS services using ArcGIS API for Python (esri.com) however, this code only seems to return the services that are living in the root folder of my ArcGIS server. I want to stop a different service inside of another folder directory and I am not sure how to do that. I think it may be something simple that I am missing.

Thanks for any help.

Cheers,

Jay

0 Kudos
1 Solution

Accepted Solutions
tigerwoulds
Occasional Contributor III

Actually, once you get the gis server object (gis_servers), you can try something like: 

serverFolder = 'My test folder'
serviceList = gis_servers.services.list(folder=serverFolder)

 Then loop through that list and execute .start or .stop

for service in serviceList:
    service.start()
    # service.stop()

 

View solution in original post

4 Replies
tigerwoulds
Occasional Contributor III
0 Kudos
tigerwoulds
Occasional Contributor III

Actually, once you get the gis server object (gis_servers), you can try something like: 

serverFolder = 'My test folder'
serviceList = gis_servers.services.list(folder=serverFolder)

 Then loop through that list and execute .start or .stop

for service in serviceList:
    service.start()
    # service.stop()

 

ZacharyHart
Occasional Contributor III

@tigerwoulds 

when i try what you suggest using the sample code from the tutorial I get:

AttributeError: 'list' object has no attribute 'services'
0 Kudos
Jen_Zumbado-Hannibal
Occasional Contributor

Thanks! This really worked for me even though I'm a very novice code writer. 

I'm using ArcGIS API for Python with Notebook in ArcPro and follow these steps. 

1 -Create profile

2-Connect as admin

3- Write following code:

#Connect to production server federated to Portal
gis_servers = gis.admin.servers.list()[1]
#List all services in Folder1
hosted_services = gis_servers.services.list(folder='Folder1')
#Stop all services in the Folder1
for service in hosted_services:
        service.stop()
#List the status of services in Folder1
service.status

 

So, I have four more folders and each one has services in them. How would you write this code to include not only stopping services at the root level but also in the various folders?

Thanks. 

 

 

Jen Zumbado-Hannibal, GISP
GIS Coordinator
City of Forest Grove
Forest Grove, OR 97116

0 Kudos