script to stop ArcGIS Server service

3392
5
02-11-2013 10:26 AM
EricGardecki
Occasional Contributor
I've used the following script to start/stop the AGS windows service, standalone and in models, so I can do some data management with very little downtime.  This script worked find in 10.0 but doesn't work in 10.1 now.  The name of the windows service changed and is reflected in the script but it does not start/stop the service as expected.  I can't seem to find out what changed in 10.1 that made this not work, nor can I find any alternative that makes any sense to me.  I need it to be a script without any prompts.  I've seen posts about stopping individual services but I don't see the need to do that when I can stop it all through the windows service instead...and much faster....plus all those scripts prompted for service name.   Anyone know what is wrong with this code now?

Thanks

import os
import arcpy
os.system('sc \\\\MachineName stop "ArcGIS Server"')
Tags (2)
0 Kudos
5 Replies
JakeSkinner
Esri Esteemed Contributor
What is the error you are receiving?  Also, are you executing the script on the same server that ArcGIS for Server is running?
0 Kudos
EricGardecki
Occasional Contributor
I am getting no errors.  A cmd window opens and closes again so fast I can't see if it says anything.  I kept getting schema lock messages in my model and then I checked the services on the server and the ArcGIS Server service was still running and continued to after trying the script.

I'm running it on another machine.  The machine with ArcGIS desktop on it, where I run my models.
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Create a new txt file and place the following command within the file:

sc \\<server> stop "ArcGIS Server"

Save the txt file and rename it to .bat.  Then, try executing the os.system command in python to run the batch file.  Ex:

import os
os.system(r"C:\temp\test.bat")
0 Kudos
EricGardecki
Occasional Contributor
same result.   Any other thoughts?   Is it possibly a permissions issue with the service?  That's the only thing that jumps out at me as the service is set to logon as the AGS admin account instead of local system. 

thanks
0 Kudos
EricGardecki
Occasional Contributor
It turns out it was definitely a permissions thing.  My user account wasn't able to stop the service.  Once adjusted it works as intended.

Thanks
0 Kudos