Select to view content in your preferred language

Start/stop arcgis secure services Python 3

1980
7
06-30-2020 11:13 PM

Start/stop arcgis secure services Python 3

For anyone who is interested, here a Python 3 script that stops or starts all map services in the ROOT folder. It can be started with the following command:

"<arcgis install dir>\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3\python.exe" <file location>\Start_stop_arcgis_services_in_folder_https_P3.py %1 %USER% %2 %PASS% %3 %SERV% %4 %MAP% %5 %STARTSTOP%

Any improvements are welcome of course

Attachments
Comments
MeleKoneya
Regular Contributor

Thank you for posting this!     I have been struggling to find a working solution for a while.    This is perfect.   

IanIce1
New Contributor III

This is great! I'm currently migrating old python 2 scripts to python 3 and spent way too much time trying to get it to work in Py 3 (after upgrading httplib, encoding, https, etc).  One thing I added to make it work for services in a folder was adding the actual folder variable in the servicesStartStop function:

def serviceStartStop(server, port, svc, folder, action, token):
# Build URL
url = "https://{}:{}/arcgis/admin".format(server, port)
requestURL = url + "/services/{}/{}/{}".format(folder, svc, action)

Otherwise it will raise an error saying "service.mapserver does not exist or operation is not supported"

Thank you!

JakeSkinner
Esri Esteemed Contributor

Just an FYI, here is a way to do this with the ArcGIS API for Python.  It also demonstrates how to iterate through all folders to stop those services as well.

from arcgis.gis import server

# If federated server, connect using Portal credentials
# If stand-alone ArcGIS Server, connect using ArcGIS Server credentials
agsServer = server.Server(url="https://ags.esri.com/server", username='portaladmin', password='********')

serviceList = []
folderList = [folder for folder in agsServer.content.folders if folder != 'Hosted'
              and folder != 'System' and folder != 'Utilities']
folderList.append('')
for folder in folderList:
    for service in agsServer.services.list(folder):
        service.stop()

 

ahagopian_coj
Occasional Contributor

@JakeSkinner Thanks for posting this.  I tried it but it is throwing a KeyError: 'folders'

Any tips for correcting the error?

JakeSkinner
Esri Esteemed Contributor

@ahagopian_coj what version of ArcGIS API for Python are you running?  Or, what version of Pro are you using when executing the above?

ahagopian_coj
Occasional Contributor

@JakeSkinner According to PyCharm I have arcgis version 2.2.01 installed.

ahagopian_coj
Occasional Contributor

@JakeSkinner Figured it out.  It was my server url.  I put in the portal url instead of this one: http://machinename.domain.com/webadapter.  Once I corrected that then it worked.

Version history
Last update:
‎06-30-2020 11:13 PM
Updated by:
Contributors