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
Thank you for posting this! I have been struggling to find a working solution for a while. This is perfect.
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!
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()
@JakeSkinner Thanks for posting this. I tried it but it is throwing a KeyError: 'folders'
Any tips for correcting the error?
@ahagopian_coj what version of ArcGIS API for Python are you running? Or, what version of Pro are you using when executing the above?
@JakeSkinner According to PyCharm I have arcgis version 2.2.01 installed.
@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.