print "service definition draft created" arcpy.AddMessage("service definition draft created") # Set local variables inSdFile = sd con = "GIS Servers\\arcgis on HPWS32_6080 (admin)" inServer = con inServiceName = 'districtwise' inCluster = "default" inFolderType = "EXISTING" inFolder = "weather" inStartup = "STARTED" inOverride = "OVERRIDE_DEFINITION" inMyContents = "NO_SHARE_ONLINE" inPublic = "PRIVATE" inOrganization = "NO_SHARE_ORGANIZATION" inGroups = "" print "publishing local variables defined" arcpy.AddMessage("publishing local variables defined") # stage and upload the service if the sddraft analysis did not contain errors if analysis['errors'] == {}: # Execute StageService arcpy.StageService_server(sddraft, sd) print "StageService_server created" arcpy.AddMessage("StageService_server created") # Execute UploadServiceDefinition arcpy.UploadServiceDefinition_server(inSdFile, inServer, inServiceName, inCluster, inFolderType, inFolder, inStartup, inOverride, inMyContents, inPublic, inOrganization, inGroups) print "Uploaded..." arcpy.AddMessage("Uploaded..") else: # if the sddraft analysis contained errors, display them print analysis['errors']
Hi,
Did you end up finding a solution to this problem?
Have you got it working now?
Thanks
-Ben
Same problem here
I've found the exact same question mentioned here -
and yet I can't seem to manage overwriting an existing service!
Tried everything already!!
DIVYA SAHU your error suggests that there is an error with the params.
try changing the string - con = "GIS Servers\\arcgis on HPWS32_6080 (admin)"
into - "GIS Servers/arcgis on HPWS32_6080 (admin)"
just make sure this is the right name as shown in the arcgis catalog under the "GIS Servers" section
I stumbled onto this thread as I am also attempting to overwrite an existing service on ArcGIS Server with python. The script provided by stackexchange still doesn't work for me. I'm getting the following errors:
Traceback (most recent call last):
File "C:\scripts\PubStackExchange.py", line 35, in <module>
con, True, None, summary, tags)
File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\utils.py", line 18
1, in fn_
return fn(*args, **kw)
File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\mapping.py", line
382, in CreateMapSDDraft
return convertArcObjectToPythonObject(arcgisscripting._createMapSDDraft(*gp_
fixargs([map_document, out_sddraft, service_name, server_type, connection_file_p
ath, copy_data_to_server, folder_name, summary, tags], True, False)))
IOError: Missing raster band wavelength properties.
Any ideas?Python
No time to decipher your code, but here is an example that is working in 10.2.1. (this also disables KML) This will republish from mxd the services in docList. This also disables schema locking, so If you want your services to lock your schema, will have to remove that part.
import arcpy import xml.dom.minidom as DOM from arcpy import env import os env.workspace = r'\\myserver\iMapMXDs\PublicWorks\drafts' arcpy.env.overwriteOutput = True docList = ['PW_Irrigation','PW_Water','PW_Storm','PW_Sewer','PW_SewerTracking'] for service in docList: # Reference map document. mapDoc = arcpy.mapping.MapDocument(r'\\myserver\iMapMXDs\PublicWorks' + os.sep + service + '.mxd') sddraft = r'\\myserver\iMapMXDs\PublicWorks\drafts' + os.sep + service + '.sddraft' Server = r"GIS Servers\arcgis on myserver (admin)" arcpy.AddMessage(("RePublishing - " + service + " From " + mapDoc.filePath)) inServiceDefinitionDraft = sddraft inSdFile = outServiceDefinition = service + ".sd" newType = 'esriServiceDefinitionType_Replacement' # Create sddraft. arcpy.mapping.CreateMapSDDraft(mapDoc, sddraft, service, 'ARCGIS_SERVER') # The Server Object Extension (SOE) to disable. soe = 'KmlServer' # Read the sddraft xml. doc = DOM.parse(sddraft) # Find all elements named TypeName. This is where the server object extension (SOE) names are defined. typeNames = doc.getElementsByTagName('TypeName') for typeName in typeNames: # Get the TypeName we want to disable. if typeName.firstChild.data == soe: extension = typeName.parentNode for extElement in extension.childNodes: # Disabled SOE. if extElement.tagName == 'Enabled': extElement.firstChild.data = 'false' descriptions = doc.getElementsByTagName('Type') for desc in descriptions: if desc.parentNode.tagName == 'SVCManifest': if desc.hasChildNodes(): desc.firstChild.data = newType keys = doc.getElementsByTagName('Key') for key in keys: if key.hasChildNodes(): if key.firstChild.data == 'schemaLockingEnabled': key.nextSibling.firstChild.data = 'false' if key.firstChild.data == 'textAntialiasingMode': key.nextSibling.firstChild.data = 'None' f = open(sddraft, 'w') doc.writexml( f ) f.close() # Execute StageService arcpy.StageService_server(sddraft, outServiceDefinition) # Execute UploadServiceDefinition arcpy.UploadServiceDefinition_server(inSdFile, Server,"#","#","EXISTING","PublicWorks","STARTED")
Hi,
I actually solved this problem already by using some premade python tools that enables start/stop/deleting existing services.
So my script starts to search for the name of the relevant service name
using - getServiceList()
if he exists then I delete him
using - stopStartServices()
and after all that I publish my new service
using - arcpy.UploadServiceDefinition_server()
its not perfect but it works perfectly
http://www.arcgis.com/home/item.html?id=12dde73e0e784e47818162b4d41ee340
I tried this method at first and works fine to just re-publish. However, it didn't seem to pick up changes to things like adding a value to a Domain. For this, I had to re-create the service definition from the mxd first, then re-publish and the new values show.
I also right-click on the service in ArcCatalog and modify the settings some (turn off KML and schema locking). This method is the only way I could find to accomplish this.
R_
Yeah sorry I actually forgot to mention that part.. you need to create the SD file and my script takes him from a network path and run the publish method