Upload Service Definition (Server)

License Level:BasicStandardAdvanced

Summary

Uploads and publishes a GIS service to a specified GIS server based on a staged service definition (.sd) file.

Usage

Syntax

UploadServiceDefinition_server (in_sd_file, in_server, {in_service_name}, {in_cluster}, {in_folder_type}, {in_folder}, {in_startupType}, {in_override}, {in_my_contents}, {in_public}, {in_organization}, {in_groups})
ParameterExplanationData Type
in_sd_file

The service definition (.sd) contains all the information needed to publish a GIS service.

File
in_server

You can use ArcGIS for Server connections listed under the GIS Servers node in the Catalog window, or you can navigate to a different folder where you might have server connection files stored.

If you are connecting to ArcGIS Online, make sure you type My Hosted Services for the server connection with each word capitalized and a space between each word.

ServerConnection
in_service_name
(Optional)

Use this to override the service name currently specified in the service definition with a new name.

String
in_cluster
(Optional)

Use this if you want to change the cluster to which the service has been assigned. You must choose from clusters that are available on the specified server.

String
in_folder_type
[in_folder_type,...]
(Optional)

Folder type is used to determine the source for the folder. The default is to get a folder from the service definition. You can also choose to get a list of folders already existing on the specified server, or you can specify a new folder to be created once you publish this service.

  • NEWUse this to create a new folder.
  • EXISTINGUse this to specify a folder that exists on the server.
  • FROM_SERVICE_DEFINITIONUse the folder already specified in the service definition. This is the default.
String
in_folder
(Optional)

Use this to specify the folder for the service. The default is to use the folder specified in the service definition. If you chose the NEW folder type, you use this parameter to enter a new folder name. If you chose the EXISTING folder type, you can choose from the existing folders on the server.

String
in_startupType
(Optional)

Use this to determine the start/stop state of the service immediately after publishing.

  • STARTEDThe service starts immediately after publishing.
  • STOPPEDThe service does not start after publishing. You will have to start the service manually.
Boolean
in_override
(Optional)

Use this parameter if you want to override the sharing properties set in the service definition. These properties define if, and how, you are sharing your service with ArcGIS Online. Sharing your service with ArcGIS Online exposes it for others to use.

  • OVERRIDE_DEFINITIONOverride the sharing properties set in the service definition with new values.
  • USE_DEFINITIONThe sharing properties currently set in the service definition will be used when the service is published. This is the default.

You must be logged in to ArcGIS Online in order to override sharing properties.

Boolean
in_my_contents
(Optional)

All shared services are available through My Contents. Even if you only want to share with a specific group in your organization, the service will also be shared through My Contents.

  • SHARE_ONLINEShares the service on ArcGIS Online. The service will be listed under My Content.
  • NO_SHARE_ONLINEThe service will not be shared on ArcGIS Online and will be inaccessible to other ArcGIS Online users and clients on the web.

You must be logged in to ArcGIS Online in order to override sharing properties.

Boolean
in_public
(Optional)

Choose whether or not your service will be available to the public.

  • PUBLICShare the service with the public.
  • PRIVATEDo not share the service with the public.

You must be logged in to ArcGIS Online in order to override sharing properties.

Boolean
in_organization
(Optional)

You can share your service with your organization.

  • SHARE_ORGANIZATIONShare the service with your organization.
  • NO_SHARE_ORGANIZATIONDo not share the service with your organization.

You must be logged in to ArcGIS Online in order to override sharing properties.

Boolean
in_groups
[group_name,...]
(Optional)

A list of group names with which to share the service.

You must be logged in to ArcGIS Online in order to override sharing properties.

String

Code Sample

UploadServiceDefinition example (Python window)

Uploads and publishes a service definition to a specified server.

import arcpy
from arcpy import env
env.workspace = "C:/data"
arcpy.UploadServiceDefinition_server("myMapService.sd", "GIS Servers/myServerConnection")
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)
UploadServiceDefinition example 2 (stand-alone script)

The following script loops through all service definitions in a folder and publishes each one to an ArcGIS Server.

# Name: UploadServiceDefinition_example3.py
# Description: Upload and publish all service definitions contained in a folder
# 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 variable
inServer = "myServerConnection.ags"
print "Publishing to " + inServer

# Find all the service definitions (.sd or .sds) in a workspace and 
# upload\publish each one to an ArcGIS Server, Spaital Data Server, or My Hosted Services
sdList = arcpy.ListFiles("*.sd")
for inSdFile in sdList:
    print "Publishing " + sdName
    try:
        arcpy.UploadServiceDefinition_server(inSdFile, inServer)        
    except Exception, e:
        print e.message
UploadServiceDefinition example 3 (stand-alone script)

The following script uploads an existing service definition and uses optional parameters to modify some properties of the service.

# Name: UploadServiceDefinition_example5.py
# Description: Uploads an existing service definition and uses optional 
#              parameters to modify some details of the service
# 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
inSdFile = "myMapService.sd"
inServer = "myServerConnection.ags"
inServiceName = "newServiceName"
inCluster = "myCluster"
inFolderType = "NEW"
inFolder = "newFolder"
inStartup = "STOPPED"
inOverride = "OVERRIDE_DEFINITION"
inMyContents = "SHARE_ONLINE"
inPublic = "PRIVATE"
inOrganization = "NO_SHARE_ORGANIZATION"
inGroups = "My Group"

# Execute UploadServiceDefinition
arcpy.UploadServiceDefinition_server(inSdFile, inServer, inServiceName, 
                                     inCluster, inFolderType, inFolder, 
                                     inStartup, inOverride, inMyContents, 
                                     inPublic, inOrganization, inGroups)
Overwriting services example (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
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

This tool does not use any geoprocessing environments

Related Topics

Licensing Information

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