Hello,
I created a simple python script that will just Stop a service, as in the future I want to build upon this script.
This python script works when I run it from an IDE, it works in ArcPro as a direct python script, and it works as a Toolbox's Script tool.
It will even print out all my print statements as it goes through the process.
However, when I publish the tool to our Enterprise, it will run successfully, but do nothing. It won't print anything, it won't do anything. Any help? Here is the script below.
import arcpy
from arcgis.gis import GIS
import arcgis.gis.admin
gis = GIS("https://gis.domain.com/portal", "admin", "password", verify_cert=False)
gis_servers = gis.admin.servers.get(role="HOSTING_SERVER")
target_folder = "Tyler"
target_service = "TylerDataMap_WM_TRAIN"
for server in gis_servers:
for service in server.services.list(folder=target_folder):
arcpy.AddMessage(service.properties.serviceName)
if service.properties.serviceName == target_service:
arcpy.AddMessage(f"Stopping {target_service}...")
service.stop()
arcpy.AddMessage(f"{target_service} has been stopped.")
breakAny idea why it 'runs successfully' but actually does nothing?
The script itself looks correct, especially since it works in ArcGIS Pro, from the IDE, and as a local Script Tool.
Given that the published GP service completes successfully but produces no messages and does not stop the service, I would suspect an issue with the ArcGIS Server execution environment rather than the code logic.
A few things I would check:
Verify that the ArcGIS API for Python (arcgis package) is installed and available in the ArcGIS Server Python environment. The GP service runs on the Server machine, not in the same Python environment as ArcGIS Pro.
Wrap the entire script in a try/except block and write any exceptions using arcpy.AddError() along with traceback.format_exc(). This can reveal errors that are otherwise hidden during service execution.
Temporarily add:
import sys arcpy.AddMessage(sys.executable)
to confirm which Python environment is actually executing the service.
Check ArcGIS Server logs at DEBUG level immediately after running the GP service. In many cases the actual exception appears in the Server logs even when the GP job reports Success.
Confirm that the account being used by GIS(...) has sufficient administrative privileges to stop services on the Hosting Server.
My first suspicion would be either a missing/incompatible ArcGIS API for Python installation on the Server machine or an exception occurring before the service enumeration loop begins.