Wednesday, January 29, 2014

Change application pool of an existing service application

This is the 4th post of the article series regarding service applications

As I mentioned in a previous post, If we create a new service application an application in IIS is also created. That allows us to isolate service applications by providing different application pools. In this article I will show how to assign a new application pool to an existing service application.

Can we manually create an application pool with a proper identity in IIS and assign it to the service application ? It is the wrong way of assigning the application pool

The wrong way

To demonstrate above fact I created a new Managed Metadata Service application and associated it with an existing application pool named MMS2 using central administration.

Then I’ll go to IIS Manager and create a new application pool manually and associate it with our service application as below

image

Although IIS allows us to associate application with new application pool, SharePoint does not know the change. To show that we will use following PowerShell commands.

  1. $app = Get-SPMetadataServiceApplication -Identity 796cb0d5-b8cf-4e0c-a03b-1d8cc285efe3
  2. $app.ApplicationPool

Following is the result I got

image

To stress the point further, I will stop the “Managed Metadata Web Service” in services on this server section. Then all Managed Metadata Service related applications in IIS will be deleted. Once I start the service again those applications will be recreated in IIS. As you can see the application pool of the service application is reverted back to MMS12 (with it’s Guid) and no longer “MMS2AppPool”

image

The correct way

The first thing to not is that, service applications need to be associated with an instance of SPServiceApplicationPool. Following is the way to do that.

  1. #Create new application pool
  2. $managedAccount = Get-SPManagedAccount -Identity "dev\spserviceapp"
  3. $servicePppPool = New-SPServiceApplicationPool -Name MetadataApplicationPool -Account $managedAccount
  4.  
  5. #Assign application pool to service application
  6. $app = Get-SPMetadataServiceApplication -Identity 796cb0d5-b8cf-4e0c-a03b-1d8cc285efe3
  7. $app.ApplicationPool = $servicePppPool
  8. $app.Update()

Following is the result I got

image

Now it doesn’t matter if I stop and start the service instance, the application pool remains the same.

No comments: