Hey Becky,I just uploaded the ArcGIS Server Administration Toolkit: http://www.arcgis.com/home/item.html?id=12dde73e0e784e47818162b4d41ee340Its a bunch of tools and scripts which you can use to do administrative tasks.I also enhanced the listing of services- it now happens through the REST Admin, so even if a task is stopped, it'll report it back in the list.Hope this could be of some use to you.
--> this won't work service if the service wasn't originally started --> to begin with....would never make the "services" list
''' Sample of using REST API for ArcGIS Server 10.1 to list a service folder, and stop and start the services...it also creates a token, if needed (can be hard coded). I have it set to work with MapServices but it in theory is can work with any. This script basically lists the services in a folder (dfg_common in sample), stops those that are currently running, then starts them again. This is a snippet used for testing (and not very pratical by itself). For me, I will incorporate it with updating data and caches. Most likely it can be cleaned up a bit. Modified for general sample distribution. Replace the following with local info: variable values for server, port, username (AGS site Admin), and password. Also in the line "if folder == "dfg_common" should be modified and/or replaced for your local site....or can be modified if you don't have subfolder structure. This was developed under 10.1 beta 2...not tested with pre-release yet, which is due out any day. I will test in the next couple weeks and update/repost if needed. Thanks to Kevin Hibma who got me on the right track, and additional info was from samples in the 10.1 beta ArcGIS Rest API help.... Rebecca S. debugged using Wing Pro IDE ''' import json, urllib2, urllib import arcpy server = "<your server>" port = "6080" username = "<AGS site admin username>" password = "<AGS site admin password>" baseUrl = "http://{}:{}/arcgis/rest/services".format(server, port) def gentoken(url, username, password, expiration=60): #code to get token from the server query_dict = {'username': username, 'password': password, 'expiration': str(expiration), 'client': 'requestip'} query_string = urllib.urlencode(query_dict) #arcpy.AddMessage("query_string: " + query_string) return json.loads(urllib.urlopen(url + "?f=json", query_string).read())['token'] def getCatalog(usermame, password): catalog = json.load(urllib2.urlopen(baseUrl + "/" + "?f=json")) print 'ROOT' if "error" in catalog: return services = catalog['services'] for service in services: response = json.load(urllib2.urlopen(baseUrl + '/' + service['name'] + '/' + service['type'] + "?f=json")) arcpy.AddMessage(' %s %s (%s)' % (service['name'], service['type'], 'ERROR' if "error" in response else 'SUCCESS')) folders = catalog['folders'] for folderName in folders: if folderName == "dfg_common": # I was filtering for a particular folder for testing catalog = json.load(urllib2.urlopen(baseUrl + "/" + folderName + "?f=json")) arcpy.AddMessage(folderName) if "error" in catalog: return services = catalog['services'] for service in services: response = json.load(urllib2.urlopen(baseUrl + '/' + service['name'] + '/' + service['type'] + "?f=json")) #print ' %s %s (%s)' % (service['name'], service['type'], 'ERROR' if "error" in response else 'SUCCESS') #arcpy.AddMessage(' %s %s (%s)' % (service['name'], service['type'], 'ERROR' if "error" in response else 'SUCCESS')) serviceName = (service['name'] + "." + service['type'] ) #arcpy.AddMessage(serviceName) msgStop = stopService(server, serviceName, username, password) if 'success' in msgStop: arcpy.AddMessage("stopped " + (service['name'])) else: arcpy.AddMessage( msgStop) ''' --> this won't work service if the service wasn't originally started --> to begin with....would never make the "services" list ''' msgStart = startService(server, serviceName, username, password) if 'success' in msgStop: arcpy.AddMessage("started " + (service['name'])) else: arcpy.AddMessage( msgStart) def stopService(server, servicename, username, password, token=None, port=6080): #code to stop the service. token can be passed in, but code below will envoke the gettoken function if token is None: token_url = "http://{}:{}/arcgis/admin/generateToken".format(server, port) arcpy.AddMessage("token_url: " + token_url) token = gentoken(token_url, username, password) arcpy.AddMessage("token: " + token) stop_service_url = "http://{}:{}/arcgis/admin/services/{}/stop?token={}&f=json".format(server, port, servicename, token) #arcpy.AddMessage(stop_service_url) msg = urllib2.urlopen(stop_service_url, ' ').read() # The ' ' forces POST return msg def startService(server, servicename, username, password, token=None, port=6080): #code to start the service. token can be passed in, but code below will envoke the gettoken function if token is None: token_url = "http://{}:{}/arcgis/admin/generateToken".format(server, port) token = gentoken(token_url, username, password) start_service_url = "http://{}:{}/arcgis/admin/services/{}/start?token={}&f=json".format(server, port, servicename, token) #arcpy.AddMessage("start_service_url: " + start_service_url) msg = urllib2.urlopen(start_service_url, ' ').read() # The ' ' forces POST return msg getCatalog(username, password)
Membros conectados podem postar, seguir atualizações e mais. Novo aqui? Registre uma conta gratuita.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.