none
Stopping and starting a service on a failover cluster

    Soru

  • I need to create a script for stopping and starting a service on a 2008 enterprise sp1 failover cluster. This is a two node active/passive cluster. I need to stop and restart the tomcat:8080 service at different times of the day on the active node. This is pretty straight forward on a server but I'm not sure how to tackle this on a cluster.

    17 Şubat 2012 Cuma 14:52

Yanıtlar

  • just use the cluster name:

    physical node:   clusternode1
                              clusternode2

    virtual node:      virtualnode

    Start-Service -InputObject $(Get-Service -Computer virtualnode -Name tomcat)
    

    you can also use Stop-Service and Restart-Service with the exact same argument depending on what you want to do.

    Edit:  By using the virtualnode, you'll always auto-select the current active node.

    17 Şubat 2012 Cuma 15:11

Tüm Yanıtlar

  • just use the cluster name:

    physical node:   clusternode1
                              clusternode2

    virtual node:      virtualnode

    Start-Service -InputObject $(Get-Service -Computer virtualnode -Name tomcat)
    

    you can also use Stop-Service and Restart-Service with the exact same argument depending on what you want to do.

    Edit:  By using the virtualnode, you'll always auto-select the current active node.

    17 Şubat 2012 Cuma 15:11
  • Windows 2008 R2 includes Failover cluster cmdlets, but since you're using Windows 2008 SP1 you'll need to use WMI.  If you can grab the cluster resource and then invoke the TakeOffline and BringOnline methods. I would not recommend using the restart-service cmdlet as this is only for standalone services.

    1. Get all cluster resources

    $cluster = "yourclustername"

    gwmi -ComputerName $cluster -Authentication PacketPrivacy -Namespace "root\mscluster" -Class MSCluster_Resource 

    2. See the TakeOffline and BringOnline methods

    gwmi -ComputerName $cluster -Authentication PacketPrivacy -Namespace "root\mscluster" -Class MSCluster_Resource  | get-member

    3. Filter the output to just the one service you want to "restart"

    gwmi -ComputerName $cluster -Authentication PacketPrivacy -Namespace "root\mscluster" -Class MSCluster_Resource  -Filter "name = 'yourResourcename'" 

    4. Here's a complete command to "restart" the service (you'll need to test this):

    gwmi -ComputerName $cluster -Authentication PacketPrivacy -Namespace "root\mscluster" -Class MSCluster_Resource  -Filter "name = 'yourResourcename'"  | foreach {$_.TakeOffline(120); $_.BringOnline(120)}


    17 Şubat 2012 Cuma 19:22
  • you can also use the built-in management tools with cluster.exe:

    c:\>cluster.exe /CLUSTER:cluster-name RES tomcat /OFF
    c:\>cluster.exe /CLUSTER:cluster-name RES tomcat /ON

    17 Şubat 2012 Cuma 20:01
  • You could, but one limitation of using cluster.exe is that you'd need the cluster management tools installed. The nice thing about a WMI-based approach is that I can execute from any machine remotely.
    17 Şubat 2012 Cuma 21:35
  • Would this same solution work on server 2003 with Powershell?
    20 Şubat 2012 Pazartesi 21:44
  • According to the following technet article, both of the methods used with the MSCluster namespace should be supported in 2003

    http://technet.microsoft.com/en-us/query/aa371464

    20 Şubat 2012 Pazartesi 21:53
  • Excellent reference - thank you!
    21 Şubat 2012 Salı 13:59