1
votes

I have a two-node cluster running Windows Server 2008 R2. It is essentially an active/passive cluster for SQL Server.

I have set up a scheduled task on the current active node. I want to set up that same task on the passive node but have it so that the task only runs on the active node.

I realise that this version of Windows doesn't support clustered tasks, but I thought that a work-around might be to create another task that is triggered on the node becoming 'active' which enables the first task, and a partner task to disable the first task when the node becomes 'passive'.

I haven't found anything on the internet about doing something like this though, so I was wondering whether this was possible, and if so how?

2

2 Answers

1
votes

I use generic script for enabling and disabling tasks:

WshShell = new ActiveXObject("WScript.Shell");
strEnableTask = "schtasks /change /ENABLE /TN \"\\Task\"";
strDisableTask = "schtasks /change /DISABLE /TN \"\\Task\"";

function Open() {
 return true;
}

function Online() {
 oExec = WshShell.Run(strEnableBackup, 0, true);
 return oExec.ExitCode;
}

function LooksAlive() {
 return true;
}

function IsAlive() {
 return true;
}

function Offline() {
 oExec = WshShell.Run(strDisableBackup, 0, true);
 return oExec.ExitCode;
}

function Close() {
 return true;
}

function Terminate() {
 return true;
}
0
votes

I think I've found a way to do this.

To enable or disable tasks from the command line I can use the schtasks command:

schtasks /Change /TN "MyTask" /ENABLE
schtasks /Change /TN "MyTask" /DISABLE

I can place these commands in a .bat file and trigger them to run when the cluster is activated by creating a task and setting a trigger with the following settings:

Begin the task: On an event
Log: Microsoft-Windows-FailoverClustering/Operational
Source: FailoverClustering
EventID: 1201

A similar task with EventID 1204 will trigger when the cluster is taken offline.

Combining all this means that I can create a task on both nodes of my cluster and only ever have it enabled on the active node.

One big caveat with this is that I haven't yet tested it! I'm also not 100% certain that those events will always fire (if, for example, a node loses power and is subsequently rebooted) so I might also need to check for some other events. It looks promising though.