[KEERO-83] Windows Agent: Ability to reboot machine after execution plan is executed
This commit is contained in:
parent
5873d3610b
commit
58d823eca5
@ -16,5 +16,6 @@ namespace Mirantis.Keero.WindowsAgent
|
||||
|
||||
public string[] Scripts { get; set; }
|
||||
public LinkedList<Command> Commands { get; set; }
|
||||
public int RebootOnCompletion { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -24,20 +24,23 @@ namespace Mirantis.Keero.WindowsAgent
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public bool RebootNeeded { get; set; }
|
||||
|
||||
public string Execute()
|
||||
{
|
||||
RebootNeeded = false;
|
||||
try
|
||||
{
|
||||
var plan = JsonConvert.DeserializeObject<ExecutionPlan>(File.ReadAllText(this.path));
|
||||
var resultPath = this.path + ".result";
|
||||
List<object> currentResults = null;
|
||||
List<ExecutionResult> currentResults = null;
|
||||
try
|
||||
{
|
||||
currentResults = JsonConvert.DeserializeObject<List<object>>(File.ReadAllText(resultPath));
|
||||
currentResults = JsonConvert.DeserializeObject<List<ExecutionResult>>(File.ReadAllText(resultPath));
|
||||
}
|
||||
catch
|
||||
{
|
||||
currentResults = new List<object>();
|
||||
currentResults = new List<ExecutionResult>();
|
||||
}
|
||||
|
||||
|
||||
@ -100,6 +103,19 @@ namespace Mirantis.Keero.WindowsAgent
|
||||
IsException = false,
|
||||
Result = currentResults
|
||||
}, Formatting.Indented);
|
||||
|
||||
if (plan.RebootOnCompletion > 0)
|
||||
{
|
||||
if (plan.RebootOnCompletion == 1)
|
||||
{
|
||||
RebootNeeded = !currentResults.Any(t => t.IsException);
|
||||
}
|
||||
else
|
||||
{
|
||||
RebootNeeded = true;
|
||||
}
|
||||
}
|
||||
|
||||
File.Delete(resultPath);
|
||||
return executionResult;
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ namespace Mirantis.Keero.WindowsAgent
|
||||
|
||||
void Loop()
|
||||
{
|
||||
var doReboot = false;
|
||||
const string filePath = "data.json";
|
||||
while (!stop)
|
||||
{
|
||||
@ -40,10 +41,16 @@ namespace Mirantis.Keero.WindowsAgent
|
||||
File.WriteAllText(filePath, message.Body);
|
||||
message.Ack();
|
||||
}
|
||||
var result = new PlanExecutor(filePath).Execute();
|
||||
var executor = new PlanExecutor(filePath);
|
||||
var result = executor.Execute();
|
||||
if(stop) break;
|
||||
rabbitMqClient.SendResult(result);
|
||||
File.Delete(filePath);
|
||||
if (executor.RebootNeeded)
|
||||
{
|
||||
doReboot = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
@ -51,6 +58,18 @@ namespace Mirantis.Keero.WindowsAgent
|
||||
}
|
||||
|
||||
}
|
||||
if (doReboot)
|
||||
{
|
||||
Console.WriteLine("Rebooting...");
|
||||
try
|
||||
{
|
||||
System.Diagnostics.Process.Start("shutdown.exe", "-r -t 0");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -32,5 +32,6 @@
|
||||
"Name": "TestThrow",
|
||||
|
||||
}
|
||||
]
|
||||
],
|
||||
"RebootOnCompletion": 0
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user