I have a workflow where I update data on a nightly basis. The same data that I am updating also feeds a web mapping service that is served up through ArcGIS Server (AGS) (10.7.1).
The issue that I am running into is that the service is putting a lock on my source data and therefore cannot update it.
I did find an article where you could turn off Lock Database Schema. Instead of updating the feature class row by row I just recreate the feature locally and then overwrite the feature class that sits on our server. Unfortunately, this did not prevent my feature class from still being locked.
When I manually stop the service, my script runs perfectly and the feature class in question is updated. So naturally I started investigating how one would stop an AGS service using Python. I came across the following article.
How To: Stop GIS Services Using ArcGIS API for Python
The problem that I encounter is that I cannot actually connect to my AGS.
from arcgis.gis import GIS
import arcgis.gis.admin
gis = GIS("https://XYZ/MyWebAdaptor/admin", "MyLogin", "MyPassword", verify_cert=False)
I get multiple errors all relating to a login error.
Exception: A general error occurred: Could not login. Please ensure you have valid credentials and set your security login question.
I used the exact same URL and login information to access my AGS in ArcGIS Pro. I also use the same login information to login into AGS Manager.
I'm not sure what I am missing when I can use the same information to login multiple ways but when using python, it does not recognize the login.
Any assistance or suggestions would be greatly appreciated.
Thank you.
~DJB
Solved! Go to Solution.
Hi @DJB,
Try the following:
from arcgis.gis import server
# Stand-alone ArcGIS Server instance specify Primary Site Admin (i.e. siteadmin)
# Federated ArcGIS Server instance specify Portal Admin (i.e. portaladmin)
agsServer= server.Server(url="https://ags.esri.com/server", username='portaladmin', password='*******')
# Stop services
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()
Hi @DJB,
Try the following:
from arcgis.gis import server
# Stand-alone ArcGIS Server instance specify Primary Site Admin (i.e. siteadmin)
# Federated ArcGIS Server instance specify Portal Admin (i.e. portaladmin)
agsServer= server.Server(url="https://ags.esri.com/server", username='portaladmin', password='*******')
# Stop services
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()
You did it again and solved my issue. I tweaked your code slightly so that I am turning of the specific service in question.
folderList.append('')
for folder in folderList:
for service in agsServer.services.list(folder):
if service.properties.serviceName == "Nutrient_Management_Application_Sites":
service.stop()
Thank you so much for your lightning quick response.
This is getting ridiculous. I feel like I owe you big time for the number of times you've bailed me out.
Thanks again for all your help.
Cheers!