In ambiente cluster Windows ho avuto la necessità di eseguire dei task solo sul nodo owner di un particolare cluster group.
Con Windows 2003 era possibile rendere anche il Task Scheduler una risorsa cluster; per Windows 2008 non ho trovato una guida analoga.
Ho realizzato un semplice script in PowerShell che verifica se il nodo è owner del cluster group indicato e, solo in questo caso, esegue il comando passato allo script:
# Cluster management cmdlets Import-Module FailoverClusters Write-Host "runTask_Cluster 1.0" Write-Host # Check if command was passed as parameter If($args.Length -ne 1) { Write-Host "Usage: runTask_Cluster.ps1 <command>" Exit 1 } $cmd = $args[0] # Cluster group name $groupName = "PRODSASCMFE" Write-Host "Cluster group:`t$groupName" # Get server name $serverName = gc env:computername Write-Host "Server name:`t$serverName" # Get cluster group's owner $groupOwner = (Get-ClusterGroup -name $groupName).OwnerNode.Name.ToUpper() Write-Host "Group owner:`t$groupOwner" Write-Host # Check if actual server is cluster group's owner If($groupOwner -ieq $serverName) { Write-Host "Server is cluster group's owner, running the command:" Write-Host $cmd & $cmd Write-Host Write-Host "Done!" } Else { Write-Host "Server is not cluster group's owner, stop." } |
Come esempio ho scritto un semplice cmd che stampa Hello World a video:
e l’ho eseguito, tramite il mio script, su un nodo cluster sia nel caso in cui tale nodo sia owner del cluster group, sia nel caso contrario:
I like this script but I can’t get it to work. I get the following error. Got any ideas?
Cluster group: JAGUAR2
Server name: CFSPRODSQL1
Get-ClusterGroup : An error occurred opening the clustered service or application ‘JAGUAR2’.
At C:\scripts\runTask_Cluster.ps1:24 char:16
+ $groupOwner = (Get-ClusterGroup -name $groupName).OwnerNode.Name.ToUpper()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-ClusterGroup], ClusterCmdletException
+ FullyQualifiedErrorId : Get-ClusterGroup,Microsoft.FailoverClusters.PowerShell.GetClusterGroupCommand
You cannot call a method on a null-valued expression.
At C:\scripts\runTask_Cluster.ps1:24 char:1
+ $groupOwner = (Get-ClusterGroup -name $groupName).OwnerNode.Name.ToUpper()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Group owner:
Server is not cluster group’s owner, stop.
PS C:\Users\snapdrive.COOPFS.000>
I fixed it. the name of the cluster group was incorrect, once I fixed that the script works.
great, thanks for sharing your experience!