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
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()
Have you seen this? Example: Stop or start all services in a folder—ArcGIS Server Administration (Linux) | Documentation for ArcGIS Enterprise (depaul.edu)
@tigerwoulds
when i try what you suggest using the sample code from the tutorial I get:
AttributeError: 'list' object has no attribute 'services'
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.
Hi all,
I'm trying to use this code but I am also getting
serviceList = gis_servers.services.list(folder=serverFolder) AttributeError: 'list' object has no attribute 'services'
I'm not sure how to fix this as my python knowledge is limited. What am I missing?
Hi!
You all have helped me a quite a bit. Through this post and many other posts along with documentation, I was able to piece together full code to stop all of my services. I am posting here to help others in the future. Is there a better way to do it? Well, I was hoping so! But at least this works.
from arcgis.gis import GIS import arcgis.gis.admin gis = GIS("portalurl", "username") #GIS Server details admin = gis.admin server1 = gis.admin.servers.get(role="HOSTING_SERVER")[0] #get federated ArcGIS Server #stop root folder services for service in server1.services.list(): service.stop() #stop all services in this folder for service in server1.services.list(folder="folder1"): service.stop() #stop all services in this folder for service in server1.services.list(folder="folder2"): service.stop() #stop all services in this folder for service in server1.services.list(folder="folder3"): service.stop()
これを試した方はほかにもいますか?フォルダー内にあるサービスを停止/開始しようとしているのですが、回答のコードを実行すると AttributeError が返されます。
あなたのgis_servers変数はリストですが、必要なのはServiceオブジェクトです。
gis_servers
Service
を呼び出すと、gis.admin.servers_list()を呼び出すと、Serviceオブジェクトを含むPythonリストオブジェクトが返されます。リストから[0]などのインデックスを使って、Serverオブジェクトを取得する必要があります。
gis.admin.servers_list()
[0]
Server
はい、@GISAdmin11 @Clubdebambosは正しいです。私はいつもこうしています。コード例はこちらです:
from arcgis.gis import GIS gis = GIS("https://yourorg.net/portal", "username", "userpw") #gis= GIS("home") #サーバーの一覧を表示 gis_servers = gis.admin.servers.list() print(gis_servers) #サーバーを取得 agsfed = gis_servers[5] print(agsfed) #フォルダーを取得し、サービスを開始/停止 try: ccServicesList = agsfed.services.list(folder='CallCenterServices') for ccService in ccServicesList: print(ccService.properties.serviceName) ccService.start() #ccService.stop() print(ccService.status) except Exception: # エラーが発生した場合は、行番号とエラーメッセージを表示 import traceback, sys tb = sys.exc_info()[2] e = sys.exc_info()[1] print(e.args[0]) print "行 %i" % tb.tb_lineno
これはノートブックのセル内でも、IDLE上でも実行できます
サインインすると、投稿したり、更新をフォローしたりできます。初めての方ですか?無料アカウントを登録しましょう。
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.