<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: &amp;quot;Could not undeploy services&amp;quot; error when using Python in ArcGIS Enterprise Questions</title>
    <link>https://community.esri.com/t5/arcgis-enterprise-questions/quot-could-not-undeploy-services-quot-error-when/m-p/450938#M17481</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I did try putting in a wait time (tried 5 seconds and 12 seconds) between each call but it didn't seem to make a difference. However, I have not tried it again since doing the url open calls in the &lt;SPAN style="font-family: 'courier new', courier;"&gt;with&lt;/SPAN&gt; statement. But I don't see that it would be too different. I haven't tried every combination of these things.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tried putting another for loop using range 3 so it will try three times to complete the action. If one failed, it was never able to successfully complete on the second or third try either (whether start or stop). Again though, I haven't tried this in combination with the wait time or the new code posted above with the separated functions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I notice is that it usually gets through at least the first three services when something fails. When one service in the list actually fails, it always fails on all remaining services in the list as well. This is the same as when I was trying three times as well. It also seems to usually be on start that it fails (rather than stop).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 09 Feb 2015 23:39:56 GMT</pubDate>
    <dc:creator>BlakeTerhune</dc:creator>
    <dc:date>2015-02-09T23:39:56Z</dc:date>
    <item>
      <title>"Could not undeploy services" error when using Python</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/quot-could-not-undeploy-services-quot-error-when/m-p/450936#M17479</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a Python script running on a 64-bit Windows Server 2012r2 machine with ArcGIS Server 10.2.2. The script has a list of twelve services (stored as a Python dictionary) that it stops and starts. 90% of the time all services in the list stop and start successfully. The other ten percent: not so much. The JSON error message returned says&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Could not undeploy services from one or more machines. 'com.esri.arcgis.discovery.admin.AdminException'.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;The log message in ArcGIS Server Manager shows up as Severe level and says pretty much the same thing. I haven't been able to notice a pattern in how often or which service it fails on. Sometimes (like this most recent time) it failed to stop a service in the middle of the list, then continued on to successfully stop the rest of the services. Later on in the script the same services are started and all started successfully. So I know the script works but it's just sometimes that it fails. My script does the following:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Copy feature classes from SDE to staging file geodatabase on server&lt;/LI&gt;&lt;LI&gt;Compact staging geodatabase&lt;/LI&gt;&lt;LI&gt;Stop related services&lt;/LI&gt;&lt;LI&gt;Delete production geodatabase&lt;/LI&gt;&lt;LI&gt;Copy staging gdb to production gdb&lt;/LI&gt;&lt;LI&gt;Start services&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;The code I use to stop and start services is based on this work from Kevin Hibma:&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.arcgis.com/home/item.html?id=12dde73e0e784e47818162b4d41ee340" rel="nofollow noopener noreferrer" target="_blank"&gt;ArcGIS Server Administration Toolkit - 10.1+&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/arcpy/AdministeringArcGISServerwithPython_DS2014" rel="nofollow noopener noreferrer" target="_blank"&gt;AdministeringArcGISServerwithPython_DS2014&lt;/A&gt;‌&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here are the Python functions I came up with:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;getToken()&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def getToken(adminUser, adminPass, server, port, expiration):
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Build URL
&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; url = "&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://geonet.esri.com/" rel="nofollow noopener noreferrer" target="_blank"&gt;http://&lt;/A&gt;&lt;SPAN&gt;{}:{}/arcgis/admin/generateToken?f=json".format(server, port)&lt;/SPAN&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Encode the query string
&amp;nbsp;&amp;nbsp;&amp;nbsp; query_dict = {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'username': adminUser,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'password': adminPass,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'expiration': str(expiration),&amp;nbsp; ## Token timeout in minutes; default is 60 minutes.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'client': 'requestip'
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; query_string = urllib.urlencode(query_dict)

&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Request the token
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with contextlib.closing(urllib2.urlopen(url, query_string)) as jsonResponse:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; getTokenResult = json.loads(jsonResponse.read())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ## Validate result
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if "token" not in getTokenResult or getTokenResult == None:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; raise Exception("Failed to get token: {}".format(getTokenResult['messages']))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return getTokenResult['token']

&amp;nbsp;&amp;nbsp;&amp;nbsp; except urllib2.URLError, e:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; raise Exception("Could not connect to machine {} on port {}\n{}".format(server, port, e))&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;serviceStartStop()&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def serviceStartStop(server, port, svc, action, token):
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Build URL
&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; url = "&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://geonet.esri.com/" rel="nofollow noopener noreferrer" target="_blank"&gt;http://&lt;/A&gt;&lt;SPAN&gt;{}:{}/arcgis/admin".format(server, port)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; requestURL = url + "/services/{}/{}".format(svc, action)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Encode the query string
&amp;nbsp;&amp;nbsp;&amp;nbsp; query_dict = {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "token": token,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "f": "json"
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; query_string = urllib.urlencode(query_dict)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Send the server request and return the JSON response
&amp;nbsp;&amp;nbsp;&amp;nbsp; with contextlib.closing(urllib.urlopen(requestURL, query_string)) as jsonResponse:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return json.loads(jsonResponse.read())&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I get the token once at the beginning of the main script and call the serviceStartStop() function repeatedly in a for loop iterating through a list of services.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:08:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/quot-could-not-undeploy-services-quot-error-when/m-p/450936#M17479</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-12-11T20:08:02Z</dc:date>
    </item>
    <item>
      <title>Re: "Could not undeploy services" error when using Python</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/quot-could-not-undeploy-services-quot-error-when/m-p/450937#M17480</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you tried putting in a sleep call to pause the script in between calling serviceStartStop()?&amp;nbsp; I wonder if the server sometimes gets bogged down and file locks aren't released right away.&amp;nbsp; Have you tried re-starting or re-stopping the service that just failed, does it work the second time right after it failed the first time?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Feb 2015 20:59:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/quot-could-not-undeploy-services-quot-error-when/m-p/450937#M17480</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2015-02-09T20:59:54Z</dc:date>
    </item>
    <item>
      <title>Re: "Could not undeploy services" error when using Python</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/quot-could-not-undeploy-services-quot-error-when/m-p/450938#M17481</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I did try putting in a wait time (tried 5 seconds and 12 seconds) between each call but it didn't seem to make a difference. However, I have not tried it again since doing the url open calls in the &lt;SPAN style="font-family: 'courier new', courier;"&gt;with&lt;/SPAN&gt; statement. But I don't see that it would be too different. I haven't tried every combination of these things.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tried putting another for loop using range 3 so it will try three times to complete the action. If one failed, it was never able to successfully complete on the second or third try either (whether start or stop). Again though, I haven't tried this in combination with the wait time or the new code posted above with the separated functions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I notice is that it usually gets through at least the first three services when something fails. When one service in the list actually fails, it always fails on all remaining services in the list as well. This is the same as when I was trying three times as well. It also seems to usually be on start that it fails (rather than stop).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Feb 2015 23:39:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/quot-could-not-undeploy-services-quot-error-when/m-p/450938#M17481</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2015-02-09T23:39:56Z</dc:date>
    </item>
    <item>
      <title>Re: "Could not undeploy services" error when using Python</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/quot-could-not-undeploy-services-quot-error-when/m-p/450939#M17482</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Were you able to ever find a solution to this problem?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If not, did you re-architect your environment so this functionality was no longer needed so therefore the issue went away?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Dec 2017 18:40:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/quot-could-not-undeploy-services-quot-error-when/m-p/450939#M17482</guid>
      <dc:creator>MichaelVolz</dc:creator>
      <dc:date>2017-12-04T18:40:05Z</dc:date>
    </item>
    <item>
      <title>Re: "Could not undeploy services" error when using Python</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/quot-could-not-undeploy-services-quot-error-when/m-p/450940#M17483</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've since retired these services so also retired the script interacting with them. However, I did try&amp;nbsp;republishing all the services with the option to automatically acquire locks disabled and I don't recall having the issue after that (or maybe I just stopped paying attention, can't remember).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Dec 2017 20:00:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/quot-could-not-undeploy-services-quot-error-when/m-p/450940#M17483</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2017-12-18T20:00:54Z</dc:date>
    </item>
    <item>
      <title>Re: "Could not undeploy services" error when using Python</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/quot-could-not-undeploy-services-quot-error-when/m-p/450941#M17484</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How exactly do you setup a service to acquire locks disabled?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Dec 2017 20:05:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/quot-could-not-undeploy-services-quot-error-when/m-p/450941#M17484</guid>
      <dc:creator>MichaelVolz</dc:creator>
      <dc:date>2017-12-18T20:05:37Z</dc:date>
    </item>
    <item>
      <title>Re: "Could not undeploy services" error when using Python</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/quot-could-not-undeploy-services-quot-error-when/m-p/450942#M17485</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A class="link-titled" href="http://server.arcgis.com/en/server/latest/administer/windows/disabling-schema-locking-on-a-map-service.htm" title="http://server.arcgis.com/en/server/latest/administer/windows/disabling-schema-locking-on-a-map-service.htm"&gt;Disable schema locking on a map service—ArcGIS Server Administration (Windows) | ArcGIS Enterprise&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Dec 2017 23:19:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/quot-could-not-undeploy-services-quot-error-when/m-p/450942#M17485</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2017-12-18T23:19:40Z</dc:date>
    </item>
  </channel>
</rss>

