Stage Service (Server)

License Level:BasicStandardAdvanced

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

Syntax

StageService_server (in_service_definition_draft, out_service_definition)
ParameterExplanationData Type
in_service_definition_draft

Input draft service definition. Service definition drafts can be created using ArcGIS for Desktop. See the help topic 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

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 (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 (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, Spatial Data 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 (stand-alone script)

The following script creates and uploads a service defintion that can be used to overwite 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
from arcpy import env
import xml.dom.minidom as DOM 

# Set environment settings
env.workspace = "C:/data"

# Set local variables
inServiceDefinitionDraft = "myMapService.sddraft"
outServiceDefinition = "myMapService.sd"
newType = 'esriServiceDefinitionType_Replacement'

xml = draftPath + in_sd_draft
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

Related Topics

Licensing Information

ArcGIS for Desktop Basic: Yes
ArcGIS for Desktop Standard: Yes
ArcGIS for Desktop Advanced: Yes
1/21/2015