Thursday, 2 August 2012

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:

Create a wsp package in Visual Studio.

Copy the wsp package in the server you want to deploy the Timer Job (for instance c:)

Go to the server were you want to deploy the solution and go to Start->SharePoint 2010 Management Shell

Type Add-SPSolution

It will ask for the identity, just type c:\nameofsolution.wsp

Now let’s go to install it.

Type Install-SPSolution –GACDeployment

it will ask for the identity: just type nameofsolution.wsp

Now type net stop sptimerv4

Now type net start sptimerv4

Now type iisreset

Go to Site Collection Administration->Site Collection Features

Activate the feature.

To Uninstalling the service

Deactivate the feature by going to Site Collection Administration->Site Collection Features

Uninstall-SPSolution -Identity nameofsolution.wsp –allwebapplications

Remove-SPSolution –force

then Type the identity: nameofsolution.wsp

Now type net stop sptimerv4

Now type net start sptimerv4

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:

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:

Copy the wsp package in the server you want to deploy the Timer Job (for instance c:)

Go to the server were you want to deploy the solution and go to Start->SharePoint 2010 Management Shell

Type Add-SPSolution

It will ask for the identity, just type c:\nameofsolution.wsp

Now let’s go to install it.

Type Install-SPSolution –GACDeployment

it will ask for the identity: just type nameofsolution.wsp

Now type net stop sptimerv4

Now type net start sptimerv4

(optional) Now type iisreset

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

Go to the server were you want to deploy the solution and go to Start->SharePoint 2010 Management Shell

install-spsolution nameofsolution.wsp -GACDeployment –force

Now type net stop sptimerv4

Now type net start sptimerv4

(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:

Uninstall-SPSolution -Identity nameofsolution.wsp –allwebapplications

Remove-SPSolution –force

then Type the identity: nameofsolution.wsp

Now type net stop sptimerv4

Now type net start sptimerv4

(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.

About Me

I am a dedicated software developer who has been programming since I was 9 years old, when I made my first game in an Amstrad 128kb... after 25 years I keep doing the same stuff with different systems... If you have any problems or you want to contribute to this blog please email me to gabrielrenom@gmail.com

I have been Developing applications for mobile devices since late 90's I am keep dedicated to mobile development working with iPhone, iPad, iTouch , Windows Mobile and Android platforms having my own column in the US magazine i.Business. www.ibusinessmag.com.
Currently working in the legal industry for DWF LLP.