Add cancel shutdown feature and enhance system control access methods in dashboard
This commit is contained in:
@@ -227,6 +227,48 @@ namespace ResourceMonitorService.Controllers
|
||||
return StatusCode(500, "Internal server error");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("cancel-shutdown")]
|
||||
public ActionResult CancelShutdown()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Execute the shutdown abort command
|
||||
var processInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "shutdown",
|
||||
Arguments = "/a",
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true
|
||||
};
|
||||
|
||||
var process = Process.Start(processInfo);
|
||||
process?.WaitForExit();
|
||||
|
||||
var exitCode = process?.ExitCode ?? -1;
|
||||
|
||||
string message;
|
||||
if (exitCode == 0)
|
||||
{
|
||||
message = "Shutdown/restart canceled successfully";
|
||||
_logger.LogInformation("Shutdown/restart canceled by user");
|
||||
}
|
||||
else
|
||||
{
|
||||
message = "No shutdown/restart was scheduled to cancel, or cancellation failed";
|
||||
_logger.LogInformation("Attempted to cancel shutdown but none was scheduled");
|
||||
}
|
||||
|
||||
return Ok(new { message });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error canceling shutdown command");
|
||||
return StatusCode(500, "Internal server error");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SystemControlRequest
|
||||
|
||||
Reference in New Issue
Block a user