LLI Wiki — My Digital Knowledge Base

Arrêt et démarrage ordonnés d'une ferme SharePoint avec PowerShell

Deux scripts PowerShell pour arrêter puis démarrer les serveurs d'une ferme SharePoint dans le bon ordre (frontaux, OWA, application, bases de données).

Redémarrer une ferme SharePoint multi-serveurs exige un ordre précis : arrêter d'abord les serveurs web frontaux et en dernier les bases de données, puis démarrer d'abord les bases de données et en dernier les frontaux. Ces deux scripts PowerShell automatisent cette séquence pour une ferme hébergée sur des machines virtuelles.

Principe

Niveau Serveurs (exemple) Ordre d'arrêt Ordre de démarrage
Frontal (web) spfe01, spfe02 1 4
Office Web Apps spowa01 2 3
Application spapp01, spapp02 3 2
Base de données spdb01, spdb02 4 1

Script d'arrêt (sp_stop_server.ps1)

if ($args -notlike "/apply") {
	exit
}

$db  = @("spdb02","spdb01")
$app = @("spapp01","spapp02")
$owa = @("spowa01")
$wfe = @("spfe01","spfe02")

# Stopping SharePoint infrastructure...
Write-Host ""
Write-Host "Shutdown SharePoint Front-End..."
$wfe | foreach {
	Write-Host ""
	Write-Host "-> $_..."
	Stop-Computer -ComputerName $_ -Force
	do { Write-Host "." -NoNewline } while (Test-Connection $_ -Quiet)
	Write-Host ""
	Write-Host "-> $_ not responding..."
}
Write-Host ""
Write-Host "Shutdown OWA..."
$owa | foreach {
	Write-Host ""
	Write-Host "-> $_..."
	Stop-Computer -ComputerName $_ -Force
}
Write-Host ""
Write-Host "Shutdown SharePoint Application..."
$app | foreach {
	Write-Host ""
	Write-Host "-> $_..."
	Stop-Computer -ComputerName $_ -Force
	do { Write-Host "." -NoNewline } while (Test-Connection $_ -Quiet)
	Write-Host ""
	Write-Host "-> $_ not responding..."
}
Write-Host ""
Write-Host "Shutdown SharePoint Database..."
$db | foreach {
	Write-Host ""
	Write-Host "-> $_..."
	Stop-Computer -ComputerName $_ -Force
	do { Write-Host "." -NoNewline } while (Test-Connection $_ -Quiet)
	Write-Host ""
	Write-Host "-> $_ not responding..."
}

$ret = $false
$db + $app + $owa + $wfe | foreach { $ret = ($ret -or (Test-Connection $_ -Count 1 -Quiet)) }
if ($ret) {
	Write-Host ""
	Write-Host "Not all SharePoint servers are stopped correctly!"
	exit 1
} else {
	Write-Host ""
	Write-Host "All SharePoint servers are stopped."
	exit 0
}

Script de démarrage (sp_restart_server.ps1)

if ($args.Count -eq 0) {
	Write-Host ""
	Write-Host "Usage: start all SharePoint infrastructure."
	Write-Host "       sp_restart_server.ps1 [/apply]"
	Write-Host ""
	exit
}

if ($args -notlike "/apply") {
	exit
}

$db  = @("spdb01","spdb02")
$app = @("spapp02","spapp01")
$owa = @("spowa01")
$wfe = @("spfe01","spfe02")

# Starting SharePoint infrastructure...
Write-Host ""
Write-Host "Starting SharePoint Database..."
$db | foreach {
	Write-Host ""
	Write-Host "-> $_..."
	& .\Start-VM.ps1 $_ > Out-Null
	do { Write-Host "." -NoNewline } while (!(Test-Connection $_ -Quiet -Count 1 -Delay 1))
	Write-Host ""
	Write-Host "-> $_ responding..."
}

Write-Host ""
Write-Host "Waiting 30 seconds..."
Start-Sleep 30

Write-Host ""
Write-Host "Starting SharePoint Application..."
$app | foreach {
	Write-Host ""
	Write-Host "-> $_..."
	& .\Start-VM.ps1 $_ > Out-Null
	do { Write-Host "." -NoNewline } while (!(Test-Connection $_ -Quiet -Count 1 -Delay 1))
	Write-Host ""
	Write-Host "-> $_ responding..."
}
Write-Host ""
Write-Host "Starting OWA..."
$owa | foreach {
	Write-Host ""
	Write-Host "-> $_..."
	& .\Start-VM.ps1 $_ > Out-Null
}
Write-Host ""
Write-Host "Starting SharePoint Front-End..."
$wfe | foreach {
	Write-Host ""
	Write-Host "-> $_..."
	& .\Start-VM.ps1 $_ > Out-Null
	do { Write-Host "." -NoNewline } while (!(Test-Connection $_ -Quiet -Count 1 -Delay 1))
	Write-Host ""
	Write-Host "-> $_ responding..."
}

$ret = $true
$db + $app + $owa + $wfe | foreach { $ret = ($ret -and (Test-Connection $_ -Count 1 -Quiet)) }
if ($ret) {
	Write-Host ""
	Write-Host "All SharePoint servers are started."
	exit 0
} else {
	Write-Host ""
	Write-Host "Not all SharePoint servers are started correctly!"
	exit 1
}

Lancer chaque script avec .\sp_stop_server.ps1 /apply et .\sp_restart_server.ps1 /apply.

Remarques

Mastodon LLIMastodon SocialFosstodon