Select to view content in your preferred language

Stop start locator service with specific word in name

1620
6
Jump to solution
07-29-2021 09:12 AM
AliciaShyu
Frequent Contributor

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

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
nzjs
by
Occasional Contributor

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()

View solution in original post

0 Kudos
6 Replies
MichaelVolz
Esteemed Contributor

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?

0 Kudos
AliciaShyu
Frequent Contributor

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')

 

 

 

0 Kudos
MikeVolz
Occasional Contributor

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'):

0 Kudos
AliciaShyu
Frequent Contributor

Thanks, I'll change the variable.

The code is correct, all our public geocode services are in the root server folder.

0 Kudos
nzjs
by
Occasional Contributor

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()
0 Kudos
AliciaShyu
Frequent Contributor

Thank you so much, this fixed my script.