Select to view content in your preferred language

Start Stop Services Errors

2195
11
Jump to solution
10-17-2023 07:42 AM
kapalczynski
Frequent Contributor

I am having issues with getting a list of Services PRIOR to stopping and starting them.  I am trying to get this info two different ways and getting errors on both... 

One of the examples is coming from here:

https://support.esri.com/en-us/knowledge-base/how-to-stop-gis-services-using-arcgis-api-for-python-0...

Any ideas what I am doing wrong?

 

    from arcgis.gis import GIS
    import arcgis.gis.admin
    
    nonProdPortal = "https://xxxx.xxx.gov/portal"
    loginName = "xxxxx"
    loginPass = "xxxxx"

    gis = GIS(nonProdPortal, loginName, loginPass, verify_cert=False)
    gis_servers = gis.admin.servers.list()

    #To stop specific service(s)
    for server in gis_servers:
        for service in server.services.list():
            #print(service.properties.serviceName)
            if service.properties.serviceName == "TMPD_AGO":
                #service.stop()
                print("Stopping TMPD_AGO")

 

ERROR:

File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\server\_common\_base.py", line 93, in __getattr__
"'%s' object has no attribute '%s'" % (type(self).__name__, name)
AttributeError: 'Server' object has no attribute 'services'

 

    from arcgis import gis

    nonProdPortal = "https://xxxxx.gov/portal"
    loginName = "xxxx"
    loginPass = "xxxx"

    mygis = gis.GIS(nonProdPortal, username=loginName, password=loginPass, verify_cert=False)
    #mygis = GIS(nonProdPortal, loginName, loginPass, verify_cert=False)

    servers = mygis.admin.servers.list()
    one_server = servers[0]
    
    services_on_that_server = one_server.services.list()
    one_of_those_services = services_on_that_server[0]

    # provided your service is running to begin with
    print(one_of_those_services.status)

 

ERROR:

File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\server\_common\_base.py", line 93, in __getattr__
"'%s' object has no attribute '%s'" % (type(self).__name__, name)
AttributeError: 'Server' object has no attribute 'services'

0 Kudos
11 Replies
kapalczynski
Frequent Contributor

I got it... leaving some junk in here that is commented out that still does stuff...

BUT basically I can point to a Stand Alone Server and:

  • List Folder Names
  • List Services in those folder names
  • specific a specific folder and turn on and off services in that folder... 

It would be nice to read into that LIST OBject and get the specific service name and use that to start and stop services... Where I could say IF the service name = XXX stop it and leave the others in the folder alone... 

I have not figure out how to do that yet... as a list object is being sent back to me.

EDIT: While I was posting @EarlMedina  posted the solution to get the name... I UPDATED the code below to print that out but did not build the IF THEN yet... 

THANKS @EarlMedina 

 

 

from arcgis.gis import GIS
import arcgis.gis.server

def listServices():
    nonProdPortal = "https://xxx.xxxx.xxx.gov/portal"
    loginName = "xxxx"
    loginPass = "xxxx"

    gis = GIS(nonProdPortal, loginName, loginPass, verify_cert=False)
    gis_servers = gis.admin.servers.list()
    print(gis_servers)
    print("")

    server1 = gis_servers[0]
    print(server1)
    print("")

    foldersList = server1.services.folders
    print(foldersList)

    # LIST FOLDERS and THEN ALL THE SERVICES IN THOSE FOLDERS
    #for folder in foldersList:
    #    foldername = folder
    #    print(foldername)
    #    servicesList = server1.services.list(folder=foldername)
    #    for servicename in servicesList:
    #        servicenameValue = servicename
    #        print("---" + str(servicenameValue))
    
    servicesList2 = server1.services.list(folder='DEQ_DEV')
    for service in servicesList2:
        
        # GIVE ME THE SERVICE NAME
        service_name = service.iteminformation.properties["name"]
        print(service_name)

        print(service)    
        status = service.status
        print(status)
        #service.stop()
        #service.start()
        status = service.status
        print(status)    
    
if __name__ == '__main__':
    listServices()

 

 

0 Kudos