Summary
Stages a service definition. A staged service definition (.sd) file contains all the necessary information needed to publish a GIS service, including data that must be copied to the server because it does not appear in the server's data store.
Usage
This tool converts a service definition draft (.sddraft) into a service definition that can then be input to the Upload Service Definition tool to upload and publish the GIS service to a server. Draft service definitions cannot be used to publish a GIS service directly.
Whenever you share a service using ArcGIS Desktop, the Stage Service tool is run and you will see a result in the geoprocessing Results window.
Service definition drafts can be created using ArcGIS Desktop or by using the ArcPy functions CreateMapSDDraft (in arcpy.mapping), CreateImageSDDraft, or CreateGPSDDraft.
Once staged, the input service definition draft is deleted.
Syntax
arcpy.server.StageService(in_service_definition_draft, out_service_definition)
Parameter | Explanation | Data Type |
in_service_definition_draft | The input draft service definition. Service definition drafts can be created using ArcGIS Desktop. See About draft services for more information. You can also use the arcpy.mapping function CreateMapSDDraft to create draft service definitions. Once staged, the input draft service definition is deleted. | File |
out_service_definition | The resulting service definition. The default is to write the service definition to the same directory as the draft service definition. | File |
Code sample
StageService example 1 (Python window)
Stages a service definition.
import arcpy
from arcpy import env
env.workspace = "C:/data"
arcpy.StageService_server("myMapService.sddraft", "myMapService.sd")
Publishing workflow example 2 (stand-alone script)
The following script demonstrates a publishing workflow using Stage Service and Upload Service Definition.
# Name: StageService_UploadServiceDefinition_example2.py
# Description: Use a service definition draft to create a service definition
# and then upload and publish that service definition.
# Requirements: Connection to an ArcGIS Server or My Hosted Services
# Import system modules
import arcpy
from arcpy import env
# Set environment settings
env.workspace = "C:/data"
# Set local variables
inServiceDefinitionDraft = "myMapService.sddraft"
outServiceDefinition = "myMapService.sd"
# Execute StageService
arcpy.StageService_server(inServiceDefinitionDraft, outServiceDefinition)
# Set local variables
inSdFile = outServiceDefinition
inServer = "GIS Servers/myServerConnection"
# Execute UploadServiceDefinition
arcpy.UploadServiceDefinition_server(inSdFile, inServer)
Overwriting services example 3 (stand-alone script)
The following script creates and uploads a service definition that can be used to overwrite an existing service.
# Name: StageService_example3_UploadServiceDefinition_example4.py
# Description: Creates a service definition that can be used to overwrite an
# existing service. When this service definition is published it
# will overwrite the existing service.
# Requirements: Connection to an ArcGIS Server, Spatial Data Server,
# or My Hosted Services
# Import system modules
import arcpy
import xml.dom.minidom as DOM
# Set environment settings
arcpy.env.workspace = "C:/data"
# Set local variables
inServiceDefinitionDraft = "myMapService.sddraft"
outServiceDefinition = "myMapService.sd"
newType = 'esriServiceDefinitionType_Replacement'
xml = os.path.join(arcpy.env.workspace, inServiceDefinitionDraft)
doc = DOM.parse(xml)
descriptions = doc.getElementsByTagName('Type')
for desc in descriptions:
if desc.parentNode.tagName == 'SVCManifest':
if desc.hasChildNodes():
desc.firstChild.data = newType
outXml = xml
f = open(outXml, 'w')
doc.writexml( f )
f.close()
# Execute StageService
arcpy.StageService_server(inServiceDefinitionDraft, outServiceDefinition)
# Set local variables
inSdFile = outServiceDefinition
inServer = "GIS Servers/myServerConnection"
# Execute UploadServiceDefinition
arcpy.UploadServiceDefinition_server(inSdFile, inServer)
Environments
Licensing information
- Basic: Yes
- Standard: Yes
- Advanced: Yes