support different stop executable (for example MySQL)

git-svn-id: https://svn.kenai.com/svn/winsw~subversion/trunk@21 c8b2a3fe-9b5b-6a51-a37e-dc31b0e308fa
remotes/git-svn
jjasper4 2009-01-05 21:58:57 +00:00
parent fe0ceb5e79
commit d42cf5188c
1 changed files with 35 additions and 17 deletions

52
Main.cs
View File

@ -73,17 +73,28 @@ namespace winsw
var n = dom.SelectSingleNode("//" + tagName); var n = dom.SelectSingleNode("//" + tagName);
if (n == null) throw new InvalidDataException("<" + tagName + "> is missing in configuration XML"); if (n == null) throw new InvalidDataException("<" + tagName + "> is missing in configuration XML");
return Environment.ExpandEnvironmentVariables(n.InnerText); return Environment.ExpandEnvironmentVariables(n.InnerText);
} }
/// <summary> /// <summary>
/// Path to the executable. /// Path to the executable.
/// </summary> /// </summary>
public string Executable public string Executable
{ {
get get
{ {
return SingleElement("executable"); return SingleElement("executable");
} }
}
/// <summary>
/// Optionally specify a different Path to an executable to shutdown the service.
/// </summary>
public string StopExecutable
{
get
{
return AppendTags("stopexecutable");
}
} }
/// <summary> /// <summary>
@ -423,9 +434,9 @@ namespace winsw
startarguments += " " + descriptor.Arguments; startarguments += " " + descriptor.Arguments;
} }
EventLog.WriteEntry("Starting " + descriptor.Executable + ' ' + startarguments); EventLog.WriteEntry("Starting " + descriptor.Executable + ' ' + startarguments);
StartProcess(process, startarguments); StartProcess(process, startarguments, descriptor.Executable);
// send stdout and stderr to its respective output file. // send stdout and stderr to its respective output file.
HandleLogfiles(); HandleLogfiles();
@ -455,15 +466,22 @@ namespace winsw
stoparguments += " " + descriptor.Arguments; stoparguments += " " + descriptor.Arguments;
Process stopProcess = new Process(); Process stopProcess = new Process();
StartProcess(stopProcess, stoparguments); String executable = descriptor.StopExecutable;
if (executable == null)
{
executable = descriptor.Executable;
}
StartProcess(stopProcess, stoparguments, executable);
stopProcess.WaitForExit(); stopProcess.WaitForExit();
} }
} }
private void StartProcess(Process process, string arguments) private void StartProcess(Process process, string arguments, String executable)
{ {
var ps = process.StartInfo; var ps = process.StartInfo;
ps.FileName = descriptor.Executable; ps.FileName = executable;
ps.Arguments = arguments; ps.Arguments = arguments;
ps.CreateNoWindow = false; ps.CreateNoWindow = false;
ps.UseShellExecute = false; ps.UseShellExecute = false;