I have made a first run at this... it's a collection of service actions (start/stop), copying files, and running remote commands via WMI. You use the "Service Name" as the key to start/stop services.
Also, I was going to cross post this on dropkick but it appears you don't have a list for it Dru.
<target name="copy-and-install">
<service action="stop" service="Service1" machine="remote1" />
<copy todir="\\remote1\C$\service1\">
<fileset basedir="C:\my\Trunk\Services\bin\Debug">
<include name="**/*" />
</fileset>
</copy>
<remoteexec machine="remote1" command="C:\service1\service1.exe -install" />
<service action="start" service="Service1" machine="devapp1" />
</target>
using System;
using System.Management;
using NAnt.Core;
using NAnt.Core.Attributes;
namespace My.NAntTasks
{
[TaskName("remoteexec")]
public class ExecuteRemoteCommand : Task
{
#region Task Attributes
[TaskAttribute("machine")]
public string Machine { get; set; }
[TaskAttribute("command")]
[StringValidator(AllowEmpty = false)]
public string CommandLine { get; set; }
public string RemoteUser { get; set; }
public string RemotePassword { get; set; }
#endregion
public ExecuteRemoteCommand()
{
Machine = Environment.MachineName;
}
protected override void ExecuteTask()
{
var logger = new LogWriter(this, Level.Info, null);
// also allow for remote user/password
ConnectionOptions connOptions = new ConnectionOptions();
connOptions.Impersonation = ImpersonationLevel.Impersonate;
connOptions.EnablePrivileges = true;
ManagementScope manScope = new ManagementScope(String.Format(@"\\{0}\ROOT\CIMV2", Machine), connOptions);
manScope.Connect();
ObjectGetOptions objectGetOptions = new ObjectGetOptions();
ManagementPath managementPath = new ManagementPath("Win32_Process");
ManagementClass processClass = new ManagementClass(manScope, managementPath, objectGetOptions);
ManagementBaseObject inParams = processClass.GetMethodParameters("Create");
inParams["CommandLine"] = CommandLine;
ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, null);
int returnVal = Convert.ToInt32(outParams["returnValue"]);
switch (returnVal)
{
case 2:
throw new Exception("Access is denied.");
case 3:
throw new Exception("Insufficient privileges.");
case 8:
throw new Exception("Unknown failure.");
case 9:
throw new Exception("Path not found.");
case 21:
throw new Exception("Invalid parameter");
}
logger.WriteLine("Command executed on " + Machine);
}
}
}
----
using System;
using System.ServiceProcess;
using NAnt.Core;
using NAnt.Core.Attributes;
namespace My.NAntTasks
{
[TaskName("service")]
public class ServiceManager : Task
{
#region Task Attributes
[TaskAttribute("action")]
[StringValidator(AllowEmpty = false)]
public string Action { get; set; }
[TaskAttribute("machine")]
public string Machine { get; set; }
[TaskAttribute("service")]
[StringValidator(AllowEmpty = false)]
public string Service { get; set; }
#endregion
public ServiceManager()
{
Machine = Environment.MachineName;
}
protected override void ExecuteTask()
{
var logger = new LogWriter(this, Level.Info, null);
if (Action == "stop")
{
using (var controller = new ServiceController(Service, Machine))
{
if (controller.Status == ServiceControllerStatus.Running)
{
controller.Stop();
logger.WriteLine("Stopping " + Service);
controller.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(30));
}
}
}
else if (Action == "start")
{
using (var controller = new ServiceController(Service, Machine))
{
if (controller.Status == ServiceControllerStatus.Stopped)
{
controller.Start();
logger.WriteLine("Starting " + Service);
controller.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(30));