Hello everyone,
Is there a way to schedule a map service to restart at 5 a.m. in ArcGIS server.
Is there a way to do it in ArcGIS Server?
Thank you
not sure about scheduling a specific service but you can schedule the arcgis Server process to restart at a specific time
We only need to stop 2 services not the whole ArcGIS Server.
Are you performing maintenance on the datasource of the service that requires you to stop the service?
You'll make a Python script to stop/start the services you want and then schedule that Python script to run at your desired time with Windows Task Scheduler.
Blake:
Have you used this script yourself to stop/start services? If so, do you use the port 6080 http protocol as shown in the sample script? Or have you successfully modified the script to use port 6443 https protocol?
I have been using the port 6080 http protocol for 1.5 years but recently I have encountered token fetching errors which I have not been able to resolve so I am trying to use the port 6443 https protocol but that is throwing different errors. I was able to get the port 6080 http protocol to work with Fiddler (It acts as a forward proxy), but that is not a permanent solution as it is a security risk to have Fiddler always running.
This is the script we use to stop and start a geocode service. I think it is basically a cut and past of an esri one. We are using http and 6080:
""" Stop or start ArcGIS Server geocode service """ # Required imports import urllib import urllib2 import json import contextlib ## context manager to clean up resources when exiting a 'with' block def get_token(adminUser, adminPass, server, port, expiration): """ Function to generate a token from ArcGIS Server; returns token. http://resources.arcgis.com/en/help/arcgis-rest-api/02r3/02r3000000m5000000.htm :param adminUser: admin user :param adminPass: admin password :param server: AGS name, e.g. ceav456 :param port: server port :param expiration: token timeout :return: """ # Build URL url = "http://{}:{}/arcgis/admin/generateToken?f=json".format(server, port) # Encode the query string query_dict = { 'username': adminUser, 'password': adminPass, 'expiration': str(expiration), ## Token timeout in minutes; default is 60 minutes. 'client': 'requestip' } query_string = urllib.urlencode(query_dict) try: # Request the token with contextlib.closing(urllib2.urlopen(url, query_string)) as jsonResponse: getTokenResult = json.loads(jsonResponse.read()) ## Validate result if "token" not in getTokenResult or getTokenResult == None: raise Exception("Failed to get token: {}".format(getTokenResult['messages'])) else: return getTokenResult['token'] except urllib2.URLError, e: raise Exception("Could not connect to machine {} on port {}\n{}".format(server, port, e)) # Function to start or stop a service on ArcGIS Server; returns JSON response. ## http://resources.arcgis.com/en/help/arcgis-rest-api/02r3/02r3000001s6000000.htm def service_start_stop(server, port, svc, action, token): """ Function to start or stop a service on ArcGIS Server; returns JSON response. http://resources.arcgis.com/en/help/arcgis-rest-api/02r3/02r3000001s6000000.htm :param server: AGS name, e.g. ceav456 :param port: server port :param svc: service name, folder, and type :param action: start or stop service :param token: server token :return: json response """ # Build URL url = "http://{}:{}/arcgis/admin".format(server, port) requestURL = url + "/services/{}/{}".format(svc, action) # Encode the query string query_dict = { "token": token, "f": "json" } query_string = urllib.urlencode(query_dict) # Send the server request and return the JSON response with contextlib.closing(urllib.urlopen(requestURL, query_string)) as jsonResponse: return json.loads(jsonResponse.read()) def service_control(ags, action): """ Control server services :param ags: AGS (ArcGIS Server) :param action: start or stop :return: result string """ # Local variables # Authentication adminUser = r"siteadmin" adminPass = r"sit3mngr!" # ArcGIS Server Machine server = ags port = "6080" # Services ("FolderName/ServiceName.ServiceType") svc = "Locators/CW_Composite.GeocodeServer" # Get ArcGIS Server token expiration = 60 ## Token timeout in minutes; default is 60 minutes. token = get_token(adminUser, adminPass, server, port, expiration) # Perform action on service jsonOuput = service_start_stop(server, port, svc, action, token) ## Validate JSON object result if jsonOuput['status'] == "success": result = "{} {} successful on server {}".format(action.title(), str(svc), server) else: result = "Failed to {} {}".format(action, str(svc)) return result raise Exception(jsonOuput) return result
We have ArcGIS Web Adaptor configured on the server and use an .ags connection file pointed to the web adaptor on http. You should be able to do it all with https as long as your certificates are all valid.
Edit:
That is actually for just publishing a geocode service that overwrites the existing service so it doesn't directly relate to your question about starting and stopping services. Here are the basic steps:
Hello Jose,
You can set the recycling time for the service to be at 5:00 AM, this will restart the service.
In Server Manager > Service > Edit (the pencil button) > Processes
-Danny
Is there a script in Python 3 for https connection?
Hello ESRI? Still Python 2 in 2021 and latest docs? Come on!