I have the following script that's supposed to stop locator services with a specific word in the name.
for server in gis_server:
if (server.url == 'https://arcgisserver/admin'):
for service in server.services.list():
if service.properties.type == 'GeocodeServer' and "parcel" in service.properties.serviceName:
service.stop()
print(service.properties["serviceName"] + ' stopped')
Line #4 doesn't work, I don't get any errors but it doesn't stop the locator services that have the word "Parcel" in the name.
I have 3 locator services with the word "parcel":
- Composite_Parcel
- RegionalParcelLocator
- ABCCompositeParcel
How should I update line 4 to only stop the locator services that have "parcel" in the name?
TIA
Solved! Go to Solution.
You may need to check against a lowercase service name, as the `in` operator is case sensitive. Additionally, what MikeVolz suggested re root folder is also worth looking at.
"parcel" in service.properties.serviceName.lower()
Is this your entire script to stop locator (geocode) services? If not, can you provide more of the script?
Are these ArcMap based locators or Pro based locators?
The script stop locator services, rebuilds the locators and start services. We get new parcel every two weeks and need to update the locators to find the new parcels.
The locators were created in ArcMap. Below is the entire script.
import arcpy
from arcgis.gis import GIS
arcpy.env.overwriteOutput = True
# Variables
server = 'https://arcgisserver.com/portalt'
user = 'user'
password = 'Passwrod'
ArcGISFS = '\\\\locators\\TESTLocator'
# Connect to portal
gis = GIS(server, user, password, verify_cert=False)
print(' Connected to portal test')
# Stop services that are "GeocodeServer" type and "parcel" in name
for server in gis_server:
if (server.url == 'https://arcgisserver/admin'):
for service in server.services.list():
if service.properties.type == 'GeocodeServer' and "parcel" in service.properties.serviceName:
service.stop()
print(service.properties["serviceName"] + ' stopped')
# Rebuild locators in ArcGISFS\arcgissource\locators folder
for locator in os.listdir(ArcGISFS):
if locator.lower().endswith (".loc"):
print (locator)
locbaseGISFS= str(os.path.splitext(os.path.basename(locator))[0])
locnameGISFS= ArcGISFS+"\\"+locbaseGISFS
# Select parcel related locators and NOT Composite locators
if ("composite") not in locbaseGISFS.lower() and ("parcel") in locbaseGISFS.lower() or ("parcen") in locbaseGISFS.lower():
print('Rebuilding locators in arcgissource\locators folder')
try:
# Rebuild locators
print(' Rebuilding ' + locnameGISFS)
arcpy.RebuildAddressLocator_geocoding(locnameGISFS)
print(arcpy.GetMessages())
except:
messageGISFS = arcpy.GetMessages()
# Start services that are "GeocodeServer" type and "parcel" in name
for server in gis_server:
if (server.url == 'https://arcgisserver/admin'):
for service in server.services.list():
if service.properties.type == 'GeocodeServer' and "parcel" in service.properties.serviceName:
service.start()
print(service.properties["serviceName"] + ' started')
You should not use 'server' as a variable for your server URL as well as a variable to loop thru servers in your enterprise environment.
Add the line gis_servers = gis.admin.servers.list() and loop thru this list with a different variable than 'server'.
Your code will only locate geocode services in the root server folder. If you have geocode services in subfolders you will need to explicitly state those folder names
eg. for service in server.services.list(folder='Your folder name'):
Thanks, I'll change the variable.
The code is correct, all our public geocode services are in the root server folder.
You may need to check against a lowercase service name, as the `in` operator is case sensitive. Additionally, what MikeVolz suggested re root folder is also worth looking at.
"parcel" in service.properties.serviceName.lower()
Thank you so much, this fixed my script.