Stopping/Starting ArcGIS services using Python

5051
4
Jump to solution
05-16-2012 06:28 AM
JustinNettleton
Occasional Contributor
I am trying to find a way to start and stop a service in python so I can automate some updates. I have found the the agssom.exe script in Arcscripts. I place it in c:\windows\system32. The code I am using in my pytho script is below. The script runs with out any errors, but the service doesn't stop. Am I missing a step or does anybody have a better way of doing this?

We are running ArcGIS 10 with python 2.6.5


import os

# variables
PathToAGSSOM = r"C:\\windows\\system32\\ArcSOM.exe"
server = "VULCAN"
command = "-x" # use -x for stop
service = "Narcotics"

# use AGSSOM.exe to start map service from command line
commandLine = PathToAGSSOM + " " + server + " " + command + " " + service
os.system(commandLine)

print "Finished"


Thanks
Tags (2)
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor
Right-click on 'My Computer' > Properties > Advanced System Settings > Advanced tab.  You should see an 'Environment Variables...' button there.  Click this and then you will see 'Path' under System Variables.  'C:\Windows\System32' should be listed here.  You can test this by simply typing 'agssom' within a command prompt.  If usage variables are returned, then you are good to go.  Also, be sure you are refreshing the GIS Server connection in the Catalog window to see that the service has been stopped.

View solution in original post

4 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Justin,

You will not need the full path of the executable since it's copied to the System32 directory.  Also, a couple other notes:

-the exe is 'AGSSOM.exe', you had 'ArcSOM.exe'
-when specifying 'r' before a path, you will just need to use one '\' between directories

Try the following instead:

import os

# variables
server = "VULCAN"
command = "-x" # use -x for stop
service = "Narcotics"

# use AGSSOM.exe to start map service from command line
commandLine = "agssom " + server + " " + command + " " + service
os.system(commandLine)

print "Finished"


Also, be sure that 'C:\Windows\System32' is referenced in your PATH environment variable.
JustinNettleton
Occasional Contributor
Thanks for the response. I used the code you provided and again it ran, but the service did not stop. I am not sure what your last line means. "Also, be sure that 'C:\Windows\System32' is referenced in your PATH environment variable. " Not a real advanced programmer, can you tell me where I would need to check/set this?

Thanks,
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Right-click on 'My Computer' > Properties > Advanced System Settings > Advanced tab.  You should see an 'Environment Variables...' button there.  Click this and then you will see 'Path' under System Variables.  'C:\Windows\System32' should be listed here.  You can test this by simply typing 'agssom' within a command prompt.  If usage variables are returned, then you are good to go.  Also, be sure you are refreshing the GIS Server connection in the Catalog window to see that the service has been stopped.
JustinNettleton
Occasional Contributor
Thanks, that did the trick.
0 Kudos