Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am currently trying to build a shutdown script for a windows server 2012 which will perform a planned failover to my replica server when the primary shuts down.

My problem is that the shutdown script gets executed after the Hyper-V service has been stopped.

Is there any possibility to get it executed before?

share|improve this question

migrated from stackoverflow.com Jul 13 '13 at 2:05

This question came from our site for professional and enthusiast programmers.

    
Why not go the other way and hide the shutdown / reboot options as best as possible and use the script to call shutdown after it completes? –  AthomSfere Jul 13 '13 at 5:03
1  
Hmm. This would work but as I am in a server environment it is completely impossible to hide the shutdown/reboot options. Often the server reboots due to windows updates. –  donothingloop Jul 19 '13 at 8:22

3 Answers 3

up vote 4 down vote accepted
+50

This may be overkill, but one might create a service that depends on the Hyper-V service and performs the required action during service termination ...

share|improve this answer
    
actually it's not hard to program a service indeed. +1 for nice thinking. –  Gizmo Aug 18 '13 at 20:25
    
+1. Nice and general technique. –  harrymc Aug 19 '13 at 8:03
    
thanks :) I have implemented it and it works perfectly. now I'm angry about myself that I didn't think about that^^ –  donothingloop Aug 22 '13 at 12:59

The Microsoft Failover Clustering technology looks like a solution :

The Failover Clustering feature enables you to create and manage failover clusters. A failover cluster is a group of independent computers that work together to increase the availability of applications and services. The clustered servers (called nodes) are connected by physical cables and by software. If one of the cluster nodes fails, another node begins to provide service (a process known as failover). Users experience a minimum of disruptions in service.

For Server 2012 there are some small changes as detailed in Creating a Windows Server 2012 Failover Cluster.

Lots of additional documentation is available. For example :
Implementing Windows Server 2012 Hyper-V Failover Clustering.

share|improve this answer
    
I know that this is possible but I don't have any network attached storage and I really can't afford to buy one as it would have to be fully redundant :) –  donothingloop Aug 19 '13 at 7:43

Actually you can try to use schedule to create an task which trigger on the service stop event, and then perform shutdown -a, do the failover, and the shutdown -r.

The keypoint is get the right event to launch the tasks, and make sure it can abort the shutdown.

also, do not let window update to do auto-reboot, use the scheduler and do the event trigger to do failover and then planned reboot.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.