Friday, May 24, 2013

MSDEPLOYAGENTSERVICE 401 unauthorized–Resolution

We recently migrated a production environment for a client to new Servers. I had previously been using MSDeploy to deploy the websites/services to the servers so I figured all I had to do was install MSDeploy, point Update my deploy scripts to point to the new servers, and deploy! I was using MSDeploy 2 on the previous servers so I figured it would work on the new ones. Unfortunately it didn’t turn out to be that easy.
When I ran the updated scripts I got the following error:
Fatal: Request to remote agent URL 'http://myserver/MSDEPLOYAGENTSERVICE' failed.
Fatal: The remote server returned an error: (401) Unauthorized. Fatal count: 1
I was using an admin account and I could hit that URL above in a browser so I knew it wasn’t an authorization issue.
Here are the things I tried that DIDN’T work:
  1. Uninstall/Reinstall MSDeploy 2
  2. Install MSDeploy 3
  3. Create the fake user group on the server per these instructions:
  4. Check the file permissions on the Target server
  5. Bang my head against the wall and start crying…
After many hours of searching, I finally came across this brilliant post that solved my issue:
here are the scripts from the IIS Forum post for easy access:
dism /online /enable-feature /featurename:IIS-WebServerRole 
dism /online /enable-feature /featurename:IIS-WebServerManagementTools
dism /online /enable-feature /featurename:IIS-ManagementService
Reg Add HKLM\Software\Microsoft\WebManagement\Server /V EnableRemoteManagement /T REG_DWORD /D 1
net start wmsvc
sc config wmsvc start= auto

It turns out that the MSDeploy installers don’t tell you that you need to have some of the windows features installed in order to work properly. The installers just move forward and then fail to do the dreaded 401 unauthorized error. I uninstalled MSDeploy, ran the scripts there from the command prompt and installed. IT WORKED!

After that, I did run into 1 more issue regarding file permissions on the redirection.config file, but that was easily fixed via this post:

I hope this saves someone as much time as I wasted over the past 2 days.

Monday, May 6, 2013

Keep a website alive – PowerShell style


Recently, We had a website that didn’t have frequent visitors, but when the visitors did come, the website would take a long time to load up the first time. This is expected behavior because IIS shuts down its worker threads.

1 approach would be to set the IdleTimeout to 0 which means the threads are never aborted (details here: Instead of that though I decided to try my hand at PowerShell and came up with the following script:

   1:  # List of URLS to Ping
   2:  $urls = @("Http://", "")
   4:  #Ping all URLs in the list
   5:  foreach ($objItem in $urls) {
   6:      $req=[system.Net.HttpWebRequest]::Create($objItem);
   7:      $res = $req.getresponse();
   8:      $stat = $res.statuscode;
   9:      $res.Close();
  11:      #Pump it out to a text file
  12:      $res | Out-File pingresults.txt -append 
  13:  }

After that I set up a simple scheduled task to execute this at 15 minute intervals during business hours and walk away. Since I can schedule this when users are likely to hit the site, I have a customized “keep awake” script that provides more flexibility.