Select to view content in your preferred language

Start/Stop ArcServer Services in Modelbuilder?

3839
7
02-03-2011 11:42 AM
JeffPickles
New Contributor III
How do I start and stop ArcServer services in a Modelbuilder environment?

I'd like to create a tool that stops map services, updates their respective geodatabases, and then restarts the map services. If there's an easier way to do this outside of Modelbuilder, I'm open to that as well.
0 Kudos
7 Replies
KevinHibma
Esri Regular Contributor
There is no modelbuilder way to do this.

There is a utility on Arcscripts which you can use with a batch file to achieve this.
http://arcscripts.esri.com/details.asp?dbid=16293
I've heard a lot of people have been successful with this.

There might be other scripting alternatives, but nothing in "arcpy" to stop/start services.
That said, you could write a script to:

-call the batch file (stop services)
os.system(r"C:\path\AGSSOM.bat " + str("stop MapService1"))
-do an arcpy.WhateverToolYouNeed_to_do_the_update
-call batch file again (start services)
0 Kudos
JeffPickles
New Contributor III
Kevin,

Thanks for the reply. I'm able to get the batch file to work without any troubles. Am I to assume in your example that MapService1 is where I would enter my service names? If so, could I state *all* to catch all services?

Also, to get the arcpy.UpdaterStuff, couldn't I simply create the workflow in Modelbuilder, export as a Python script, and copy-paste the Python code? Or, heck, even just reference the .py output file and nest it in between the batch file calls?
0 Kudos
KevinHibma
Esri Regular Contributor
Jeff,

Actually, looking at the syntax of the AGSSOM utility, and then my syntax - it doesn't make sense.

You would want to change it to 1 of 2 things.
-Make a batch file and wrap any/all the AGSSOM.exe commands inside.  Then just call the batch file
-Or simply make the call to the AGSSOM.exe and add the arguments. (similar to how the batch file was called with an argument above)
And yes, looking at the usage syntax, it looks like it supports "stop all"
>> agssom.exe -x *all*


As for generating the script from modelbuilder - you could do it in modelbuilder like you want with just the service stopping inside a script. You would just make a basic script tool (probably no parameters) and embed the script tool inside your model. (script tool being the stop/start python call). The script tool just becomes another element that the model works through.

Thinking a little further (and I haven't tried this) - you might be able to do an advanced field calculation and within that have the python calls to restart the services via the agssom. Not sure if that would work, but it would be an interesting idea. (maybe I'm just over complicating it now).

Hope this helps some
0 Kudos
JeffPickles
New Contributor III
Having an issue getting the batch to run in Python.

import os
os.system(r"X:\ArcGIS\Tools\Stop_All_ArcServer_Services.bat")


The result is a syntax error.

If it helps, the line inside that .bat is
X:\ArcGIS\Tools\AGSSOM\AGSSOM.exe [ServerName] -x *all*


I can bring this .py file into Modelbuilder, but it won't run. I assume this will be fixed when the syntax error is fixed.

[EDIT: It also comes back with syntax error when I substitute the .exe straight up without the .bat]
0 Kudos
JeffPickles
New Contributor III

Thinking a little further (and I haven't tried this) - you might be able to do an advanced field calculation and within that have the python calls to restart the services via the agssom. Not sure if that would work, but it would be an interesting idea. (maybe I'm just over complicating it now).

Hope this helps some


I inserted this in my Modelbuilder via Calculated Value and it worked. Now to pull the whole thing together...
0 Kudos
by Anonymous User
Not applicable
I inserted this in my Modelbuilder via Calculated Value and it worked. Now to pull the whole thing together...


How exactly did you get this to work using the Calculate Value tool???
0 Kudos
by Anonymous User
Not applicable
How exactly did you get this to work using the Calculate Value tool???


Ok I was not able to figure out how to start/stop a map service using the Calculate Value tool ... but I was able to create a script from the .BAT file using this method.  From the script I was able to set a precondition where the result allowed the model to proceed (in this case, either stopping or starting a service). 

Basically with these simple scripts, I am now able to stop services, run some geoprocessing tasks, and turn the services back on with just one model.
0 Kudos