I am working on a standalone script that is supposed to stop a few geocoding services, then rebuild the address locators used in those services, then start the geocoding services.
It is supposed to run on a standalone, non-federated ArcGIS Server (version 10.9.1) (the same server that the services were published to) in a DMZ server network. The script is running on the server itself because machines on my internal network cannot connect with the DMZ server in the ways that are needed for this script.
I am using the ArcGIS API for Python to stop and start the services, and I based those parts of the script on sample code from Esri. The geocoding services were published on the ArcMap runtime, and today I created a Pro runtime geocoding service, and the script didn't stop that service either. I am running the script in Command Prompt and sometimes in IDLE.
PROBLEM: The script does not stop the geocoding services, yet it moves through that part of the script without throwing an error. I can see in Server Manager online that the services are never stopped. It only hits an error when it tries to rebuild an address locator but can't do it because the geocoding service was not actually stopped first.
I have run out of ideas of how to troubleshoot or fix this. I have double-checked everything I can think of to check - credentials, names and paths, etc. The credentials being used can indeed stop the services manually in Server Manager. Does anyone have any ideas?
Here is the core of the code:
import sys
import datetime
from arcgis.gis.server import Server # ArcGIS API for Python
import arcpy
import keyring
if __name__ == "__main__":
# Folder path where the locator is, not the service:
arcpy.env.workspace = r'D:\RootFolder\OtherFolder'
# Name of folder in the Server Manager where the locator lives:
folder_folder_name = 'MyFolder' # File Explorer folder name
ags_folder_name = 'MY_FOLDER' # ArcGIS Server Manager folder name
# Base URL of the ArcGIS Server where the service lives:
server_base_url = r'https://myserverbaseurl:port'
# Names of the locators (not services):
locator_name_list = ['LOCATOR_ROAD', 'LOCATOR_POINTS', 'LOCATOR_ADDR']
# Names of the geocoding services published to the server:
locservice1 = 'MY_FAV_SERVICE'
locservice2 = 'THE_OTHER_SERVICE'
username = keyring.get_password('name', 'user')
pw = keyring.get_password('other_name', 'password')
# Create an instance of a Server object in ArcGIS API for Python.
server = Server(url='{}/arcgis/admin'.format(server_base_url), username=username, password=pw)
# Access server content (ArcGIS API for Python)
cdir = server.content
# Instantiate the services as service objects
service1 = cdir.get(locservice1, folder=ags_folder_name)
service2 = cdir.get(locservice2, folder=ags_folder_name)
# TEST - this worked.
#print(service1.service.iteminformation)
#print(cdir) # This worked.
# Stop the geocoding services in order to next rebuild the locators
service1.service.stop()
service2.service.stop()
# Rebuild the locators.
for locator_name in locator_name_list:
print(locator_name)
arcpy.geocoding.RebuildAddressLocator(locator_name)
# Start the services after rebuilding. (ArcGIS API for Python)
service1.service.start()
service2.service.start()