Thursday 2 August 2012

Deploying a Timer Job in a Single Farms and Multiple Farms

What apparently could look a piece of cake, deploy a timer job, some times could become a nightmare.

On single farms Timer Jobs are controlled by the SPTimerv4 service which establish all the Timer Jobs on the START. That means, if you deploy a timer job and activate it it will not work until you re start this service

If you are working in a single farm with only one server you should have a mayor problem, but I recommend you to follow these instructions before activating the feature, this is the best installation you can perform:

  1. Create a wsp package in Visual Studio.
  2. Copy the wsp package in the server you want to deploy the Timer Job (for instance c:)
  3. Go to the server were you want to deploy the solution and go to Start->SharePoint 2010 Management Shell
  4. Type Add-SPSolution
  5. It will ask for the identity, just type c:\nameofsolution.wsp
  6. Now let’s go to install it.
  7. Type Install-SPSolution –GACDeployment
  8. it will ask for the identity: just type nameofsolution.wsp
  9. Now type net stop sptimerv4
  10. Now type net start sptimerv4
  11. Now type iisreset
  12. Go to Site Collection Administration->Site Collection Features
  13. Activate the feature.

To Uninstalling the service

  1. Deactivate the feature by going to Site Collection Administration->Site Collection Features
  2. Uninstall-SPSolution -Identity nameofsolution.wsp –allwebapplications
  3. Remove-SPSolution –force
  4. then Type the identity: nameofsolution.wsp
  5. Now type net stop sptimerv4
  6. Now type net start sptimerv4
  7. Now type iisreset

On Multiple farms it is a different issue. For the start you need to synchronize all the clocks so the whole farm can run the Timer Job properly. Only the application pool owners from the particular server where site collection lives will be able to activate the feature. The other way, will be doing it with Enable-SPFeature via Powershell or use the famous stsadm.

Now, having a farm like this:

image

The first thing we will do is going to the Server 3 (Apps). This server is the one which contains all the services, and we will do the following:

  1. Copy the wsp package in the server you want to deploy the Timer Job (for instance c:)
  2. Go to the server were you want to deploy the solution and go to Start->SharePoint 2010 Management Shell
  3. Type Add-SPSolution
  4. It will ask for the identity, just type c:\nameofsolution.wsp
  5. Now let’s go to install it.
  6. Type Install-SPSolution –GACDeployment
  7. it will ask for the identity: just type nameofsolution.wsp
  8. Now type net stop sptimerv4
  9. Now type net start sptimerv4
  10. (optional) Now type iisreset

Now, for every single server, a apart of of Server 4, do the following:

  1. Go to the server were you want to deploy the solution and go to Start->SharePoint 2010 Management Shell
  2. install-spsolution nameofsolution.wsp -GACDeployment –force
  3. Now type net stop sptimerv4
  4. Now type net start sptimerv4
  5. (optional) Now type iisreset

Go to Site Collection Administration->Site Collection Features and try to activate the feature. If you get an Access Denied, will be because you are in the wrong server, and your app pool identity doesn’t have access to it. I recommend you going to any other server to do it or just type the following from Powershell:

type Enable-SPFeature , and then type the name of the feature.

To remove the Timer Job, I suggest you to disable the feature first and then do the following:

  1. Uninstall-SPSolution -Identity nameofsolution.wsp –allwebapplications
  2. Remove-SPSolution –force
  3. then Type the identity: nameofsolution.wsp
  4. Now type net stop sptimerv4
  5. Now type net start sptimerv4
  6. (Optional) Now type iisreset

 

Conclusion: Timer Jobs are natural services for Sharepoint and become a really useful tool when you want to perform really complex operations. It is all controlled by Sharepoint so you don’t need to worry about, but only remember, theses steps so you don’t spend more time deploying it than developing.