Skip to content

Commit

Permalink
Update: Changed VRServerMonitor to ProcessMonitor, added better crash…
Browse files Browse the repository at this point in the history
… detect
  • Loading branch information
Eliminater74 committed Oct 31, 2023
1 parent fa33e4b commit 5a69ce7
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 54 deletions.
2 changes: 1 addition & 1 deletion OculusKiller/Core/MainOculusKiller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static async Task Main()
await Task.Delay(5000);

// Monitoring the VR server
VRServerMonitor.MonitorVRServer(vrServerPath, oculusPath);
ProcessMonitor.MonitorProcesses(vrServerPath, oculusPath);
}
catch (Exception e)
{
Expand Down
2 changes: 1 addition & 1 deletion OculusKiller/OculusKiller.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<Compile Include="Utilities\ProcessExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utilities\ProcessUtilities.cs" />
<Compile Include="Utilities\VRServerMonitor.cs" />
<Compile Include="Utilities\ProcessMonitor.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
Expand Down
67 changes: 67 additions & 0 deletions OculusKiller/Utilities/ProcessMonitor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Diagnostics;
using System.Linq;
using OculusKiller.Utilities;

namespace OculusKiller.Core
{
internal class ProcessMonitor
{
private const int MaxRetries = 3; // Maximum number of consecutive restart attempts

public static void MonitorProcesses(string vrServerPath, string oculusPath)
{
int retryCount = 0;

while (retryCount < MaxRetries) // Monitoring loop with retry limit
{
try
{
var vrServerProcess = Process.GetProcessesByName("vrserver")
.FirstOrDefault(process => process.MainModule.FileName == vrServerPath);

var vrDashboardProcess = Process.GetProcessesByName("vrdashboard").FirstOrDefault();

if (vrServerProcess != null && vrDashboardProcess != null)
{
ErrorLogger.Log("Monitoring vrserver and vrdashboard processes.");

vrServerProcess.WaitForExit(); // Wait for the vrserver process to exit
vrDashboardProcess.WaitForExit(); // Wait for the vrdashboard process to exit

// Check exit codes to determine if processes crashed
if (vrServerProcess.ExitCode != 0 || vrDashboardProcess.ExitCode != 0)
{
ErrorLogger.Log("vrserver or vrdashboard process crashed. Restarting...");
// Restarting the SteamVR process
ProcessUtilities.StartProcess(vrServerPath);
retryCount++;
}
else
{
ErrorLogger.Log("vrserver and vrdashboard processes exited normally.");
break; // Exit the loop if processes terminated normally
}
}
else
{
ErrorLogger.Log("vrserver or vrdashboard process not found. Starting...");
// Restarting the SteamVR process
ProcessUtilities.StartProcess(vrServerPath);
retryCount++;
}
}
catch (Exception e)
{
ErrorLogger.LogError(e);
retryCount++;
}
}

// After reaching the maximum retry limit, terminate SteamVR and Oculus Air Link
ErrorLogger.Log("Maximum retry limit reached. Terminating SteamVR and Oculus Air Link.");
ProcessUtilities.TerminateProcess("vrserver");
ProcessUtilities.TerminateProcess("OVRServer_x64");
}
}
}
52 changes: 0 additions & 52 deletions OculusKiller/Utilities/VRServerMonitor.cs

This file was deleted.

0 comments on commit 5a69ce7

Please sign in to comment.