For better maintenance to our Web Map Services, is there a Python Script out there to Reboot our Enterprise Server?
Thanks,
Larry Adgate`
Hi Jonathan, typically Monday morning I arrive at the office to inspect all my Web Services and they are all offline. As a remedy, I submit a request to IT to reboot the Enterprise Server and that seems to resolve the issue. I have suggested using a script to reboot the Server Early Monday morning but IT is bent on only a manual reboot.
Larry
I'd argue that the best thing to do would be to troubleshoot, (possible with Support), why your services are offline. Not sure if you've done a bit of that already. What errors or behavior do you see?
Are you interested in rebooting the machine or just the ArcGIS Server Windows service? You can use the subprocess module for just about anything you can do through the command line. For example, to stop the ArcGIS Server Windows service:
<SPAN class="keyword token">import</SPAN> subprocess <SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN> result <SPAN class="operator token">=</SPAN> subprocess<SPAN class="punctuation token">.</SPAN>check_output<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"net stop \"ArcGIS Server\""</SPAN><SPAN class="punctuation token">,</SPAN>stderr<SPAN class="operator token">=</SPAN>subprocess<SPAN class="punctuation token">.</SPAN>STDOUT<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>result<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">except</SPAN> subprocess<SPAN class="punctuation token">.</SPAN>CalledProcessError <SPAN class="keyword token">as</SPAN> e<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Failed - {}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>e<SPAN class="punctuation token">.</SPAN>output<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
When I need to do stuff like that, I usually use a function:
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">submitCommand</SPAN><SPAN class="punctuation token">(</SPAN>command<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN> codec <SPAN class="operator token">=</SPAN> <SPAN class="string token">'utf-8'</SPAN> result <SPAN class="operator token">=</SPAN> subprocess<SPAN class="punctuation token">.</SPAN>check_output<SPAN class="punctuation token">(</SPAN>command<SPAN class="punctuation token">,</SPAN>stderr<SPAN class="operator token">=</SPAN>subprocess<SPAN class="punctuation token">.</SPAN>STDOUT<SPAN class="punctuation token">)</SPAN> success <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN> <SPAN class="keyword token">except</SPAN> subprocess<SPAN class="punctuation token">.</SPAN>CalledProcessError <SPAN class="keyword token">as</SPAN> e<SPAN class="punctuation token">:</SPAN> result <SPAN class="operator token">=</SPAN> e<SPAN class="punctuation token">.</SPAN>output success <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">False</SPAN> <SPAN class="keyword token">except</SPAN><SPAN class="punctuation token">:</SPAN> result <SPAN class="operator token">=</SPAN> traceback<SPAN class="punctuation token">.</SPAN>format_exc<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> success <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">False</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="operator token">not</SPAN> isinstance<SPAN class="punctuation token">(</SPAN>result<SPAN class="punctuation token">,</SPAN>str<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> result <SPAN class="operator token">=</SPAN> result<SPAN class="punctuation token">.</SPAN>decode<SPAN class="punctuation token">(</SPAN>codec<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN> success<SPAN class="punctuation token">,</SPAN> result<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
I can then just call the function like:
success<SPAN class="punctuation token">,</SPAN> result <SPAN class="operator token">=</SPAN> submitCommand<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"net STOP \"ArcGIS Server\""</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>success<SPAN class="punctuation token">,</SPAN>result<SPAN class="punctuation token">)</SPAN> success<SPAN class="punctuation token">,</SPAN> result <SPAN class="operator token">=</SPAN> submitCommand<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"net START \"ArcGIS Server\""</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>success<SPAN class="punctuation token">,</SPAN>result<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
You'll just need logic to handle the response and a failure.
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.