I’m interested in people’s opinions about automating Sharepoint installations. We aim to automate everything, in fact if someone needs to touch a key or mouse button we have to through a policy waiver process.
In principal I think this is a great idea. It allows us to have a “self service” server provisioning system where anyone can use a web site wizard and end up with a server with WSS all set up without too much understanding of the manual process. This allows us to devolve some disaster recovery situations out as all the engineer needs to do is use the self service wizard to bring a new front end server into the farm.
All good so far but getting to this point has been a painful process and involved some lateral thinking. I’ll try to explain some of the pitfalls we’ve hit and what we did to get around it. I’ll assume you’ve already automated everything up to the WSS/MOSS install, ie Windows, ISS, .NET etc and that you have a configured SQL server.
Application install
On the face of it this is the easiest step. Simply use the provided silent install .xml files and call setup.exe. The only gotcha is that you might want to consider slipsteaming your SharePoint hotfixes. The next step will be to either create a new farm or to connect to an existing configuration database. If it’s the latter, your servers need to be at the same patch level as the database so our automated hotfix scripts will copy the hotfix on to a share. The SharePoint install script checks to see if there are any files in that share and copies them into the slipstream directory before calling setup.
Barebones script
XCOPY \\share\hotfixes %SP_InstallScriptDir%\Updates
setup.exe /config silent.xml
Farm setup
Because we use the same process to perform the initial server build, planned rebuilds and DRing the server we need to first check if the farm has already been created. If you don’t do this and you come to rebuild a server you’ll get unexpected results. Most likely it’ll error and return a -1 code but it might set a property back to it’s day one value or in some rare instances it can nuke your config. Because we have to script using DOS batch, all I have access to is psconfig and stsadm. This means the only mechanism for checking if the farms exists is to run
psconfig -cmd configdb -connect
or
psconfig -cmd configdb -create
Back in the early beta days MOSS would flatten your config database if you ran -create against an existing farm. Once bitten, twice shy so I always use -connect. Obviously if the server is being rebuilt and the configuration database is intact then your server just rejoined the farm and the SharePoint is in the process of bringing it up to speed. If the config database isn’t there psconfig will return a -1 error to the console, so your code needs to look something like this:
psconfig -cmd configdb -connect -server %SQLServer% -database %ConfigDB% -user %ServiceAcct% -password %ServicePass% -cmd helpcollections -installall -cmd secureresources -cmd services -install -cmd installfeatures -cmd adminvs -provision -port 12345 -windowsauthprovider onlyusentlm -cmd applicationcontent -install
if %errorlevel% == -1 goto create
if %errorlevel% NEQ 0 goto error
if %errorlevel% == 0 goto end
Bear in mind that the account you call psconfig with must have permissions within SQL. For security reasons, Windows native runas command doesn’t allow you to pipe the password so if you either need to run your whole script as the service account or use something like SANUR or CPAU.
The rest of the arguments simply mimic the steps that the gui installer takes. Obviously tweak them to suit your environment.
Ok, so what if this is the first install or a farm rebuild? Well the above logic just dropped you into a routine called :create. The first job will be to create the configuration database
psconfig -cmd configdb -create -server %SQLServer% -database %ConfigDB% -user %ServiceAcct% -password %ServicePass% -admincontentdatabase %AdminContentDB% -cmd helpcollections -installall -cmd secureresources -cmd services -install -cmd installfeatures -cmd adminvs -provision -port 12345 -windowsauthprovider onlyusentlm -cmd applicationcontent -install
There’s your core Sharepoint installation with central admin on http://server:12345 . Everything else is specific to your environment so I go into too much detail, however I will touch on a few important points. Let me start with the limitations of stsadm – the command you’ll use for 99% of your configuration. For me, it has two main problems:
- It only offers a subset of the functionality of central admin, eg you can assign a quota template as the default for a web application but there is no command to create that template in the first place
- I’ve never been able to get it to return an error code other than -1, regardless of what the fault was. This is a real problem for unattended installs where you might want to put some logic into the script
Happily, Sharepoint MVP Gary Lapointe has release something in the region of 100 stsadm extensions and so point one is solved. I strongly advise you to install it at the start of your :create routine. There was a tool on codeplex called stsadm+ which tried to tackle point 2, but at the time of writing this it isn’t available. This means that if you have any failures you can’t apply any logic and have to fail the script. This can be very frustrating if command 29 out of 30 fails and (assuming you’re sticking to your automated process) you have no choice but to disconnect the server from the farm, delete the database(s) and start over.
Be sure to run your script on one server at a time to avoid conflicts in the database. Make liberal use of
stsadm -o execadmsvcjobs
to ensure each command has finished. Below is an overview of the logic for this script:
Rem Slipstream any hotfixes that have been applied to the farm
XCOPY \\share\hotfixes %SP_InstallScriptDir%\Updates
REM Call setup to install Sharepoint
setup.exe /config silent.xml
REM Try to connect to the farm
psconfig -cmd configdb -connect -server %SQLServer% -database %ConfigDB% -user %ServiceAcct% -password %ServicePass% -cmd helpcollections -installall -cmd secureresources -cmd services -install -cmd installfeatures -cmd adminvs -provision -port 12345 -windowsauthprovider onlyusentlm -cmd applicationcontent -install
REM Check for errors to see if we connected
if %errorlevel% == -1 goto create
if %errorlevel% == 0 goto end
if %errorlevel% NEQ 0 goto error
:create
REM Create the farm
psconfig -cmd configdb -create -server %SQLServer% -database %ConfigDB% -user %ServiceAcct% -password %ServicePass% -admincontentdatabase %AdminContentDB% -cmd helpcollections -installall -cmd secureresources -cmd services -install -cmd installfeatures -cmd adminvs -provision -port 12345 -windowsauthprovider onlyusentlm -cmd applicationcontent -install
REM Install Gary Lapointe’s stsadm extensions
stsadm -o addsolution -filename lapointe.wsp
stsadm -o execadmsvcjobs
stsadm -o deploysolution -name lapointe.wsp -local -allowgacdeployment
REM Do your farm specific configuration
:End
REM Your error logic
:End
REM WooHoo we made it
Hotfix
There’s lots of info out there describing the SharePoint hotfix process so I’ll keep this brief. We split our script into two parts. Part one runs the hotfix and is run on all the servers at the same time. Part two is run on the servers one at a time and calls the upgrade process and then copies the hotfix to the share that I mentioned right at the start of this post.
psconfig -cmd upgrade -inplace b2b -wait -force
if %errorlevel% == 0 xcopy %hotfix% \\share\hotfixes\%hotfix%
I’ve not had the opportunity to convert all the above into a powershell script. It should solve the error logic gripe and would allow me much more control over the environment, effectively exposing what Gary Lapointe has given us via his extensions.
So back to my original point. Is all the above really worth it? Do you script your installs or do you do it manually? If you do use automation, what process are you using?
edit: Right on queue, SharePointdevwiki have just posted an article about scripting Sharepoint. Have a look